feat: 增加密码连接

This commit is contained in:
2026-07-22 20:32:52 +08:00
parent ef786b1529
commit bdde6ccd2e
19 changed files with 541 additions and 25 deletions

View File

@@ -99,7 +99,73 @@ class _ControllerHomeState extends State<ControllerHome> {
);
}
Future<void> _connect() async {
Future<void> _showAuthDialog() async {
final serverUrl = _serverUrlController.text.trim();
final deviceId = _deviceIdController.text.trim();
final target = _targetController.text.trim();
if (serverUrl.isEmpty || deviceId.isEmpty || target.isEmpty) {
_setStatus('请填写所有字段');
return;
}
String selectedType = 'CODE';
final valueController = TextEditingController();
await showCupertinoDialog<void>(
context: context,
builder: (ctx) => StatefulBuilder(
builder: (ctx, setDialogState) => CupertinoAlertDialog(
title: const Text('连接鉴权'),
content: Column(
children: [
const SizedBox(height: 12),
CupertinoSegmentedControl<String>(
children: const {
'CODE': Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Text('动态验证码'),
),
'PASSWORD': Padding(
padding: EdgeInsets.symmetric(horizontal: 8),
child: Text('固定密码'),
),
},
groupValue: selectedType,
onValueChanged: (v) => setDialogState(() => selectedType = v),
),
const SizedBox(height: 12),
CupertinoTextField(
controller: valueController,
placeholder: '请输入验证码或密码',
obscureText: true,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
),
],
),
actions: [
CupertinoDialogAction(
child: const Text('取消'),
onPressed: () => Navigator.of(ctx).pop(),
),
CupertinoDialogAction(
child: const Text('连接'),
onPressed: () {
final val = valueController.text.trim();
if (val.isEmpty) {
_showAlert('请输入验证码或密码');
return;
}
Navigator.of(ctx).pop();
_connect(authType: selectedType, authValue: val);
},
),
],
),
),
);
}
Future<void> _connect({required String authType, required String authValue}) async {
final serverUrl = _serverUrlController.text.trim();
final deviceId = _deviceIdController.text.trim();
final target = _targetController.text.trim();
@@ -115,6 +181,8 @@ class _ControllerHomeState extends State<ControllerHome> {
serverUrl: serverUrl,
deviceId: deviceId,
targetDeviceId: target,
authType: authType,
authValue: authValue,
);
_controller!.onStatusChanged = _setStatus;
_controller!.onConnectionEstablished = () {
@@ -142,7 +210,7 @@ class _ControllerHomeState extends State<ControllerHome> {
};
_controller!.onStats = (stats) => setState(() => _stats = stats);
_controller!.connect();
_controller!.connect(authType: authType, authValue: authValue);
}
void _onRendererUpdate() {
@@ -241,7 +309,7 @@ class _ControllerHomeState extends State<ControllerHome> {
SizedBox(
width: double.infinity,
child: CupertinoButton.filled(
onPressed: _connect,
onPressed: _showAuthDialog,
child: const Text('连接被控设备'),
),
),