فهرست منبع

feat(patient-family): 优化家人健康管理页面导航逻辑

- 新增检查家属绑定家人数量的功能
- 当只有一个绑定家人时,直接跳转至该家人的健康数据页面
- 当有多个绑定家人时,跳转至家人健康列表页面
- 无绑定家人时增加提示信息
- 引入用户绑定相关API接口和类型定义
- 完善错误处理和加载状态提示
mcbaiyun 1 ماه پیش
والد
کامیت
a579b6e17f
1فایلهای تغییر یافته به همراه83 افزوده شده و 1 حذف شده
  1. 83 1
      src/pages/patient-family/index/index.vue

+ 83 - 1
src/pages/patient-family/index/index.vue

@@ -78,6 +78,7 @@ import { handleQrScanResult } from '@/utils/qr'
 import request from '@/api/request'
 import { avatarCache } from '@/utils/avatarCache'
 import { queryBoundFamiliesActivities } from '@/api/userActivity'
+import { listUserBindingsByBoundUser, type UserBindingResponse, type UserBindingPageResponse } from '@/api/userBinding'
 
 const user = ref<{ avatar?: string; nickname?: string }>({})
 
@@ -377,12 +378,93 @@ function onItemClick(type: string) {
   if (type === '家人管理') {
     uni.navigateTo({ url: '/pages/patient-family/index/my-family' })
   } else if (type === '家人健康') {
-    uni.navigateTo({ url: '/pages/patient-family/index/family-health' })
+    // 优化:检查家属绑定的家人数量,如果只有一个则直接跳转到健康数据页面
+    checkAndNavigateToHealthData()
   } else {
     uni.showToast({ title: '功能正在开发中', icon: 'none' })
   }
 }
 
+// 检查绑定的家人数量并导航到相应页面
+async function checkAndNavigateToHealthData() {
+  uni.showLoading({ title: '加载中...' })
+  
+  try {
+    const token = uni.getStorageSync('token')
+    if (!token) {
+      uni.hideLoading()
+      uni.showToast({
+        title: '未登录',
+        icon: 'none'
+      })
+      return
+    }
+    
+    // 获取当前用户ID(家属ID)
+    const userInfo = uni.getStorageSync('user_info')
+    const familyUserId = userInfo?.id
+    
+    if (!familyUserId) {
+      uni.hideLoading()
+      uni.showToast({
+        title: '获取用户信息失败',
+        icon: 'none'
+      })
+      return
+    }
+    
+    // 查询家属绑定的家人列表
+    const response = await listUserBindingsByBoundUser(
+      familyUserId, 
+      'FAMILY', 
+      {
+        pageNum: 1,
+        pageSize: 10
+      }
+    )
+    
+    uni.hideLoading()
+    
+    const resp = response.data as any
+    
+    if (resp && resp.code === 200 && resp.data) {
+      const pageResult = resp.data as UserBindingPageResponse
+      const families = pageResult.records as UserBindingResponse[]
+      
+      // 如果只有一个家人,直接跳转到健康数据页面
+      if (families.length === 1) {
+        const family = families[0]
+        uni.navigateTo({
+          url: `/pages/public/health/index?patientId=${family.patientUserId}&bindingType=FAMILY`
+        })
+      } 
+      // 如果有多个家人,跳转到家人健康列表页面
+      else if (families.length > 1) {
+        uni.navigateTo({ url: '/pages/patient-family/index/family-health' })
+      }
+      // 如果没有绑定家人,提示用户
+      else {
+        uni.showToast({
+          title: '暂无绑定的家人',
+          icon: 'none'
+        })
+      }
+    } else {
+      uni.showToast({
+        title: '获取家人信息失败',
+        icon: 'none'
+      })
+    }
+  } catch (error) {
+    uni.hideLoading()
+    console.error('获取家人信息失败:', error)
+    uni.showToast({
+      title: '获取家人信息失败',
+      icon: 'none'
+    })
+  }
+}
+
 function onQrClick() {
   uni.navigateTo({ url: '/pages/public/profile/qr/index' })
 }