feat(ios): add online device list and pairing code redemption
- Add API methods for fetching online devices and redeeming pairing codes - Add OnlineDevice model and corresponding ViewModel state management - Add UI sections for online device list and pairing code input in SetupPanel - Ensure access token is verified before connecting to signaling server
This commit is contained in:
@@ -26,6 +26,63 @@ struct SetupPanelView: View {
|
||||
TextField("目标设备 ID", text: $viewModel.targetDeviceId)
|
||||
.autocapitalization(.allCharacters)
|
||||
.disableAutocorrection(true)
|
||||
|
||||
Button {
|
||||
viewModel.loadOnlineDevices()
|
||||
} label: {
|
||||
HStack {
|
||||
Text("刷新在线设备")
|
||||
Spacer()
|
||||
if viewModel.isLoadingOnlineDevices {
|
||||
ProgressView()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !viewModel.onlineDevices.isEmpty {
|
||||
Section("在线设备(点击填入目标 ID)") {
|
||||
ForEach(viewModel.onlineDevices) { device in
|
||||
Button {
|
||||
viewModel.targetDeviceId = device.deviceId
|
||||
} label: {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(device.nickname)
|
||||
Text(device.deviceId)
|
||||
.font(.system(.caption, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
Spacer()
|
||||
if viewModel.targetDeviceId == device.deviceId {
|
||||
Image(systemName: "checkmark")
|
||||
.foregroundColor(.accentColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section("配对码兑换(建立新绑定)") {
|
||||
HStack {
|
||||
TextField("输入被控端显示的配对码", text: $viewModel.pairingCode)
|
||||
.textInputAutocapitalization(.never)
|
||||
.autocorrectionDisabled()
|
||||
Button {
|
||||
viewModel.redeemPairingCode()
|
||||
} label: {
|
||||
if viewModel.isRedeemingPairing {
|
||||
ProgressView()
|
||||
} else {
|
||||
Text("兑换")
|
||||
}
|
||||
}
|
||||
.disabled(viewModel.isRedeemingPairing || viewModel.pairingCode.trimmingCharacters(in: .whitespaces).isEmpty)
|
||||
}
|
||||
Text("在被控端生成配对码后填入此处即可建立绑定,绑定成功后会出现在上方在线设备列表中。")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Section {
|
||||
|
||||
Reference in New Issue
Block a user