|
|
@@ -101,6 +101,7 @@ import TabBar from '@/components/tab-bar.vue'
|
|
|
import { fetchUserInfo as fetchUserInfoApi } from '@/api/user'
|
|
|
import request from '@/api/request'
|
|
|
import { handleQrScanResult } from '@/utils/qr'
|
|
|
+import { queryBoundPatientsActivities } from '@/api/userActivity'
|
|
|
|
|
|
const user = ref<{ avatar?: string; nickname?: string; title?: string }>({})
|
|
|
|
|
|
@@ -126,23 +127,11 @@ const todayReminders = ref({
|
|
|
abnormalCount: 0
|
|
|
})
|
|
|
|
|
|
-const patientActivities = ref([
|
|
|
- {
|
|
|
- desc: '患者张三血糖数据异常,请关注',
|
|
|
- time: '10分钟前',
|
|
|
- patientAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
|
|
|
- },
|
|
|
- {
|
|
|
- desc: '患者李四完成了今日复诊',
|
|
|
- time: '1小时前',
|
|
|
- patientAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
|
|
|
- },
|
|
|
- {
|
|
|
- desc: '患者王五上传了血压数据',
|
|
|
- time: '2小时前',
|
|
|
- patientAvatar: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
|
|
|
- }
|
|
|
-])
|
|
|
+const patientActivities = ref<Array<{
|
|
|
+ desc: string
|
|
|
+ time: string
|
|
|
+ patientAvatar: string
|
|
|
+}>>([])
|
|
|
|
|
|
const loadUser = () => {
|
|
|
try {
|
|
|
@@ -224,21 +213,94 @@ const fetchTodayReminders = async () => {
|
|
|
const fetchPatientActivities = async () => {
|
|
|
try {
|
|
|
const token = uni.getStorageSync('token')
|
|
|
- if (!token) return
|
|
|
- const response = await request({
|
|
|
- url: 'https://wx.baiyun.work/doctor/patient_activities',
|
|
|
- method: 'GET',
|
|
|
+ if (!token) {
|
|
|
+ console.log('No token found, skipping fetchPatientActivities')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('Fetching patient activities...')
|
|
|
|
|
|
+ // 调用真实接口获取患者动态
|
|
|
+ const response = await queryBoundPatientsActivities({
|
|
|
+ pageNum: 1,
|
|
|
+ pageSize: 10
|
|
|
})
|
|
|
+
|
|
|
+ console.log('Patient activities response:', response)
|
|
|
+
|
|
|
const resp = response.data as any
|
|
|
if (resp && resp.code === 200 && resp.data) {
|
|
|
- patientActivities.value = resp.data
|
|
|
+ console.log('Patient activities data:', resp.data)
|
|
|
+
|
|
|
+ // 转换数据格式,异步获取头像
|
|
|
+ const activitiesPromises = resp.data.records.map(async (activity: any) => ({
|
|
|
+ desc: formatActivityDescription(activity),
|
|
|
+ time: formatTime(activity.createTime),
|
|
|
+ patientAvatar: await getPatientAvatar(activity.userId)
|
|
|
+ }))
|
|
|
+
|
|
|
+ // 等待所有头像获取完成
|
|
|
+ const activities = await Promise.all(activitiesPromises)
|
|
|
+ console.log('Converted activities:', activities)
|
|
|
+ patientActivities.value = activities
|
|
|
+ } else {
|
|
|
+ console.log('No patient activities data or invalid response')
|
|
|
+ patientActivities.value = []
|
|
|
}
|
|
|
} catch (err) {
|
|
|
console.error('Fetch patient activities error:', err)
|
|
|
+ // 如果接口调用失败,显示空数据
|
|
|
+ patientActivities.value = []
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 格式化时间显示
|
|
|
+const formatTime = (createTime: string) => {
|
|
|
+ try {
|
|
|
+ const now = new Date()
|
|
|
+ const create = new Date(createTime)
|
|
|
+ const diff = now.getTime() - create.getTime()
|
|
|
+
|
|
|
+ const minutes = Math.floor(diff / (1000 * 60))
|
|
|
+ const hours = Math.floor(diff / (1000 * 60 * 60))
|
|
|
+ const days = Math.floor(diff / (1000 * 60 * 60 * 24))
|
|
|
+
|
|
|
+ if (minutes < 1) return '刚刚'
|
|
|
+ if (minutes < 60) return `${minutes}分钟前`
|
|
|
+ if (hours < 24) return `${hours}小时前`
|
|
|
+ if (days < 7) return `${days}天前`
|
|
|
+
|
|
|
+ return create.toLocaleDateString('zh-CN')
|
|
|
+ } catch (e) {
|
|
|
+ return createTime
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 获取患者头像
|
|
|
+const getPatientAvatar = async (userId: number): Promise<string> => {
|
|
|
+ try {
|
|
|
+ const token = uni.getStorageSync('token')
|
|
|
+ if (!token) return defaultAvatarUrl
|
|
|
+
|
|
|
+ // 尝试下载用户头像
|
|
|
+ const downloadRes = await uni.downloadFile({
|
|
|
+ url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${token}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ if (downloadRes.statusCode === 200 && downloadRes.tempFilePath) {
|
|
|
+ return downloadRes.tempFilePath
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.error('Download patient avatar error:', e)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果获取失败,使用默认头像
|
|
|
+ return defaultAvatarUrl
|
|
|
+}
|
|
|
+
|
|
|
// 如果在微信小程序端且未登录,自动跳转到登录页
|
|
|
onShow(() => {
|
|
|
const token = uni.getStorageSync('token')
|
|
|
@@ -269,6 +331,56 @@ function onItemClick(type: string) {
|
|
|
function onQrClick() {
|
|
|
uni.navigateTo({ url: '/pages/public/profile/qr/index' })
|
|
|
}
|
|
|
+
|
|
|
+// 格式化活动描述
|
|
|
+const formatActivityDescription = (activity: any) => {
|
|
|
+ // 如果已经有友好的描述,直接返回
|
|
|
+ if (activity.friendlyDescription) {
|
|
|
+ return activity.friendlyDescription
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据活动类型生成友好的描述
|
|
|
+ switch (activity.activityType) {
|
|
|
+ case 'BLOOD_GLUCOSE_UPLOAD':
|
|
|
+ return '上传了血糖数据'
|
|
|
+ case 'BLOOD_GLUCOSE_UPDATE':
|
|
|
+ return '更新了血糖数据'
|
|
|
+ case 'BLOOD_PRESSURE_UPLOAD':
|
|
|
+ return '上传了血压数据'
|
|
|
+ case 'HEART_RATE_UPLOAD':
|
|
|
+ return '上传了心率数据'
|
|
|
+ case 'PHYSICAL_DATA_UPLOAD':
|
|
|
+ return '上传了体格数据'
|
|
|
+ case 'HEALTH_RECORD_CREATE':
|
|
|
+ return '创建了健康档案'
|
|
|
+ case 'HEALTH_RECORD_UPDATE':
|
|
|
+ return '更新了健康档案'
|
|
|
+ case 'MEDICATION_CREATE':
|
|
|
+ return '添加了用药记录'
|
|
|
+ case 'MEDICATION_UPDATE':
|
|
|
+ return '更新了用药记录'
|
|
|
+ case 'FOLLOW_UP_CREATE':
|
|
|
+ return '提交了复诊申请'
|
|
|
+ case 'FOLLOW_UP_UPDATE':
|
|
|
+ return '更新了复诊信息'
|
|
|
+ case 'FOLLOW_UP_CONFIRM':
|
|
|
+ return '医生已确认复诊'
|
|
|
+ case 'FOLLOW_UP_CANCEL':
|
|
|
+ return '医生已取消复诊'
|
|
|
+ case 'FOLLOW_UP_COMPLETE':
|
|
|
+ return '医生已完成复诊'
|
|
|
+ case 'USER_BINDING_CREATE':
|
|
|
+ return '绑定了新患者'
|
|
|
+ case 'USER_BINDING_DELETE':
|
|
|
+ return '解除了患者绑定'
|
|
|
+ default:
|
|
|
+ // 如果没有匹配的类型,尝试使用 activityDescription 或返回默认值
|
|
|
+ return activity.activityDescription && !activity.activityDescription.includes('Controller')
|
|
|
+ ? activity.activityDescription
|
|
|
+ : '执行了操作'
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<style>
|