From d574565fb3e9915f17855a10b5d177c53d22ae2d 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, 5 Nov 2026 13:54:05 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E6=9B=B4=E6=96=B0=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E5=86=85=E5=AE=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/manifest.json | 10 +-
src/pages/add-device/add-device.scss | 13 +
src/pages/add-device/index.vue | 28 +-
src/pages/add-device/use-add-device.ts | 96 ++++-
.../device/components/hot-devices/index.vue | 105 ------
src/pages/device/device.types.ts | 6 -
.../components/location-map/index.vue | 337 +++++++++++++++---
.../home-manage/location/home-location.scss | 48 ++-
.../device/home-manage/location/index.vue | 76 +++-
.../home-manage/location/use-home-location.ts | 240 ++++++++-----
src/pages/device/index.vue | 12 +-
src/pages/device/use-device.ts | 22 +-
src/pages/mine/edit/use-edit-profile.ts | 12 +-
src/pages/mine/privacy/index.vue | 2 +-
src/static/icon-map-pin.png | Bin 0 -> 369 bytes
src/utils/bluetooth.ts | 74 +++-
src/utils/static-assets.ts | 2 +
17 files changed, 782 insertions(+), 301 deletions(-)
delete mode 100644 src/pages/device/components/hot-devices/index.vue
create mode 100644 src/static/icon-map-pin.png
diff --git a/src/manifest.json b/src/manifest.json
index f7027b4..25f4b54 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -2,7 +2,7 @@
"name" : "虫子智家",
"appid" : "__UNI__925D0CC",
"description" : "",
- "versionName" : "1.2.3",
+ "versionName" : "1.2.4",
"versionCode" : "100",
"transformPx" : false,
/* 5+App特有相关 */
@@ -70,6 +70,14 @@
"version" : "2",
"offline" : false
}
+ },
+ "geolocation" : {
+ "amap" : {
+ "name" : "",
+ "__platform__" : [ "ios", "android" ],
+ "appkey_ios" : "7d9a3ca1ef32775dd5cef9b11962ca49",
+ "appkey_android" : "6b0279ce51355d222b5023c1124f4581"
+ }
}
},
"icons" : {
diff --git a/src/pages/add-device/add-device.scss b/src/pages/add-device/add-device.scss
index d54f8f7..ef6d468 100644
--- a/src/pages/add-device/add-device.scss
+++ b/src/pages/add-device/add-device.scss
@@ -10,6 +10,19 @@
width: 100%;
}
+.add-device-page__checking {
+ flex: 1;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 120rpx 48rpx;
+}
+
+.add-device-page__checking-text {
+ font-size: 28rpx;
+ color: #98a2b3;
+}
+
.add-device-page__body {
padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
}
diff --git a/src/pages/add-device/index.vue b/src/pages/add-device/index.vue
index 995d94e..545f217 100644
--- a/src/pages/add-device/index.vue
+++ b/src/pages/add-device/index.vue
@@ -1,7 +1,10 @@
-
+
+ 正在检测蓝牙…
+
+
@@ -30,16 +33,35 @@
diff --git a/src/pages/add-device/use-add-device.ts b/src/pages/add-device/use-add-device.ts
index 0f384ea..881974d 100644
--- a/src/pages/add-device/use-add-device.ts
+++ b/src/pages/add-device/use-add-device.ts
@@ -4,7 +4,9 @@ import {
getBluetoothErrorMessage,
isBluetoothApiSupported,
isBluetoothPermissionError,
+ probeBluetoothEnabledForBind,
promptEnableBluetooth,
+ subscribeBluetoothAdapterStateChange,
} from '@/utils/bluetooth'
import { parseId } from '@/utils/device-id'
import { readStoredHomeId } from '@/utils/selected-home'
@@ -42,7 +44,13 @@ export const BIND_FEATURES: BindFeatureItem[] = [
export function useAddDevice() {
const currentStep = 1
const opening = ref(false)
+ /** 进入页时检测蓝牙,未完成前不闪引导内容 */
+ const checkingBluetooth = ref(true)
const bindHomeId = ref('')
+ let routingToScan = false
+ /** 仅用户去系统设置开启蓝牙后,回页才复检;避免系统弹窗触发 onShow 误跳扫描 */
+ let awaitingBluetoothSettings = false
+ let unsubscribeAdapterState: (() => void) | undefined
function applyBindHomeId(homeId?: string | number) {
const parsed = parseId(homeId)
@@ -55,8 +63,80 @@ export function useAddDevice() {
}
}
+ function scanPageUrl() {
+ const q = bindHomeId.value ? `?homeId=${bindHomeId.value}` : ''
+ return `/pages/add-device/scan/index${q}`
+ }
+
+ function goScanPage(replace = false) {
+ if (routingToScan) return
+ routingToScan = true
+ awaitingBluetoothSettings = false
+ stopWatchBluetoothOn()
+ const url = scanPageUrl()
+ if (replace) {
+ uni.redirectTo({
+ url,
+ fail: () => {
+ routingToScan = false
+ uni.navigateTo({ url })
+ },
+ })
+ return
+ }
+ uni.navigateTo({
+ url,
+ complete: () => {
+ routingToScan = false
+ },
+ })
+ }
+
+ function stopWatchBluetoothOn() {
+ unsubscribeAdapterState?.()
+ unsubscribeAdapterState = undefined
+ }
+
+ /** 停留在引导页时监听:用户一开蓝牙立即进扫描 */
+ function startWatchBluetoothOn() {
+ if (unsubscribeAdapterState || routingToScan || !isBluetoothApiSupported()) return
+ unsubscribeAdapterState = subscribeBluetoothAdapterStateChange((res) => {
+ if (!res.available || routingToScan) return
+ goScanPage(true)
+ })
+ }
+
+ /**
+ * 蓝牙已开则直进扫描页;未开则展示本页引导并开始监听开启事件。
+ * @param silent 从设置返回时静默复检,不闪「正在检测」
+ */
+ async function checkBluetoothAndRoute(options?: { silent?: boolean }) {
+ if (routingToScan) return
+ const silent = Boolean(options?.silent)
+ if (!silent) checkingBluetooth.value = true
+ try {
+ if (!isBluetoothApiSupported()) {
+ return
+ }
+ await probeBluetoothEnabledForBind()
+ goScanPage(true)
+ } catch {
+ // 未开启 / 无权限:停留在引导页,并监听随后开启
+ startWatchBluetoothOn()
+ } finally {
+ if (!silent) checkingBluetooth.value = false
+ }
+ }
+
+ /** 从系统设置返回时调用:仅在主动去开启后复检;平时靠适配器状态监听即时跳转 */
+ function onPageShowAfterSettings() {
+ if (!awaitingBluetoothSettings || checkingBluetooth.value || routingToScan) return
+ awaitingBluetoothSettings = false
+ void checkBluetoothAndRoute({ silent: true })
+ }
+
async function onOpenBluetooth() {
- if (opening.value) return
+ if (opening.value || routingToScan) return
opening.value = true
try {
if (!isBluetoothApiSupported()) {
@@ -69,8 +149,7 @@ export function useAddDevice() {
return
}
await assertBluetoothEnabledForScan()
- const q = bindHomeId.value ? `?homeId=${bindHomeId.value}` : ''
- uni.navigateTo({ url: `/pages/add-device/scan/index${q}` })
+ goScanPage(false)
} catch (err) {
if (isBluetoothPermissionError(err)) {
uni.showModal({
@@ -81,6 +160,8 @@ export function useAddDevice() {
})
return
}
+ awaitingBluetoothSettings = true
+ startWatchBluetoothOn()
promptEnableBluetooth()
} finally {
opening.value = false
@@ -88,13 +169,22 @@ export function useAddDevice() {
}
function onBindLater() {
+ stopWatchBluetoothOn()
uni.navigateBack()
}
+ function onPageUnload() {
+ stopWatchBluetoothOn()
+ }
+
return {
currentStep,
opening,
+ checkingBluetooth,
applyBindHomeId,
+ checkBluetoothAndRoute,
+ onPageShowAfterSettings,
+ onPageUnload,
onOpenBluetooth,
onBindLater,
}
diff --git a/src/pages/device/components/hot-devices/index.vue b/src/pages/device/components/hot-devices/index.vue
deleted file mode 100644
index 5571222..0000000
--- a/src/pages/device/components/hot-devices/index.vue
+++ /dev/null
@@ -1,105 +0,0 @@
-
-
-
- 热门设备
- 去商城看看 >
-
-
-
-
-
- {{ item.name }}
- {{ item.desc }}
-
-
-
-
-
-
-
-
-
diff --git a/src/pages/device/device.types.ts b/src/pages/device/device.types.ts
index 9a3a733..96b9826 100644
--- a/src/pages/device/device.types.ts
+++ b/src/pages/device/device.types.ts
@@ -4,12 +4,6 @@ export interface RoomTab {
locationId?: string | number
}
-export interface HotDeviceItem {
- id: string
- name: string
- desc: string
-}
-
/** POST /app/device/list 查询参数(按家庭/房间筛选) */
export interface DeviceQueryBody {
homeId?: string | number
diff --git a/src/pages/device/home-manage/location/components/location-map/index.vue b/src/pages/device/home-manage/location/components/location-map/index.vue
index 994be62..2c8527b 100644
--- a/src/pages/device/home-manage/location/components/location-map/index.vue
+++ b/src/pages/device/home-manage/location/components/location-map/index.vue
@@ -1,7 +1,8 @@
+
+ @updated="onMapUpdated"
+ >
+
+
+
+
+
+ ◎
+
+
+
+
+
-
-
+
+
+ ◎
+
+
diff --git a/src/pages/device/home-manage/location/use-home-location.ts b/src/pages/device/home-manage/location/use-home-location.ts
index f196bdd..4671c25 100644
--- a/src/pages/device/home-manage/location/use-home-location.ts
+++ b/src/pages/device/home-manage/location/use-home-location.ts
@@ -1,6 +1,6 @@
import { onLoad, onUnload } from '@dcloudio/uni-app'
-import type { Ref } from 'vue'
-import { ref } from 'vue'
+import type { ComponentInternalInstance } from 'vue'
+import { computed, ref } from 'vue'
import {
buildUpdateHomeBody,
isValidHomeName,
@@ -15,19 +15,16 @@ import {
} from '@/utils/amap'
import { ensureLocationPermission, getLocationFailHint } from '@/utils/location-permission'
import { formatCoordinateAddress } from '@/utils/map-geocode'
+import { staticAssets } from '@/utils/static-assets'
import { loadHomeGeo, saveHomeGeo } from '../use-home-manage'
import type { HomeGeoInfo } from '../home-manage.types'
const DEFAULT_LATITUDE = 39.9042
const DEFAULT_LONGITUDE = 116.4074
-
-interface LocationMapExpose {
- moveTo: (lng: number, lat: number) => void
- moveToUserLocation: () => void
-}
+const MAP_ID = 'home-location-map'
interface UseHomeLocationOptions {
- locationMapRef?: Ref
+ pageInstance?: ComponentInternalInstance | null
}
async function requestUserLocation(): Promise {
@@ -53,16 +50,41 @@ export function useHomeLocation(options: UseHomeLocationOptions = {}) {
const saving = ref(false)
const latitude = ref(DEFAULT_LATITUDE)
const longitude = ref(DEFAULT_LONGITUDE)
+ const mapCenterReady = ref(false)
const searchKeyword = ref('')
const addressText = ref('')
const locating = ref(false)
const resolvingAddress = ref(false)
- const mapReady = ref(false)
+ const choosingLocation = ref(false)
const searchVisible = ref(false)
const searchCity = ref('')
+
let geocodeTimer: ReturnType | null = null
- let pendingMapCenter: { lng: number; lat: number } | null = null
let disposed = false
+ let mapCtx: UniApp.MapContext | null = null
+
+ /**
+ * 根因:App-vue 的