fix:最新

This commit is contained in:
李伊帆
2026-10-23 10:26:54 +08:00
parent e4276b0853
commit 28531c8120
104 changed files with 3248 additions and 722 deletions

View File

@@ -45,9 +45,8 @@ export function useDeviceDetail() {
const deviceStatus = ref<string>()
const bluetoothConnected = ref(false)
const charging = ref(false)
const isOnline = ref(false)
const loading = ref(false)
const updating = ref(false)
const isOnline = computed(() => bluetoothConnected.value)
const runMode = ref<RunMode>('0')
const fanLevel = ref<FanLevel>('0')
@@ -148,13 +147,15 @@ export function useDeviceDetail() {
filterLife.value = view.filterLife
filterRemainText.value = view.filterRemainText
filterReplaced.value = view.filterReplaced
isOnline.value = view.isOnline
if (data.deviceBattery != null) applyBatteryLevel(data.deviceBattery, false)
if (data.status !== undefined) deviceStatus.value = data.status
if (!bluetoothConnected.value && data.status !== undefined) {
deviceStatus.value = data.status
}
}
async function refreshDeviceMeta() {
if (!deviceId.value) return
const bleConnectedLocally = bluetoothConnected.value
try {
const list = await fetchDeviceList()
const device = list?.find((item) => String(item.deviceId) === deviceId.value)
@@ -171,10 +172,13 @@ export function useDeviceDetail() {
const matched = locations.find((item) => sameId(item.locationId, parsedLocationId))
if (matched) locationName.value = matched.name
}
bluetoothConnected.value = isBluetoothConnected(device.bluetoothConnected)
charging.value = device.charging === '1'
if (device.status !== undefined) deviceStatus.value = device.status
isOnline.value = device.status === '1'
if (!bleConnectedLocally) {
bluetoothConnected.value = isBluetoothConnected(device.bluetoothConnected)
deviceStatus.value = bluetoothConnected.value
? '1'
: (device.status === '0' ? '0' : '2')
}
} catch {
// 列表刷新失败时保留路由参数状态
}
@@ -198,28 +202,37 @@ export function useDeviceDetail() {
}
async function patchRuntime(patch: { runMode?: RunMode; fanLevel?: FanLevel }) {
if (!deviceId.value || updating.value) return
updating.value = true
if (!deviceId.value) return
if (patch.runMode != null && runMode.value === patch.runMode) return
if (patch.fanLevel != null && fanLevel.value === patch.fanLevel) return
const snapshot = { runMode: runMode.value, fanLevel: fanLevel.value }
if (patch.runMode != null) runMode.value = patch.runMode
if (patch.fanLevel != null) fanLevel.value = patch.fanLevel
const bleCmd = patch.runMode != null
? encodeRunModeBleCommand(patch.runMode)
: patch.fanLevel != null
? encodeFanLevelBleCommand(patch.fanLevel)
: undefined
try {
const bleCmd = patch.runMode != null
? encodeRunModeBleCommand(patch.runMode)
: patch.fanLevel != null
? encodeFanLevelBleCommand(patch.fanLevel)
: undefined
if (bleCmd) {
await sendBleCommand(bleCmd)
}
await updateDeviceRuntime({
const apiTask = updateDeviceRuntime({
deviceId: deviceId.value,
...patch,
})
const data = await fetchDeviceRuntime({ deviceId: deviceId.value })
applyRuntime(data)
await refreshDeviceMeta()
if (bleCmd) {
const [bleOk] = await Promise.all([sendBleCommand(bleCmd), apiTask])
if (!bleOk) {
throw new Error('蓝牙指令发送失败')
}
} else {
await apiTask
}
} catch (err) {
runMode.value = snapshot.runMode
fanLevel.value = snapshot.fanLevel
uni.showToast({ title: getErrorMessage(err, '设置失败'), icon: 'none' })
} finally {
updating.value = false
}
}
@@ -278,10 +291,7 @@ export function useDeviceDetail() {
}),
onBluetoothConnectedChange: (connected) => {
bluetoothConnected.value = connected
if (connected) {
isOnline.value = true
deviceStatus.value = '1'
}
deviceStatus.value = connected ? '1' : '2'
},
onSyncTextChange: (text) => {
syncText.value = text
@@ -309,12 +319,9 @@ export function useDeviceDetail() {
const parsedHomeId = parseId(query?.homeId)
if (parsedHomeId) homeId.value = parsedHomeId
if (query?.model) productModel.value = decodeURIComponent(String(query.model))
if (query?.status) {
deviceStatus.value = String(query.status)
isOnline.value = query.status === '1'
}
if (query?.mac) deviceMac.value = decodeURIComponent(String(query.mac))
bluetoothConnected.value = isBluetoothConnected(query?.bluetoothConnected)
bluetoothConnected.value = false
deviceStatus.value = '2'
charging.value = query?.charging === '1'
void loadRuntime().then(() => {
startSyncLoop()