diff --git a/src/App.vue b/src/App.vue index 9e62649..367cb56 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,13 +1,11 @@ diff --git a/src/hooks/use-page-show-refresh.ts b/src/hooks/use-page-show-refresh.ts new file mode 100644 index 0000000..8c309f9 --- /dev/null +++ b/src/hooks/use-page-show-refresh.ts @@ -0,0 +1,20 @@ +import { onShow } from '@dcloudio/uni-app' + +/** + * 页面再次显示时执行刷新(从子页返回、切换 Tab 等)。 + * skipInitialShow:首屏由 onLoad 加载时设为 true,避免与 onLoad 重复请求。 + */ +export function usePageShowRefresh( + handler: () => void | Promise, + options?: { skipInitialShow?: boolean }, +) { + let skipFirst = Boolean(options?.skipInitialShow) + + onShow(() => { + if (skipFirst) { + skipFirst = false + return + } + void handler() + }) +} diff --git a/src/manifest.json b/src/manifest.json index 64fc1e0..fa7c96f 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name" : "虫子智家", "appid" : "__UNI__925D0CC", "description" : "", - "versionName" : "1.1.6", + "versionName" : "1.1.9", "versionCode" : "100", "transformPx" : false, /* 5+App特有相关 */ @@ -21,8 +21,7 @@ "Bluetooth" : {}, "Camera" : {}, "Push" : {}, - "Maps" : {}, - "Geolocation" : {} + "Maps" : {} }, /* 应用发布信息 */ "distribute" : { @@ -41,7 +40,6 @@ "", "", "", - "", "", "", "", @@ -56,11 +54,7 @@ }, /* ios打包配置 */ "ios" : { - "dSYMs" : false, - "privacyDescription" : { - "NSLocationWhenInUseUsageDescription" : "你的位置信息将用于在地图上选择家庭位置", - "NSLocationAlwaysAndWhenInUseUsageDescription" : "你的位置信息将用于在地图上选择家庭位置" - } + "dSYMs" : false }, /* SDK配置 */ "sdkConfigs" : { diff --git a/src/pages/add-device/complete/complete.api.ts b/src/pages/add-device/complete/complete.api.ts index 155767c..d982673 100644 --- a/src/pages/add-device/complete/complete.api.ts +++ b/src/pages/add-device/complete/complete.api.ts @@ -10,7 +10,10 @@ function normalizeProductOption(item: ProductOption): ProductOption { } } -/** GET /app/device/productOptions — 获取产品型号下拉列表 */ +/** + * GET /app/device/productOptions + * 返回所有启用状态的产品型号,供添加设备页下拉选择;无需再传 status。 + */ export function fetchProductOptions() { return request({ url: '/app/device/productOptions', diff --git a/src/pages/add-device/complete/complete.types.ts b/src/pages/add-device/complete/complete.types.ts index b2c8603..2039666 100644 --- a/src/pages/add-device/complete/complete.types.ts +++ b/src/pages/add-device/complete/complete.types.ts @@ -1,11 +1,6 @@ -/** POST /app/device/productOptions 返回项 */ +/** GET /app/device/productOptions — 启用状态产品型号(AppProductOptionVo) */ export interface ProductOption { productId?: string | number model?: string name?: string - category?: string - connectTypes?: string - filterEnabled?: boolean - filterTotalDays?: number - capabilities?: string[] } diff --git a/src/pages/add-device/complete/use-complete-device.ts b/src/pages/add-device/complete/use-complete-device.ts index 96d2f64..fd6e03b 100644 --- a/src/pages/add-device/complete/use-complete-device.ts +++ b/src/pages/add-device/complete/use-complete-device.ts @@ -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) { 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() diff --git a/src/pages/change-password/use-change-password.ts b/src/pages/change-password/use-change-password.ts index f9007c7..045dd86 100644 --- a/src/pages/change-password/use-change-password.ts +++ b/src/pages/change-password/use-change-password.ts @@ -1,38 +1,39 @@ import { onLoad } from '@dcloudio/uni-app' import { ref } from 'vue' -import { teardownMessageInbox } from '@/hooks/use-message-inbox' -import { ApiError, getErrorMessage } from '@/utils/api-error' -import { clearStoredToken } from '@/utils/auth-token' -import { markPasswordModified } from '@/utils/password-modified-at' +import { getErrorMessage } from '@/utils/api-error' +import { + handleAuthSessionExpired, + isAuthSessionExpiredError, +} from '@/utils/auth-session' +import { markPasswordModifiedPendingForPhone } from '@/utils/password-modified-at' import { isValidStrongPassword, PASSWORD_INVALID_TOAST } from '@/utils/validate' import { resetPasswordByToken } from './change-password.api' -const LOGIN_ROUTE = '/pages/login/index' - -function isSessionInvalidError(err: unknown): boolean { - if (!(err instanceof ApiError)) return false - if (err.code === 401) return true - return /登录|token|认证|授权/i.test(err.message) +function redirectToLoginAfterPasswordChange(toastTitle = '密码修改成功,请重新登录') { + handleAuthSessionExpired({ + message: toastTitle, + forceNavigateToLogin: true, + }) } -function redirectToLoginAfterPasswordChange(toastTitle = '密码修改成功,请重新登录') { - teardownMessageInbox() - clearStoredToken() - uni.showToast({ title: toastTitle, icon: 'none' }) - setTimeout(() => { - uni.reLaunch({ url: LOGIN_ROUTE }) - }, 800) +/** 改密后勿再请求 profile,避免 401 触发全局踢登抢占跳转 */ +function recordPasswordModifiedAfterReset(fallbackPhone: string) { + if (!fallbackPhone.trim()) return + markPasswordModifiedPendingForPhone(fallbackPhone) } export function useChangePassword() { const password = ref('') const confirmPassword = ref('') const resetToken = ref('') + const boundPhone = ref('') const loading = ref(false) onLoad((query) => { const raw = (query?.resetToken as string) || '' resetToken.value = raw ? decodeURIComponent(raw) : '' + const phoneRaw = (query?.phone as string) || '' + boundPhone.value = phoneRaw ? decodeURIComponent(phoneRaw) : '' if (!resetToken.value) { uni.showToast({ title: '请先完成验证码校验', icon: 'none' }) setTimeout(() => uni.navigateBack(), 1500) @@ -60,11 +61,11 @@ export function useChangePassword() { newPassword: password.value, confirmPassword: confirmPassword.value, }) - markPasswordModified() + recordPasswordModifiedAfterReset(boundPhone.value) redirectToLoginAfterPasswordChange() } catch (err) { - if (isSessionInvalidError(err)) { - markPasswordModified() + if (isAuthSessionExpiredError(err)) { + recordPasswordModifiedAfterReset(boundPhone.value) redirectToLoginAfterPasswordChange('登录状态已失效,请使用新密码重新登录') return } diff --git a/src/pages/device/components/device-header/index.vue b/src/pages/device/components/device-header/index.vue index d806b94..d4ceeaa 100644 --- a/src/pages/device/components/device-header/index.vue +++ b/src/pages/device/components/device-header/index.vue @@ -21,28 +21,36 @@ v-if="pickerOpen" class="device-header__mask" @tap="closePicker" + @touchmove.stop.prevent="preventTouchMove" /> - - - {{ home.homeName || '我的家' }} - - - + + {{ home.homeName || '我的家' }} + + + + 家庭管理 @@ -79,7 +87,7 @@ diff --git a/src/pages/mine/support/index.vue b/src/pages/mine/support/index.vue index e9567f0..430031e 100644 --- a/src/pages/mine/support/index.vue +++ b/src/pages/mine/support/index.vue @@ -1,4 +1,4 @@ -