Pārlūkot izejas kodu

用户组接口对接

liyuliangjiazai 2 mēneši atpakaļ
vecāks
revīzija
4d849abd73

+ 85 - 88
code/ajyApp/pages/device/bodyParams/bodyParams.nvue

@@ -43,12 +43,11 @@
 					</view>
 				</view>
 
-				<!-- 肩高 -->
+				<!-- 手机号 -->
 				<view class="formItem">
-					<text class="formLabel">肩高(地面到肩膀的高度)</text>
+					<text class="formLabel">手机号</text>
 					<view class="inputWrap">
-						<input class="formInput" v-model="form.shoulderHeight" type="digit" placeholder="例如:135" placeholder-class="pholder" />
-						<text class="unitTxt">cm</text>
+						<input class="formInput" v-model="form.phone" type="number" placeholder="请输入手机号" placeholder-class="pholder" maxlength="11" />
 					</view>
 				</view>
 
@@ -61,6 +60,15 @@
 					</view>
 				</view>
 
+				<!-- 身高 -->
+				<view class="formItem">
+					<text class="formLabel">身高</text>
+					<view class="inputWrap">
+						<input class="formInput" v-model="form.height" type="digit" placeholder="例如:175" placeholder-class="pholder" />
+						<text class="unitTxt">cm</text>
+					</view>
+				</view>
+
 				<!-- 体重 -->
 				<view class="formItem">
 					<text class="formLabel">体重</text>
@@ -70,6 +78,24 @@
 					</view>
 				</view>
 
+				<!-- 身长/坐高 -->
+				<view class="formItem">
+					<text class="formLabel">坐高(坐姿时头顶到坐面的高度)</text>
+					<view class="inputWrap">
+						<input class="formInput" v-model="form.bodyHeight" type="digit" placeholder="例如:85" placeholder-class="pholder" />
+						<text class="unitTxt">cm</text>
+					</view>
+				</view>
+
+				<!-- 脊柱长度 -->
+				<view class="formItem">
+					<text class="formLabel">C7-S4 脊柱长度</text>
+					<view class="inputWrap">
+						<input class="formInput" v-model="form.spineLength" type="digit" placeholder="例如:48" placeholder-class="pholder" />
+						<text class="unitTxt">cm</text>
+					</view>
+				</view>
+
 				<!-- 保存按钮 -->
 				<view class="saveBtn" @click="onSave">
 					<text class="saveTxt">保存</text>
@@ -85,6 +111,7 @@
 
 <script>
 import ayToast from '@/components/ay-toast/ay-toast.nvue'
+import { addGroupMember, updateGroupMember, getGroupMembers } from '@/utils/api/group.js'
 
 export default {
 	components: {
@@ -94,14 +121,18 @@ export default {
 		return {
 			statusBarHeight: 44,
 			mode: 'add', // add / edit
-			userId: '',
+			groupId: '',
+			profileId: '',
 			form: {
 				name: '',
 				gender: 1,
 				age: '',
-				shoulderHeight: '',
+				phone: '',
 				shoulderWidth: '',
-				weight: ''
+				height: '',
+				weight: '',
+				bodyHeight: '',
+				spineLength: ''
 			}
 		}
 	},
@@ -109,8 +140,9 @@ export default {
 		const sysInfo = uni.getSystemInfoSync()
 		this.statusBarHeight = sysInfo.statusBarHeight || 44
 		this.mode = options.mode || 'add'
-		this.userId = options.userId || ''
-		if (this.mode === 'edit' && this.userId) {
+		this.groupId = options.groupId || ''
+		this.profileId = options.profileId || ''
+		if (this.mode === 'edit' && this.profileId) {
 			this.loadUserData()
 		}
 	},
@@ -118,96 +150,61 @@ export default {
 		goBack() {
 			uni.navigateBack()
 		},
-		/** 加载编辑数据 */
-		loadUserData() {
-			const list = uni.getStorageSync('user_manage_list') || []
-			const user = list.find(u => u.id === this.userId)
-			if (user) {
-				this.form.name = user.name || ''
-				this.form.gender = user.gender || 1
-				this.form.age = user.age ? String(user.age) : ''
-				this.form.shoulderHeight = user.shoulderHeight ? String(user.shoulderHeight) : ''
-				this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
-				this.form.weight = user.weight ? String(user.weight) : ''
+		/** 加载编辑数据 - 从后端获取群组成员列表中查找当前成员 */
+		async loadUserData() {
+			try {
+				const list = await getGroupMembers(this.groupId)
+				const user = (list || []).find(u => String(u.profileId) === String(this.profileId))
+				if (user) {
+					this.form.name = user.name || ''
+					this.form.gender = user.gender || 1
+					this.form.age = user.age ? String(user.age) : ''
+					this.form.phone = user.phone || ''
+					this.form.shoulderWidth = user.shoulderWidth ? String(user.shoulderWidth) : ''
+					this.form.height = user.height ? String(user.height) : ''
+					this.form.weight = user.weight ? String(user.weight) : ''
+					this.form.bodyHeight = user.bodyHeight ? String(user.bodyHeight) : ''
+					this.form.spineLength = user.spineLength ? String(user.spineLength) : ''
+				}
+			} catch (e) {
+				console.error('加载用户数据失败:', e)
 			}
 		},
 		/** 校验并保存 */
-		onSave() {
-			// 校验
+		async onSave() {
+			// 校验姓名
 			if (!this.form.name.trim()) {
 				this.$refs.ayToast.error('请输入姓名')
 				return
 			}
-			const height = Number(this.form.shoulderHeight)
-			if (!height || height < 50 || height > 250) {
-				this.$refs.ayToast.error('肩高范围为50-250cm')
-				return
-			}
-			const width = Number(this.form.shoulderWidth)
-			if (!width || width < 20 || width > 80) {
-				this.$refs.ayToast.error('肩宽范围为20-80cm')
-				return
-			}
-			const weight = Number(this.form.weight)
-			if (!weight || weight < 10 || weight > 300) {
-				this.$refs.ayToast.error('体重范围为10-300kg')
-				return
-			}
 
-			let list = uni.getStorageSync('user_manage_list') || []
+			// 构建请求参数
+			const params = {
+				name: this.form.name.trim(),
+				gender: this.form.gender
+			}
+			if (this.form.age) params.age = Number(this.form.age)
+			if (this.form.phone) params.phone = this.form.phone
+			if (this.form.shoulderWidth) params.shoulderWidth = Number(this.form.shoulderWidth)
+			if (this.form.height) params.height = Number(this.form.height)
+			if (this.form.weight) params.weight = Number(this.form.weight)
+			if (this.form.bodyHeight) params.bodyHeight = Number(this.form.bodyHeight)
+			if (this.form.spineLength) params.spineLength = Number(this.form.spineLength)
 
-			if (this.mode === 'add') {
-				// 再次检查是否超过10个
-				if (list.length >= 10) {
-					this.$refs.ayToast.error('最多可添加10个用户')
-					return
-				}
-				const newUser = {
-					id: 'user_' + Date.now() + '_' + Math.random().toString(36).substr(2, 6),
-					name: this.form.name.trim(),
-					gender: this.form.gender,
-					age: Number(this.form.age) || 0,
-					shoulderHeight: height,
-					shoulderWidth: width,
-					weight: weight,
-					createTime: Date.now()
-				}
-				list.push(newUser)
-				uni.setStorageSync('user_manage_list', list)
-				// 如果是第一个用户,自动设为当前用户
-				if (list.length === 1) {
-					uni.setStorageSync('current_manage_user_id', newUser.id)
-					uni.setStorageSync('current_manage_user', newUser)
+			try {
+				if (this.mode === 'add') {
+					await addGroupMember(this.groupId, params)
+					this.$refs.ayToast.success('添加成功')
+				} else {
+					await updateGroupMember(this.groupId, this.profileId, params)
+					this.$refs.ayToast.success('保存成功')
 				}
-				this.$refs.ayToast.success('添加成功')
-			} else {
-				// 编辑模式
-				const index = list.findIndex(u => u.id === this.userId)
-				if (index === -1) {
-					this.$refs.ayToast.error('用户信息已过期,请刷新')
-					return
-				}
-				list[index] = {
-					...list[index],
-					name: this.form.name.trim(),
-					gender: this.form.gender,
-					age: Number(this.form.age) || 0,
-					shoulderHeight: height,
-					shoulderWidth: width,
-					weight: weight
-				}
-				uni.setStorageSync('user_manage_list', list)
-				// 如果编辑的是当前用户,更新当前用户缓存
-				const curId = uni.getStorageSync('current_manage_user_id')
-				if (curId === this.userId) {
-					uni.setStorageSync('current_manage_user', list[index])
-				}
-				this.$refs.ayToast.success('保存成功')
+				setTimeout(() => {
+					uni.navigateBack()
+				}, 800)
+			} catch (e) {
+				console.error('保存失败:', e)
 			}
-
-			setTimeout(() => {
-				uni.navigateBack()
-			}, 800)
 		}
 	}
 }

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

@@ -345,7 +345,9 @@ export default {
 			advertisData: '',
 			isShowDrawer2: false,
 			modelist: ['无艾灸模式', '专业模式', '自定义模式', '延年圣手模式'],
-			currentUserName: ''
+			currentUserName: '',
+			groupId: '',
+			profileId: ''
 		}
 	},
 	computed: {
@@ -377,6 +379,8 @@ export default {
 		this.id= decodeURIComponent(options.id || '')
 		this.deviceType=decodeURIComponent(options.deviceType || '')
 		this.advertisData = decodeURIComponent(options.advertisData || '')
+		this.groupId = decodeURIComponent(options.groupId || '')
+		this.profileId = decodeURIComponent(options.profileId || '')
 
 		// TODO: 后续接口确定后实现 - 下载穴位列表
 		// TODO: 后续接口确定后实现 - 下载专业模式推荐方案
@@ -417,7 +421,7 @@ export default {
 		/** 跳转用户管理页 */
 		goUserManage() {
 			uni.navigateTo({
-				url: '/pages/device/userManage/userManage'
+				url: '/pages/device/userManage/userManage?groupId=' + encodeURIComponent(this.groupId || '')
 			})
 		},
 		// 座椅角度控制 - 来自 l-sliderRange 组件

+ 1 - 1
code/ajyApp/pages/device/list/list.nvue

@@ -80,7 +80,7 @@ export default {
 		},
 		goDeviceInfo(item) {
 			uni.navigateTo({
-				url: '/pages/device/deviceInfo/deviceInfo?name=' + encodeURIComponent(item.deviceName || item.name || '') + '&deviceId=' + encodeURIComponent(item.deviceId || '') + '&advertisData=' + encodeURIComponent(item.deviceCode || '') + '&rssi=' + encodeURIComponent(item.RSSI || '')+'&id=' + encodeURIComponent(item.id || '')+'&deviceType='+encodeURIComponent(item.deviceType || '')
+				url: '/pages/device/deviceInfo/deviceInfo?name=' + encodeURIComponent(item.deviceName || item.name || '') + '&deviceId=' + encodeURIComponent(item.deviceId || '') + '&advertisData=' + encodeURIComponent(item.deviceCode || '') + '&rssi=' + encodeURIComponent(item.RSSI || '')+'&id=' + encodeURIComponent(item.id || '')+'&deviceType='+encodeURIComponent(item.deviceType || '')+'&groupId='+encodeURIComponent(item.groupId || '')+'&profileId='+encodeURIComponent(item.profileId || '')
 			})
 		},
 		/** 如果设备已连接,实时获取RSSI并更新缓存 */

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

@@ -181,7 +181,7 @@ export default {
 				// 调用设备详情接口获取deviceType
 				let deviceType = ''
 				try {
-					const detail = await getDeviceDetail(res.id)
+					const detail = await getDeviceDetail(res.deviceId)
 					deviceType = detail.deviceType || ''
 					console.log('获取设备类型', deviceType)
 				} catch (detailErr) {
@@ -190,10 +190,10 @@ export default {
 
 				// 后端绑定成功后,保存到本地
 				deviceList.push({
-					deviceId: device.deviceId,
+					deviceId: res.deviceId,
 					name: device.name || '艾灸椅',
 					RSSI: device.RSSI,
-					id: res.id,
+					id: res.deviceId,
 					deviceType: deviceType,
 					advertisData: device.advertisData
 				})

+ 48 - 31
code/ajyApp/pages/device/userManage/userManage.nvue

@@ -15,8 +15,8 @@
 			<text class="tipTxt">最多可添加10个用户,点击卡片切换用户</text>
 			<scroll-view class="userList" scroll-y="true">
 				<view class="listInner">
-				<view class="cardWrap" :class="{'curCardWrap': item.id === currentUserId}"
-					v-for="(item, index) in userList" :key="item.id" @click="switchUser(item)">
+				<view class="cardWrap" :class="{'curCardWrap': item.profileId === currentUserId}"
+					v-for="(item, index) in userList" :key="item.profileId" @click="switchUser(item)">
 					<view class="userCard">
 						<view class="userInfo">
 							<view class="avatarWrap">
@@ -29,7 +29,7 @@
 									<text class="userAge" v-if="item.age">{{item.age}}岁</text>
 								</view>
 								<view class="bodyRow">
-									<text class="bodyTxt">肩高:{{item.shoulderHeight || '--'}}cm</text>
+									<text class="bodyTxt">身高:{{item.height || '--'}}cm</text>
 									<text class="bodyTxt">肩宽:{{item.shoulderWidth || '--'}}cm</text>
 									<text class="bodyTxt">体重:{{item.weight || '--'}}kg</text>
 								</view>
@@ -40,7 +40,7 @@
 							<text class="editBtn" @click.stop="editUser(item)">编辑</text>
 							<text class="deleteBtn" @click.stop="confirmDelete(item)">删除</text>
 						</view>
-						<view class="curTag" v-if="item.id === currentUserId">
+						<view class="curTag" v-if="item.profileId === currentUserId">
 							<text class="curTagTxt">当前</text>
 						</view>
 					</view>
@@ -72,6 +72,7 @@
 <script>
 import customPopup from '@/components/customPopup/customPopup.nvue'
 import ayToast from '@/components/ay-toast/ay-toast.nvue'
+import { getGroupMembers, deleteGroupMember } from '@/utils/api/group.js'
 
 export default {
 	components: {
@@ -81,15 +82,17 @@ export default {
 	data() {
 		return {
 			statusBarHeight: 44,
+			groupId: '',
 			userList: [],
 			currentUserId: '',
 			showDeletePopup: false,
 			deleteTarget: null
 		}
 	},
-	onLoad() {
+	onLoad(options) {
 		const sysInfo = uni.getSystemInfoSync()
 		this.statusBarHeight = sysInfo.statusBarHeight || 44
+		this.groupId = options.groupId || ''
 	},
 	onShow() {
 		this.loadUsers()
@@ -98,21 +101,30 @@ export default {
 		goBack() {
 			uni.navigateBack()
 		},
-		/** 从本地存储加载用户列表 */
-		loadUsers() {
-			const list = uni.getStorageSync('user_manage_list') || []
-			this.userList = list
-			this.currentUserId = uni.getStorageSync('current_manage_user_id') || ''
-			// 如果没有当前用户且列表不为空,默认选中第一个
-			if (!this.currentUserId && list.length > 0) {
-				this.currentUserId = list[0].id
-				uni.setStorageSync('current_manage_user_id', this.currentUserId)
+		/** 从后端加载群组成员列表 */
+		async loadUsers() {
+			if (!this.groupId) {
+				this.$refs.ayToast.error('缺少群组信息')
+				return
+			}
+			try {
+				const list = await getGroupMembers(this.groupId)
+				this.userList = list || []
+				// 读取本地缓存的当前用户
+				this.currentUserId = uni.getStorageSync('current_manage_user_id') || ''
+				// 如果没有当前用户且列表不为空,默认选中第一个
+				if (!this.currentUserId && this.userList.length > 0) {
+					this.currentUserId = this.userList[0].profileId
+					uni.setStorageSync('current_manage_user_id', this.currentUserId)
+				}
+			} catch (e) {
+				console.error('加载群组成员失败:', e)
 			}
 		},
 		/** 切换用户 */
 		switchUser(item) {
-			this.currentUserId = item.id
-			uni.setStorageSync('current_manage_user_id', item.id)
+			this.currentUserId = item.profileId
+			uni.setStorageSync('current_manage_user_id', item.profileId)
 			uni.setStorageSync('current_manage_user', item)
 			this.$refs.ayToast.success('已切换至用户:' + item.name)
 			setTimeout(() => {
@@ -126,13 +138,13 @@ export default {
 				return
 			}
 			uni.navigateTo({
-				url: '/pages/device/bodyParams/bodyParams?mode=add'
+				url: '/pages/device/bodyParams/bodyParams?mode=add&groupId=' + encodeURIComponent(this.groupId)
 			})
 		},
 		/** 编辑用户 */
 		editUser(item) {
 			uni.navigateTo({
-				url: '/pages/device/bodyParams/bodyParams?mode=edit&userId=' + item.id
+				url: '/pages/device/bodyParams/bodyParams?mode=edit&groupId=' + encodeURIComponent(this.groupId) + '&profileId=' + encodeURIComponent(item.profileId)
 			})
 		},
 		/** 确认删除 */
@@ -147,23 +159,28 @@ export default {
 		/** 录入指纹 */
 		enrollFingerprint(item) {
 			this.$refs.ayToast.loading("指纹录入中", { mask: false })
-
 		},
 		/** 执行删除 */
-		doDelete() {
+		async doDelete() {
 			if (!this.deleteTarget) return
-			const id = this.deleteTarget.id
-			this.userList = this.userList.filter(u => u.id !== id)
-			uni.setStorageSync('user_manage_list', this.userList)
-			// 如果删除的是当前用户,切换到第一个
-			if (this.currentUserId === id && this.userList.length > 0) {
-				this.currentUserId = this.userList[0].id
-				uni.setStorageSync('current_manage_user_id', this.currentUserId)
-				uni.setStorageSync('current_manage_user', this.userList[0])
+			const profileId = this.deleteTarget.profileId
+			try {
+				await deleteGroupMember(this.groupId, profileId)
+				// 删除成功,刷新列表
+				this.userList = this.userList.filter(u => u.profileId !== profileId)
+				// 如果删除的是当前用户,切换到第一个
+				if (this.currentUserId === profileId && this.userList.length > 0) {
+					this.currentUserId = this.userList[0].profileId
+					uni.setStorageSync('current_manage_user_id', this.currentUserId)
+					uni.setStorageSync('current_manage_user', this.userList[0])
+				}
+				this.showDeletePopup = false
+				this.deleteTarget = null
+				this.$refs.ayToast.success('删除成功')
+			} catch (e) {
+				this.showDeletePopup = false
+				console.error('删除成员失败:', e)
 			}
-			this.showDeletePopup = false
-			this.deleteTarget = null
-			this.$refs.ayToast.success('删除成功')
 		}
 	}
 }

+ 44 - 0
code/ajyApp/utils/api/group.js

@@ -0,0 +1,44 @@
+/**
+ * 群组成员管理 API
+ */
+import http from '@/utils/http'
+
+/**
+ * 查询群组成员列表
+ * @param {number} groupId - 家庭设备群组 ID
+ * @returns {Promise<Array>} 成员列表
+ */
+export function getGroupMembers(groupId) {
+	return http.get(`/app/group/${groupId}/members`)
+}
+
+/**
+ * 新增群组成员
+ * @param {number} groupId - 家庭设备群组 ID
+ * @param {Object} data - 成员信息(name必填,gender/age/phone/shoulderWidth/bodyHeight/spineLength/height/weight/fingerWidth1/fingerWidth15/fingerWidth3等可选)
+ * @returns {Promise<Object>} 新增成员信息
+ */
+export function addGroupMember(groupId, data) {
+	return http.post(`/app/group/${groupId}/members`, data)
+}
+
+/**
+ * 修改群组成员
+ * @param {number} groupId - 家庭设备群组 ID
+ * @param {number} profileId - 成员的用户档案 ID
+ * @param {Object} data - 成员信息
+ * @returns {Promise<Object>} 修改后的成员信息
+ */
+export function updateGroupMember(groupId, profileId, data) {
+	return http.put(`/app/group/${groupId}/members/${profileId}`, data)
+}
+
+/**
+ * 删除群组成员(软删除)
+ * @param {number} groupId - 家庭设备群组 ID
+ * @param {number} profileId - 待移除成员的用户档案 ID
+ * @returns {Promise<null>}
+ */
+export function deleteGroupMember(groupId, profileId) {
+	return http.delete(`/app/group/${groupId}/members/${profileId}`)
+}