feat(device): 更新设备配置页面功能
- 添加EP832设备型号支持到蓝牙发现模块 - 重构设备匹配显示逻辑,改进UI布局结构 - 增强设备列表操作的错误处理机制
This commit is contained in:
parent
aa0264ba19
commit
bcf2285b65
|
|
@ -12,7 +12,7 @@ import { showToast } from '@/utils/toast'
|
|||
const FILTER_SCAN_TIMEOUT_MS = 4000
|
||||
const RESTART_SCAN_DELAY_MS = 120
|
||||
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 = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -121,7 +121,7 @@ export function createBluetoothDiscovery(options = {}) {
|
|||
return DEVICE_PROFILE.ED719
|
||||
}
|
||||
|
||||
if (text.includes('ED713')) {
|
||||
if (text.includes('713WQ')) {
|
||||
return DEVICE_PROFILE.ED713
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,12 +27,14 @@
|
|||
<view class="device-name-row">
|
||||
<text class="device-name">{{ device.showName }}</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>
|
||||
<text class="device-id">{{ device.deviceId }}</text>
|
||||
<view class="device-actions">
|
||||
<view class="action-btn" :class="{ disabled: wifiPreparing }" @click.stop="openWifiPanel(device)">
|
||||
{{ wifiPreparing ? '鉴权中' : '网络配置' }}
|
||||
<view class="action-btn" :class="{ disabled: isDevicePreparing(device.deviceId) }"
|
||||
@click.stop="openWifiPanel(device.deviceId)">
|
||||
{{ isDevicePreparing(device.deviceId) ? '鉴权中' : '网络配置' }}
|
||||
</view>
|
||||
<view class="action-btn">参数配置</view>
|
||||
<view class="action-btn">服务器配置</view>
|
||||
|
|
@ -54,7 +56,10 @@
|
|||
</view>
|
||||
|
||||
<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
|
||||
v-model.trim="wifiForm.ssid"
|
||||
class="wifi-input wifi-input-ssid"
|
||||
|
|
@ -68,7 +73,10 @@
|
|||
</view>
|
||||
|
||||
<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
|
||||
v-model.trim="wifiForm.password"
|
||||
class="wifi-input"
|
||||
|
|
@ -92,7 +100,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { createBluetoothDiscovery } from '@/hooks/useBluetoothDiscovery'
|
||||
import { createBluetoothDiscovery } from '@/hooks/useBluetoothDiscovery'
|
||||
import { navigateBack } from '@/utils/navigation'
|
||||
import { showToast } from '@/utils/toast'
|
||||
|
||||
|
|
@ -143,9 +151,11 @@ export default {
|
|||
// WiFi 弹层状态。
|
||||
wifiPanelVisible: false,
|
||||
wifiPreparing: false,
|
||||
activePreparingDeviceId: '',
|
||||
wifiSending: false,
|
||||
fetchingCurrentWifi: false,
|
||||
wifiPrepared: false,
|
||||
devicePreparingMap: {},
|
||||
selectedWifiDevice: null,
|
||||
wifiForm: {
|
||||
ssid: '',
|
||||
|
|
@ -204,6 +214,7 @@ export default {
|
|||
this.wifiPanelVisible = false
|
||||
this.wifiPrepared = false
|
||||
this.wifiPreparing = false
|
||||
this.activePreparingDeviceId = ''
|
||||
this.fetchingCurrentWifi = false
|
||||
this.selectedWifiDevice = null
|
||||
this.resetWifiForm()
|
||||
|
|
@ -215,11 +226,47 @@ export default {
|
|||
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() {
|
||||
if (!this.discoveryController) {
|
||||
return
|
||||
}
|
||||
|
||||
this.devicePreparingMap = {}
|
||||
this.cleanupWifiPanelState()
|
||||
this.discoveryController.cleanupDiscovery()
|
||||
},
|
||||
|
|
@ -245,7 +292,7 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
async openWifiPanel(device) {
|
||||
async openWifiPanel(deviceId) {
|
||||
if (this.wifiPreparing || this.wifiSending) {
|
||||
return
|
||||
}
|
||||
|
|
@ -254,14 +301,28 @@ export default {
|
|||
return
|
||||
}
|
||||
|
||||
if (!device || !device.deviceId) {
|
||||
const targetDeviceId = String(deviceId || '').trim()
|
||||
if (!targetDeviceId) {
|
||||
showToast('未选择可配置设备')
|
||||
return
|
||||
}
|
||||
|
||||
if (this.activePreparingDeviceId && this.activePreparingDeviceId !== targetDeviceId) {
|
||||
showToast('正在为其他设备鉴权,请稍候')
|
||||
return
|
||||
}
|
||||
|
||||
const targetDevice = this.getDeviceById(targetDeviceId)
|
||||
if (!targetDevice) {
|
||||
showToast('设备已失效,请重新搜索')
|
||||
return
|
||||
}
|
||||
|
||||
this.wifiPreparing = true
|
||||
this.activePreparingDeviceId = targetDeviceId
|
||||
this.wifiPrepared = false
|
||||
this.selectedWifiDevice = device
|
||||
this.selectedWifiDevice = targetDevice
|
||||
this.setDevicePreparing(targetDeviceId, true)
|
||||
|
||||
uni.showLoading({
|
||||
title: '密钥鉴权中',
|
||||
|
|
@ -272,7 +333,7 @@ export default {
|
|||
/**
|
||||
* 按需求先执行 MAC+0000 密钥鉴权,成功后再允许进入 WiFi 弹层。
|
||||
*/
|
||||
await this.discoveryController.prepareWifiConfig(device.deviceId, {
|
||||
await this.discoveryController.prepareWifiConfig(targetDeviceId, {
|
||||
suffix: '0000',
|
||||
timeout: 8000
|
||||
})
|
||||
|
|
@ -284,6 +345,8 @@ export default {
|
|||
showToast(getErrorMessage(error))
|
||||
await this.safeDisconnect()
|
||||
} finally {
|
||||
this.setDevicePreparing(targetDeviceId, false)
|
||||
this.activePreparingDeviceId = ''
|
||||
this.wifiPreparing = false
|
||||
uni.hideLoading()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue