fix:bug解决
This commit is contained in:
@@ -153,7 +153,12 @@ export function useDeviceBluetoothSync(context: DeviceBluetoothSyncContext) {
|
||||
if (!foundDevice) {
|
||||
setSyncText('未找到设备,请确认已开机并靠近手机')
|
||||
if (!tearingDown) {
|
||||
reportBleLinkLostLocal()
|
||||
if (hadSuccessfulSync) {
|
||||
hadSuccessfulSync = false
|
||||
void reportBleDisconnected()
|
||||
} else {
|
||||
reportBleLinkLostLocal()
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -184,7 +189,12 @@ export function useDeviceBluetoothSync(context: DeviceBluetoothSyncContext) {
|
||||
if (!tearingDown) {
|
||||
bleDeviceId.value = undefined
|
||||
clearZ2BleHandleCache(targetBleId)
|
||||
reportBleLinkLostLocal()
|
||||
if (hadSuccessfulSync) {
|
||||
hadSuccessfulSync = false
|
||||
void reportBleDisconnected()
|
||||
} else {
|
||||
reportBleLinkLostLocal()
|
||||
}
|
||||
}
|
||||
return false
|
||||
} finally {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { usePageShowRefresh } from '@/hooks/use-page-show-refresh'
|
||||
import { computed, ref } from 'vue'
|
||||
import { fetchRoomList } from '@/api/location'
|
||||
import { getErrorMessage } from '@/utils/api-error'
|
||||
import { parseDeviceId, parseId, sameId } from '@/utils/device-id'
|
||||
import { fetchProductOptions } from '@/pages/add-device/complete/complete.api'
|
||||
import { fetchDeviceList } from '../device.api'
|
||||
import { fetchAllDeviceList } from '../device.api'
|
||||
import { findPatchedDeviceName } from '../device-list-patch'
|
||||
import { fetchDeviceRuntime, updateDeviceRuntime } from './device-detail.api'
|
||||
import type { AppDeviceRuntimeVo, DeviceDetailRouteQuery, FanLevel, RunMode } from './device-detail.types'
|
||||
import {
|
||||
@@ -33,6 +35,8 @@ import {
|
||||
import type { BleRuntimePatch } from './device-bluetooth-read'
|
||||
import { useDeviceBluetoothSync } from './use-device-bluetooth-sync'
|
||||
|
||||
const DEVICE_CONTROL_WAIT_TOAST = '设备连接中,请稍候'
|
||||
|
||||
export function useDeviceDetail() {
|
||||
const deviceId = ref('')
|
||||
const deviceNo = ref('')
|
||||
@@ -156,13 +160,16 @@ export function useDeviceDetail() {
|
||||
async function refreshDeviceMeta() {
|
||||
if (!deviceId.value) return
|
||||
const bleConnectedLocally = bluetoothConnected.value
|
||||
const patchedName = findPatchedDeviceName(deviceId.value)
|
||||
if (patchedName) deviceName.value = patchedName
|
||||
try {
|
||||
const list = await fetchDeviceList()
|
||||
const list = await fetchAllDeviceList()
|
||||
const device = list?.find((item) => String(item.deviceId) === deviceId.value)
|
||||
if (!device) return
|
||||
if (device.deviceId != null) deviceId.value = String(device.deviceId)
|
||||
if (device.deviceNo) deviceNo.value = device.deviceNo
|
||||
if (device.mac) deviceMac.value = device.mac
|
||||
if (device.name) deviceName.value = device.name
|
||||
const parsedLocationId = parseId(device.locationId)
|
||||
if (parsedLocationId) locationId.value = parsedLocationId
|
||||
const parsedHomeId = parseId(device.homeId)
|
||||
@@ -201,10 +208,17 @@ export function useDeviceDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
function promptWaitForDeviceOnline(): boolean {
|
||||
if (bluetoothConnected.value) return true
|
||||
uni.showToast({ title: DEVICE_CONTROL_WAIT_TOAST, icon: 'none' })
|
||||
return false
|
||||
}
|
||||
|
||||
async function patchRuntime(patch: { runMode?: RunMode; fanLevel?: FanLevel }) {
|
||||
if (!deviceId.value) return
|
||||
if (patch.runMode != null && runMode.value === patch.runMode) return
|
||||
if (patch.fanLevel != null && fanLevel.value === patch.fanLevel) return
|
||||
if (!promptWaitForDeviceOnline()) return
|
||||
|
||||
const snapshot = { runMode: runMode.value, fanLevel: fanLevel.value }
|
||||
if (patch.runMode != null) runMode.value = patch.runMode
|
||||
@@ -232,7 +246,11 @@ export function useDeviceDetail() {
|
||||
} catch (err) {
|
||||
runMode.value = snapshot.runMode
|
||||
fanLevel.value = snapshot.fanLevel
|
||||
uni.showToast({ title: getErrorMessage(err, '设置失败'), icon: 'none' })
|
||||
const fallback = bluetoothConnected.value ? '设置失败' : DEVICE_CONTROL_WAIT_TOAST
|
||||
const message = bluetoothConnected.value
|
||||
? getErrorMessage(err, fallback)
|
||||
: DEVICE_CONTROL_WAIT_TOAST
|
||||
uni.showToast({ title: message, icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,7 +289,15 @@ export function useDeviceDetail() {
|
||||
}
|
||||
|
||||
async function onConfirmFilterReplace() {
|
||||
await sendBleCommand(Z2_BLE_CMD.FILTER_RESET)
|
||||
if (!promptWaitForDeviceOnline()) return
|
||||
const ok = await sendBleCommand(Z2_BLE_CMD.FILTER_RESET)
|
||||
if (!ok) {
|
||||
uni.showToast({
|
||||
title: bluetoothConnected.value ? '操作失败,请重试' : DEVICE_CONTROL_WAIT_TOAST,
|
||||
icon: 'none',
|
||||
})
|
||||
return
|
||||
}
|
||||
filterReplaced.value = true
|
||||
filterLife.value = 100
|
||||
updateFilterRemainText()
|
||||
@@ -328,6 +354,8 @@ export function useDeviceDetail() {
|
||||
})
|
||||
})
|
||||
|
||||
usePageShowRefresh(() => refreshDeviceMeta(), { skipInitialShow: true })
|
||||
|
||||
return {
|
||||
deviceName,
|
||||
connectionText,
|
||||
|
||||
Reference in New Issue
Block a user