From 98402548eb3aec6d9e3d82f85abd8f62c83b96b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=8A=E5=B8=86?= <15818603+Osborn-lyf@user.noreply.gitee.com> Date: Thu, 29 Oct 2026 10:09:43 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=93=9D=E7=89=99bug=E8=A7=A3?= =?UTF-8?q?=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/hooks/use-page-show-refresh.ts | 30 +- src/manifest.json | 2 +- .../device/components/device-list/index.vue | 8 - .../ble-reconnect-loading/index.vue | 126 +++++++++ .../device/detail/device-bluetooth-read.ts | 56 +++- src/pages/device/detail/device-detail.scss | 15 + src/pages/device/detail/index.vue | 27 +- .../detail/use-device-bluetooth-sync.ts | 261 +++++++++++++++--- src/pages/device/detail/use-device-detail.ts | 120 ++++++-- src/pages/device/device-list-patch.ts | 106 ++++++- src/pages/device/device-presence-state.ts | 26 +- src/pages/device/device-presence.ts | 58 +++- src/pages/device/device.types.ts | 6 + src/pages/device/index.vue | 2 - .../device/settings/room/use-device-room.ts | 11 +- .../device/settings/use-device-settings.ts | 64 +++-- src/pages/device/use-device.ts | 15 +- src/pages/mine/notify/index.vue | 5 +- src/pages/mine/notify/notify.scss | 5 +- src/pages/mine/notify/notify.utils.ts | 12 +- src/pages/mine/notify/use-notify.ts | 3 +- .../support/support-device-consult.utils.ts | 53 +++- .../support/use-support-device-consult.ts | 11 +- src/utils/ble-device-id-cache.ts | 51 ++++ src/utils/bluetooth.ts | 54 +++- src/utils/message-push.ts | 27 +- src/utils/z2-ble-protocol.ts | 45 ++- src/utils/z2-ble.ts | 5 + 28 files changed, 1018 insertions(+), 186 deletions(-) create mode 100644 src/pages/device/detail/components/ble-reconnect-loading/index.vue create mode 100644 src/utils/ble-device-id-cache.ts diff --git a/src/hooks/use-page-show-refresh.ts b/src/hooks/use-page-show-refresh.ts index 8c309f9..bec5609 100644 --- a/src/hooks/use-page-show-refresh.ts +++ b/src/hooks/use-page-show-refresh.ts @@ -1,20 +1,44 @@ import { onShow } from '@dcloudio/uni-app' +function clearStaleNativeLoading() { + try { + uni.hideLoading() + } catch { + // 部分端无 loading 时 hideLoading 可能抛错,忽略即可 + } +} + /** * 页面再次显示时执行刷新(从子页返回、切换 Tab 等)。 - * skipInitialShow:首屏由 onLoad 加载时设为 true,避免与 onLoad 重复请求。 + * - skipInitialShow:首屏由 onLoad 加载时设为 true,避免与 onLoad 重复请求 + * - 自动清掉残留的原生 showLoading(避免改名等流程的 loading 串到其他页) + * - 短防抖 + 进行中跳过,避免连点返回/快速切页触发重复请求或闪提示 */ export function usePageShowRefresh( handler: () => void | Promise, - options?: { skipInitialShow?: boolean }, + options?: { skipInitialShow?: boolean; debounceMs?: number }, ) { let skipFirst = Boolean(options?.skipInitialShow) + let inflight = false + let timer: ReturnType | undefined + const debounceMs = options?.debounceMs ?? 280 onShow(() => { + clearStaleNativeLoading() if (skipFirst) { skipFirst = false return } - void handler() + if (timer) clearTimeout(timer) + timer = setTimeout(() => { + if (inflight) return + inflight = true + Promise.resolve() + .then(() => handler()) + .catch(() => {}) + .finally(() => { + inflight = false + }) + }, debounceMs) }) } diff --git a/src/manifest.json b/src/manifest.json index fa7c96f..fa1dfca 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name" : "虫子智家", "appid" : "__UNI__925D0CC", "description" : "", - "versionName" : "1.1.9", + "versionName" : "1.2.2", "versionCode" : "100", "transformPx" : false, /* 5+App特有相关 */ diff --git a/src/pages/device/components/device-list/index.vue b/src/pages/device/components/device-list/index.vue index 9a12df4..90fee7e 100644 --- a/src/pages/device/components/device-list/index.vue +++ b/src/pages/device/components/device-list/index.vue @@ -7,7 +7,6 @@ {{ onlineCount }} 台在线 - 管理 > @@ -31,7 +30,6 @@ defineProps<{ }>() defineEmits<{ - manage: [] select: [device: DeviceListItem] }>() @@ -44,7 +42,6 @@ defineEmits<{ .device-list__head { display: flex; align-items: center; - justify-content: space-between; margin-bottom: 24rpx; } @@ -72,11 +69,6 @@ defineEmits<{ line-height: 1; } -.device-list__manage { - font-size: 26rpx; - color: $color-text-secondary; -} - .device-list__grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); diff --git a/src/pages/device/detail/components/ble-reconnect-loading/index.vue b/src/pages/device/detail/components/ble-reconnect-loading/index.vue new file mode 100644 index 0000000..6422505 --- /dev/null +++ b/src/pages/device/detail/components/ble-reconnect-loading/index.vue @@ -0,0 +1,126 @@ + + + + + diff --git a/src/pages/device/detail/device-bluetooth-read.ts b/src/pages/device/detail/device-bluetooth-read.ts index 6fb6e91..619838f 100644 --- a/src/pages/device/detail/device-bluetooth-read.ts +++ b/src/pages/device/detail/device-bluetooth-read.ts @@ -1,8 +1,9 @@ import { mapZ2StateToRuntimePatch, + Z2_BLE_CMD, type Z2AirQuality, } from '@/utils/z2-ble-protocol' -import { queryZ2BleState } from '@/utils/z2-ble' +import { queryZ2BleState, sendZ2BleCommand } from '@/utils/z2-ble' import type { UpdateDeviceRuntimeBody } from './device-detail.types' export type BleRuntimePatch = Partial & { @@ -11,12 +12,61 @@ export type BleRuntimePatch = Partial & { airQuality?: Z2AirQuality } -/** 通过 Z2 BLE 协议查询设备运行数据 */ +function toUpdateRuntimeBody(patch: BleRuntimePatch): Partial { + const { + runMode, + fanLevel, + tvoc, + powerMode, + deviceBattery, + filterLife, + charging, + status, + bluetoothConnected, + signalLevel, + } = patch + return { + ...(runMode != null ? { runMode } : {}), + ...(fanLevel != null ? { fanLevel } : {}), + ...(tvoc != null ? { tvoc } : {}), + ...(powerMode != null ? { powerMode } : {}), + ...(deviceBattery != null ? { deviceBattery } : {}), + ...(filterLife != null ? { filterLife } : {}), + ...(charging != null ? { charging } : {}), + ...(status != null ? { status } : {}), + ...(bluetoothConnected != null ? { bluetoothConnected } : {}), + ...(signalLevel != null ? { signalLevel } : {}), + } +} + +/** 通过 Z2 BLE 协议查询设备运行数据(Q 全量 + I 滤芯,滤芯始终单独查) */ export async function readRuntimeFromBle( bleDeviceId: string, ): Promise { if (typeof uni.readBLECharacteristicValue !== 'function') return {} const state = await queryZ2BleState(bleDeviceId) - return mapZ2StateToRuntimePatch(state) + let patch = mapZ2StateToRuntimePatch(state) + + // 滤芯衰减靠嵌入式维护,Q 里经常没有;每次同步都发 I,避免一直显示云端旧百分比 + try { + const filterState = await sendZ2BleCommand(bleDeviceId, Z2_BLE_CMD.QUERY_FILTER, { + timeoutMs: 4000, + }) + const filterPatch = mapZ2StateToRuntimePatch(filterState) + if (filterPatch.filterLife != null) { + patch = { ...patch, filterLife: filterPatch.filterLife } + } else if (import.meta.env.DEV || import.meta.env.VITE_BLE_DEBUG === 'true') { + console.log('[Z2 BLE] filter query returned no filterLife', filterState) + } + } catch (err) { + if (import.meta.env.DEV || import.meta.env.VITE_BLE_DEBUG === 'true') { + console.log('[Z2 BLE] filter query failed', err) + } + } + + return { + ...toUpdateRuntimeBody(patch), + ...(patch.airQuality != null ? { airQuality: patch.airQuality } : {}), + } } diff --git a/src/pages/device/detail/device-detail.scss b/src/pages/device/detail/device-detail.scss index 1b3c424..32edb6d 100644 --- a/src/pages/device/detail/device-detail.scss +++ b/src/pages/device/detail/device-detail.scss @@ -97,11 +97,26 @@ } } +.device-detail-hero__status-spinner { + width: 20rpx; + height: 20rpx; + border-radius: 50%; + border: 3rpx solid rgba(255, 255, 255, 0.35); + border-top-color: #fff; + animation: device-detail-status-spin 0.8s linear infinite; +} + .device-detail-hero__status-text { font-size: 24rpx; color: rgba(255, 255, 255, 0.92); } +@keyframes device-detail-status-spin { + to { + transform: rotate(360deg); + } +} + .device-detail-hero__metric-row { position: relative; z-index: 1; diff --git a/src/pages/device/detail/index.vue b/src/pages/device/detail/index.vue index 69ed706..96b0b18 100644 --- a/src/pages/device/detail/index.vue +++ b/src/pages/device/detail/index.vue @@ -22,6 +22,12 @@