|
|
@@ -102,6 +102,7 @@ import { fetchUserInfo as fetchUserInfoApi } from '@/api/user'
|
|
|
import request from '@/api/request'
|
|
|
import { handleQrScanResult } from '@/utils/qr'
|
|
|
import { queryBoundPatientsActivities } from '@/api/userActivity'
|
|
|
+import { avatarCache } from '@/utils/avatarCache'
|
|
|
|
|
|
const user = ref<{ avatar?: string; nickname?: string; title?: string }>({})
|
|
|
|
|
|
@@ -165,18 +166,25 @@ const fetchUserInfo = async () => {
|
|
|
if (!resp.data.avatar || !resp.data.avatar.startsWith('http')) {
|
|
|
const userId = resp.data.id || resp.data.userId
|
|
|
if (userId) {
|
|
|
- try {
|
|
|
- const downloadRes = await uni.downloadFile({
|
|
|
- url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
|
- header: {
|
|
|
- Authorization: `Bearer ${token}`
|
|
|
+ // 检查是否有缓存的头像
|
|
|
+ if (avatarCache.has(userId)) {
|
|
|
+ resp.data.avatar = avatarCache.get(userId)
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ const downloadRes = await uni.downloadFile({
|
|
|
+ url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
|
+ header: {
|
|
|
+ Authorization: `Bearer ${token}`
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (downloadRes.statusCode === 200 && downloadRes.tempFilePath) {
|
|
|
+ resp.data.avatar = downloadRes.tempFilePath
|
|
|
+ // 缓存头像路径
|
|
|
+ avatarCache.set(userId, downloadRes.tempFilePath)
|
|
|
}
|
|
|
- })
|
|
|
- if (downloadRes.statusCode === 200 && downloadRes.tempFilePath) {
|
|
|
- resp.data.avatar = downloadRes.tempFilePath
|
|
|
+ } catch (e) {
|
|
|
+ console.error('Download avatar error:', e)
|
|
|
}
|
|
|
- } catch (e) {
|
|
|
- console.error('Download avatar error:', e)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -277,11 +285,16 @@ const formatTime = (createTime: string) => {
|
|
|
}
|
|
|
|
|
|
// 获取患者头像
|
|
|
-const getPatientAvatar = async (userId: number): Promise<string> => {
|
|
|
+const getPatientAvatar = async (userId: string): Promise<string> => {
|
|
|
try {
|
|
|
const token = uni.getStorageSync('token')
|
|
|
if (!token) return defaultAvatarUrl
|
|
|
|
|
|
+ // 检查是否有缓存的头像
|
|
|
+ if (avatarCache.has(userId)) {
|
|
|
+ return avatarCache.get(userId)!
|
|
|
+ }
|
|
|
+
|
|
|
// 尝试下载用户头像
|
|
|
const downloadRes = await uni.downloadFile({
|
|
|
url: `https://wx.baiyun.work/user/avatar/${userId}`,
|
|
|
@@ -291,6 +304,8 @@ const getPatientAvatar = async (userId: number): Promise<string> => {
|
|
|
})
|
|
|
|
|
|
if (downloadRes.statusCode === 200 && downloadRes.tempFilePath) {
|
|
|
+ // 缓存头像路径
|
|
|
+ avatarCache.set(userId, downloadRes.tempFilePath)
|
|
|
return downloadRes.tempFilePath
|
|
|
}
|
|
|
} catch (e) {
|