fix:bug解决

This commit is contained in:
李伊帆
2026-10-28 10:36:39 +08:00
parent c369127166
commit 91bca314ba
57 changed files with 2839 additions and 384 deletions

View File

@@ -4,13 +4,12 @@ import { resolveValidHomeId } from '@/api/home'
import { getErrorMessage } from '@/utils/api-error'
import { fetchRoomList } from '@/api/location'
import type { RoomOption } from '@/types/location'
import { fetchDeviceList } from '@/pages/device/device.api'
import { fetchAllDeviceList } from '@/pages/device/device.api'
import { updateDeviceRuntime } from '@/pages/device/detail/device-detail.api'
import { updateDeviceSettings } from '@/pages/device/settings/device-settings.api'
import { buildBleDeviceName, isStandardBleDeviceName } from '@/utils/ble-device-name'
import { releaseBleDevice } from '@/utils/bluetooth'
import { clearZ2BleHandleCache, sendZ2BleRenameCommand } from '@/utils/z2-ble'
import { getZ2RenameProgressLabel } from '@/utils/z2-ble-protocol'
import { bindDevice } from '../add-device.api'
import { parseId, sameId } from '@/utils/device-id'
import { readStoredHomeId, saveSelectedHomeId } from '@/utils/selected-home'
@@ -22,6 +21,8 @@ export function useCompleteDevice() {
const currentStep = 4
const deviceNo = ref('')
const deviceName = ref('Z2 空气净化器')
/** 配对时读到的 BLE 广播名,与用户可改的云端显示名无关 */
const pairedBleName = ref('')
const serialMasked = ref('****A3B2')
const productId = ref('')
const model = ref('')
@@ -142,7 +143,10 @@ export function useCompleteDevice() {
function applyQuery(query: Record<string, string | undefined>) {
const ctx = readBindDeviceContext(query)
if (ctx.deviceNo) deviceNo.value = ctx.deviceNo
if (ctx.name) deviceName.value = ctx.name
if (ctx.name) {
deviceName.value = ctx.name
pairedBleName.value = ctx.name
}
if (ctx.serialMasked) serialMasked.value = ctx.serialMasked
const parsedProductId = parseId(ctx.productId)
if (parsedProductId) productId.value = parsedProductId
@@ -246,23 +250,15 @@ export function useCompleteDevice() {
try {
if (bleDeviceId.value && bluetoothConnected.value && mac.value) {
const bleName = buildBleDeviceName(mac.value)
const needRename = !isStandardBleDeviceName(mac.value, deviceName.value)
const needRename = pairedBleName.value
&& !isStandardBleDeviceName(mac.value, pairedBleName.value)
if (needRename) {
uni.showLoading({ title: '正在同步蓝牙名称…', mask: true })
try {
await sendZ2BleRenameCommand(bleDeviceId.value, bleName, {
timeoutMs: 25000,
onProgress: (progress) => {
uni.showLoading({
title: getZ2RenameProgressLabel(progress) || '正在同步蓝牙名称…',
mask: true,
})
},
})
} catch {
// 蓝牙名称同步失败不影响云端绑定,静默继续
} finally {
uni.hideLoading()
}
}
}
@@ -281,7 +277,7 @@ export function useCompleteDevice() {
...(locationId.value ? { locationId: locationId.value } : {}),
})
const list = await fetchDeviceList()
const list = await fetchAllDeviceList()
const bound = list?.find((item) => item.deviceNo === deviceNo.value.trim())
if (bound?.deviceId != null) {
const boundName = bound.name?.trim()