feat(device): 更新设备配置页面功能

- 添加EP832设备型号支持到蓝牙发现模块
- 重构设备匹配显示逻辑,改进UI布局结构
- 增强设备列表操作的错误处理机制
This commit is contained in:
ozh 2026-04-21 16:43:57 +08:00
parent aa0264ba19
commit bcf2285b65
2 changed files with 75 additions and 12 deletions

View File

@ -12,7 +12,7 @@ import { showToast } from '@/utils/toast'
const FILTER_SCAN_TIMEOUT_MS = 4000 const FILTER_SCAN_TIMEOUT_MS = 4000
const RESTART_SCAN_DELAY_MS = 120 const RESTART_SCAN_DELAY_MS = 120
const DISCOVERY_POLL_INTERVAL_MS = 1200 const DISCOVERY_POLL_INTERVAL_MS = 1200
const TARGET_NAME_KEYWORDS = Object.freeze(['ED713', '713WQ', 'ED719']) const TARGET_NAME_KEYWORDS = Object.freeze(['ED713', '713WQ', 'ED719','EP832'])
function promisifyUniApi(apiName, params = {}) { function promisifyUniApi(apiName, params = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -121,7 +121,7 @@ export function createBluetoothDiscovery(options = {}) {
return DEVICE_PROFILE.ED719 return DEVICE_PROFILE.ED719
} }
if (text.includes('ED713')) { if (text.includes('713WQ')) {
return DEVICE_PROFILE.ED713 return DEVICE_PROFILE.ED713
} }

View File

@ -27,12 +27,14 @@
<view class="device-name-row"> <view class="device-name-row">
<text class="device-name">{{ device.showName }}</text> <text class="device-name">{{ device.showName }}</text>
<text v-if="device.hasTargetService" class="device-tag">00F4</text> <text v-if="device.hasTargetService" class="device-tag">00F4</text>
<text v-else-if="device.matchedByName || device.matchedByPayload" class="device-tag name-tag">名称匹配</text> <text v-else-if="device.matchedByName || device.matchedByPayload" class="device-tag name-tag">名称匹配
</text>
</view> </view>
<text class="device-id">{{ device.deviceId }}</text> <text class="device-id">{{ device.deviceId }}</text>
<view class="device-actions"> <view class="device-actions">
<view class="action-btn" :class="{ disabled: wifiPreparing }" @click.stop="openWifiPanel(device)"> <view class="action-btn" :class="{ disabled: isDevicePreparing(device.deviceId) }"
{{ wifiPreparing ? '鉴权中' : '网络配置' }} @click.stop="openWifiPanel(device.deviceId)">
{{ isDevicePreparing(device.deviceId) ? '鉴权中' : '网络配置' }}
</view> </view>
<view class="action-btn">参数配置</view> <view class="action-btn">参数配置</view>
<view class="action-btn">服务器配置</view> <view class="action-btn">服务器配置</view>
@ -54,7 +56,10 @@
</view> </view>
<view class="wifi-row wifi-row-ssid"> <view class="wifi-row wifi-row-ssid">
<text class="wifi-label"><text class="wifi-required">*</text>WiFi名称</text> <text class="wifi-label">
<text class="wifi-required">*</text>
WiFi名称
</text>
<input <input
v-model.trim="wifiForm.ssid" v-model.trim="wifiForm.ssid"
class="wifi-input wifi-input-ssid" class="wifi-input wifi-input-ssid"
@ -68,7 +73,10 @@
</view> </view>
<view class="wifi-row"> <view class="wifi-row">
<text class="wifi-label"><text class="wifi-required">*</text>WiFi密码</text> <text class="wifi-label">
<text class="wifi-required">*</text>
WiFi密码
</text>
<input <input
v-model.trim="wifiForm.password" v-model.trim="wifiForm.password"
class="wifi-input" class="wifi-input"
@ -92,7 +100,7 @@
</template> </template>
<script> <script>
import { createBluetoothDiscovery } from '@/hooks/useBluetoothDiscovery' import { createBluetoothDiscovery } from '@/hooks/useBluetoothDiscovery'
import { navigateBack } from '@/utils/navigation' import { navigateBack } from '@/utils/navigation'
import { showToast } from '@/utils/toast' import { showToast } from '@/utils/toast'
@ -143,9 +151,11 @@ export default {
// WiFi // WiFi
wifiPanelVisible: false, wifiPanelVisible: false,
wifiPreparing: false, wifiPreparing: false,
activePreparingDeviceId: '',
wifiSending: false, wifiSending: false,
fetchingCurrentWifi: false, fetchingCurrentWifi: false,
wifiPrepared: false, wifiPrepared: false,
devicePreparingMap: {},
selectedWifiDevice: null, selectedWifiDevice: null,
wifiForm: { wifiForm: {
ssid: '', ssid: '',
@ -204,6 +214,7 @@ export default {
this.wifiPanelVisible = false this.wifiPanelVisible = false
this.wifiPrepared = false this.wifiPrepared = false
this.wifiPreparing = false this.wifiPreparing = false
this.activePreparingDeviceId = ''
this.fetchingCurrentWifi = false this.fetchingCurrentWifi = false
this.selectedWifiDevice = null this.selectedWifiDevice = null
this.resetWifiForm() this.resetWifiForm()
@ -215,11 +226,47 @@ export default {
this.wifiForm.password = '' this.wifiForm.password = ''
}, },
setDevicePreparing(deviceId, preparing) {
const safeDeviceId = String(deviceId || '').trim()
if (!safeDeviceId) {
return
}
this.devicePreparingMap = {
...this.devicePreparingMap,
[safeDeviceId]: Boolean(preparing)
}
},
isDevicePreparing(deviceId) {
const safeDeviceId = String(deviceId || '').trim()
if (!safeDeviceId) {
return false
}
return Boolean(this.devicePreparingMap[safeDeviceId])
},
getDeviceById(deviceId) {
const safeDeviceId = String(deviceId || '').trim()
if (!safeDeviceId) {
return null
}
const mapDevice = this.deviceMap[safeDeviceId]
if (mapDevice) {
return mapDevice
}
return this.deviceList.find((item) => item.deviceId === safeDeviceId) || null
},
cleanupDiscovery() { cleanupDiscovery() {
if (!this.discoveryController) { if (!this.discoveryController) {
return return
} }
this.devicePreparingMap = {}
this.cleanupWifiPanelState() this.cleanupWifiPanelState()
this.discoveryController.cleanupDiscovery() this.discoveryController.cleanupDiscovery()
}, },
@ -245,7 +292,7 @@ export default {
} }
}, },
async openWifiPanel(device) { async openWifiPanel(deviceId) {
if (this.wifiPreparing || this.wifiSending) { if (this.wifiPreparing || this.wifiSending) {
return return
} }
@ -254,14 +301,28 @@ export default {
return return
} }
if (!device || !device.deviceId) { const targetDeviceId = String(deviceId || '').trim()
if (!targetDeviceId) {
showToast('未选择可配置设备') showToast('未选择可配置设备')
return return
} }
if (this.activePreparingDeviceId && this.activePreparingDeviceId !== targetDeviceId) {
showToast('正在为其他设备鉴权,请稍候')
return
}
const targetDevice = this.getDeviceById(targetDeviceId)
if (!targetDevice) {
showToast('设备已失效,请重新搜索')
return
}
this.wifiPreparing = true this.wifiPreparing = true
this.activePreparingDeviceId = targetDeviceId
this.wifiPrepared = false this.wifiPrepared = false
this.selectedWifiDevice = device this.selectedWifiDevice = targetDevice
this.setDevicePreparing(targetDeviceId, true)
uni.showLoading({ uni.showLoading({
title: '密钥鉴权中', title: '密钥鉴权中',
@ -272,7 +333,7 @@ export default {
/** /**
* 按需求先执行 MAC+0000 密钥鉴权成功后再允许进入 WiFi 弹层 * 按需求先执行 MAC+0000 密钥鉴权成功后再允许进入 WiFi 弹层
*/ */
await this.discoveryController.prepareWifiConfig(device.deviceId, { await this.discoveryController.prepareWifiConfig(targetDeviceId, {
suffix: '0000', suffix: '0000',
timeout: 8000 timeout: 8000
}) })
@ -284,6 +345,8 @@ export default {
showToast(getErrorMessage(error)) showToast(getErrorMessage(error))
await this.safeDisconnect() await this.safeDisconnect()
} finally { } finally {
this.setDevicePreparing(targetDeviceId, false)
this.activePreparingDeviceId = ''
this.wifiPreparing = false this.wifiPreparing = false
uni.hideLoading() uni.hideLoading()
} }