Explorar el Código

Merge branch 'refs/heads/dev' into jiapu_aijiuyi

jiapu hace 3 meses
padre
commit
1460f3bc7a

+ 3 - 3
code/ajyApp/pages/device/detail/detail.nvue

@@ -110,9 +110,9 @@ export default {
 	onLoad(options) {
 		const sysInfo = uni.getSystemInfoSync()
 		this.statusBarHeight = sysInfo.statusBarHeight || 44
-		this.name = options.name || ''
-		this.deviceId = options.deviceId || ''
-		this.rssi = options.rssi || ''
+		this.name = decodeURIComponent(options.name || '')
+		this.deviceId = decodeURIComponent(options.deviceId || '')
+		this.rssi = decodeURIComponent(options.rssi || '')
 	},
 	async onShow() {
 		const bleStore = useBleStore()

+ 6 - 4
code/ajyApp/pages/device/deviceInfo/deviceInfo.nvue

@@ -366,9 +366,9 @@ export default {
 		const sysInfo = uni.getSystemInfoSync()
 		this.statusBarHeight = sysInfo.statusBarHeight || 44
 
-		this.deviceId = options.deviceId || ''
-		this.deviceName = options.name || ''
-		this.rssi = options.rssi || ''
+		this.deviceId = decodeURIComponent(options.deviceId || '')
+		this.deviceName = decodeURIComponent(options.name || '')
+		this.rssi = decodeURIComponent(options.rssi || '')
 
 		// TODO: 后续接口确定后实现 - 下载穴位列表
 		// TODO: 后续接口确定后实现 - 下载专业模式推荐方案
@@ -383,7 +383,9 @@ export default {
 	},
 	onUnload() {
 		this.destroyAudio()
-		this.disconnectBle()
+		// 离开页面时不断开蓝牙连接,仅停止扫描
+		// 下次进入相同设备可复用连接
+		this.cleanupOnLeave()
 	},
 	methods: {
 		goBack() {

+ 33 - 3
code/ajyApp/pages/device/deviceInfo/mixins/ble-mixin.js

@@ -5,7 +5,7 @@
  */
 import { useBleStore } from '@/stores/ble'
 import { MODE, MOXI_STATE, POWER, MUTE, TEMPERATURE, CHAIR_ANGLE } from '@/utils/ble/constants.js'
-import { ensureBlePrerequisite } from '@/utils/ble/permission.js'
+import { ensureBlePrerequisite, openBluetoothSettings, openLocationSettings } from '@/utils/ble/permission.js'
 
 export default {
 	data() {
@@ -61,13 +61,35 @@ export default {
 					this.$refs.ayToast.error('请开启位置服务后重试')
 					return
 				}
+				if (e.message === 'BLE_ADAPTER_OFF') {
+					uni.showModal({
+						title: '提示',
+						content: '蓝牙未开启,请先开启蓝牙',
+						cancelText: '取消',
+						confirmText: '去开启',
+						success: (res) => {
+							if (res.confirm) {
+								openBluetoothSettings()
+							}
+						}
+					})
+					return
+				}
+			}
+
+			// 2. 判断当前是否已连接同一设备,如果是则跳过重连
+			const currentDevice = this.bleStore.device
+			console.log('[BLE] 当前设备', currentDevice,this.bleStore.linked,this.deviceId)
+			if (this.bleStore.linked && currentDevice && currentDevice.deviceId === this.deviceId) {
+				console.log('[BLE] 已连接相同设备,跳过重连', this.deviceId)
+				return
 			}
 
-			// 2. 断开旧连接并关闭适配器(不解绑全局监听器)
+			// 3. 不同设备或未连接:断开旧连接并关闭适配器(不解绑全局监听器)
 			try { await this.bleStore.disconnect() } catch (_) {}
 			try { await this.bleStore.resetAdapter() } catch (_) {}
 
-			// 3. 扫描并连接设备(优先直连,跳过扫描避免 Android 限流)
+			// 4. 扫描并连接设备(优先直连,跳过扫描避免 Android 限流)
 			try {
 				const scanOpt = { timeout: 8000 }
 				// 已有 deviceId 时优先直连,不需要扫描
@@ -194,6 +216,14 @@ export default {
 			this.bleStore.disconnect().catch(() => {})
 		},
 
+		/**
+		 * 页面离开时的轻量清理:只停止扫描,不断开BLE连接
+		 * 保持蓝牙连接状态,下次进入相同设备页面可复用
+		 */
+		cleanupOnLeave() {
+			this.bleStore.stopScan()
+		},
+
 		// ========== BLE错误码转用户友好提示 ==========
 		_bleFriendlyMsg(e) {
 			const code = e && (e.code || e.message || '')

+ 15 - 35
code/ajyApp/pages/device/userManage/userManage.nvue

@@ -29,9 +29,9 @@
 									<text class="userAge" v-if="item.age">{{item.age}}岁</text>
 								</view>
 								<view class="bodyRow">
-									<text class="bodyTxt">身长:{{item.bodyHeight || item.shoulderHeight || '--'}}cm</text>
+									<text class="bodyTxt">肩高:{{item.shoulderHeight || '--'}}cm</text>
 									<text class="bodyTxt">肩宽:{{item.shoulderWidth || '--'}}cm</text>
-									<text class="bodyTxt">脊柱:{{item.spineLength || '--'}}cm</text>
+									<text class="bodyTxt">体重:{{item.weight || '--'}}kg</text>
 								</view>
 							</view>
 						</view>
@@ -72,7 +72,6 @@
 <script>
 import customPopup from '@/components/customPopup/customPopup.nvue'
 import ayToast from '@/components/ay-toast/ay-toast.nvue'
-import { getGroupMembers } from '@/utils/api/device'
 
 export default {
 	components: {
@@ -99,45 +98,21 @@ export default {
 		goBack() {
 			uni.navigateBack()
 		},
-		/** 从后端加载当前设备用户列表 */
-		async loadUsers() {
-			const currentDevice = uni.getStorageSync('current_device') || {}
-			let list = []
-			if (currentDevice.groupId) {
-				try {
-					const data = await getGroupMembers(currentDevice.groupId)
-					list = (data || []).map(this.normalizeMember)
-					uni.setStorageSync('user_manage_list', list)
-				} catch (e) {
-					console.error('加载群组成员失败,使用本地缓存', e)
-					list = uni.getStorageSync('user_manage_list') || []
-				}
-			} else {
-				const currentUser = uni.getStorageSync('current_manage_user') || currentDevice.profile
-				list = currentUser ? [this.normalizeMember(currentUser)] : []
-				uni.setStorageSync('user_manage_list', list)
-			}
+		/** 从本地存储加载用户列表 */
+		loadUsers() {
+			const list = uni.getStorageSync('user_manage_list') || []
 			this.userList = list
-			this.currentUserId = String(uni.getStorageSync('current_manage_user_id') || '')
+			this.currentUserId = uni.getStorageSync('current_manage_user_id') || ''
 			// 如果没有当前用户且列表不为空,默认选中第一个
 			if (!this.currentUserId && list.length > 0) {
-				this.currentUserId = String(list[0].id)
+				this.currentUserId = list[0].id
 				uni.setStorageSync('current_manage_user_id', this.currentUserId)
-				uni.setStorageSync('current_manage_user', list[0])
-			}
-		},
-		normalizeMember(item) {
-			return {
-				...item,
-				id: String(item.profileId || item.id),
-				bodyHeight: item.bodyHeight || item.shoulderHeight || '',
-				profileComplete: !!item.profileComplete
 			}
 		},
 		/** 切换用户 */
 		switchUser(item) {
-			this.currentUserId = String(item.id)
-			uni.setStorageSync('current_manage_user_id', this.currentUserId)
+			this.currentUserId = item.id
+			uni.setStorageSync('current_manage_user_id', item.id)
 			uni.setStorageSync('current_manage_user', item)
 			this.$refs.ayToast.success('已切换至用户:' + item.name)
 			setTimeout(() => {
@@ -162,7 +137,12 @@ export default {
 		},
 		/** 确认删除 */
 		confirmDelete(item) {
-			this.$refs.ayToast.error('暂不支持在App端删除群组成员')
+			if (this.userList.length <= 1) {
+				this.$refs.ayToast.error('至少保留一个用户')
+				return
+			}
+			this.deleteTarget = item
+			this.showDeletePopup = true
 		},
 		/** 录入指纹 */
 		enrollFingerprint(item) {