Browse Source

公共设备用户信息展示对接

liyuliangjiazai 4 months ago
parent
commit
565e5b57f2

+ 31 - 2
code/ajyApp/pages/device/bodyParams/bodyParams.nvue

@@ -112,6 +112,7 @@
 <script>
 import ayToast from '@/components/ay-toast/ay-toast.nvue'
 import { addGroupMember, updateGroupMember, getGroupMembers } from '@/utils/api/group.js'
+import { getProfile, updateProfile } from '@/utils/api/user.js'
 
 export default {
 	components: {
@@ -121,6 +122,7 @@ export default {
 		return {
 			statusBarHeight: 44,
 			mode: 'add', // add / edit
+			source: '', // '' = group member, 'profile' = current user profile
 			groupId: '',
 			profileId: '',
 			form: {
@@ -140,9 +142,13 @@ export default {
 		const sysInfo = uni.getSystemInfoSync()
 		this.statusBarHeight = sysInfo.statusBarHeight || 44
 		this.mode = options.mode || 'add'
+		this.source = options.source || ''
 		this.groupId = options.groupId || ''
 		this.profileId = options.profileId || ''
-		if (this.mode === 'edit' && this.profileId) {
+		if (this.source === 'profile') {
+			// 公共设备:加载当前账号个人资料
+			this.loadProfileData()
+		} else if (this.mode === 'edit' && this.profileId) {
 			this.loadUserData()
 		}
 	},
@@ -150,6 +156,25 @@ export default {
 		goBack() {
 			uni.navigateBack()
 		},
+		/** 加载个人资料数据(公共设备模式) */
+		async loadProfileData() {
+			try {
+				const profile = await getProfile()
+				if (profile) {
+					this.form.name = profile.name || ''
+					this.form.gender = profile.gender || 1
+					this.form.age = profile.age ? String(profile.age) : ''
+					this.form.phone = profile.phone || ''
+					this.form.shoulderWidth = profile.shoulderWidth ? String(profile.shoulderWidth) : ''
+					this.form.height = profile.height ? String(profile.height) : ''
+					this.form.weight = profile.weight ? String(profile.weight) : ''
+					this.form.bodyHeight = profile.bodyHeight ? String(profile.bodyHeight) : ''
+					this.form.spineLength = profile.spineLength ? String(profile.spineLength) : ''
+				}
+			} catch (e) {
+				console.error('加载个人资料失败:', e)
+			}
+		},
 		/** 加载编辑数据 - 从后端获取群组成员列表中查找当前成员 */
 		async loadUserData() {
 			try {
@@ -192,7 +217,11 @@ export default {
 			if (this.form.spineLength) params.spineLength = Number(this.form.spineLength)
 
 			try {
-				if (this.mode === 'add') {
+				if (this.source === 'profile') {
+					// 公共设备:调用修改个人资料接口
+					await updateProfile(params)
+					this.$refs.ayToast.success('保存成功')
+				} else if (this.mode === 'add') {
 					await addGroupMember(this.groupId, params)
 					this.$refs.ayToast.success('添加成功')
 				} else {

+ 39 - 13
code/ajyApp/pages/device/deviceInfo/deviceInfo.nvue

@@ -326,6 +326,7 @@ import acupointMixin from './mixins/acupoint-mixin.js'
 import planMixin from './mixins/plan-mixin.js'
 import { useBleStore } from '@/stores/ble'
 import { CHAIR_ANGLE } from '@/utils/ble/constants.js'
+import { getProfile } from '@/utils/api/user.js'
 
 export default {
 	components: {
@@ -339,7 +340,7 @@ export default {
 			statusBarHeight: 44,
 			deviceId: '',
 			deviceName: '',
-			deviceType:'',
+			deviceType:'',//1=家庭设备,2=公共设备'
 			id:'',
 			rssi: '',
 			advertisData: '',
@@ -409,23 +410,48 @@ export default {
 			uni.navigateBack()
 		},
 		/** 加载当前用户信息 */
-		loadCurrentUser() {
-			// uni.removeStorageSync('current_manage_user')
-			const user = uni.getStorageSync('current_manage_user')
-			console.log("user",user)
-			if (user && user.name) {
-				this.currentUserName = user.name
-				this.profileId = user.id || ''
+		async loadCurrentUser() {
+			if (this.deviceType === '2') {
+				// 公共设备:通过接口获取当前账号个人资料
+				try {
+					const profile = await getProfile()
+					if (profile && profile.name) {
+						this.currentUserName = profile.name
+						this.profileId = profile.profileId || profile.id || ''
+					} else {
+						this.currentUserName = ''
+						this.profileId = ''
+					}
+				} catch (e) {
+					console.error('获取个人资料失败:', e)
+					this.currentUserName = ''
+					this.profileId = ''
+				}
 			} else {
-				this.currentUserName = ''
-				this.profileId = ''
+				// 家庭设备:从本地缓存读取群组当前用户
+				const user = uni.getStorageSync('current_manage_user')
+				if (user && user.name) {
+					this.currentUserName = user.name
+					this.profileId = user.id || ''
+				} else {
+					this.currentUserName = ''
+					this.profileId = ''
+				}
 			}
 		},
 		/** 跳转用户管理页 */
 		goUserManage() {
-			uni.navigateTo({
-				url: '/pages/device/userManage/userManage?groupId=' + encodeURIComponent(this.groupId || '')
-			})
+			if (this.deviceType === '2') {
+				// 公共设备:跳转体形参数页编辑个人资料
+				uni.navigateTo({
+					url: '/pages/device/bodyParams/bodyParams?mode=edit&source=profile'
+				})
+			} else {
+				// 家庭设备:跳转用户管理页
+				uni.navigateTo({
+					url: '/pages/device/userManage/userManage?groupId=' + encodeURIComponent(this.groupId || '')
+				})
+			}
 		},
 		// 座椅角度控制 - 来自 l-sliderRange 组件
 		onSliderAngleChange(val) {