修改图片鉴权后的头像和吉祥物不显示问题
This commit is contained in:
+20
-16
@@ -11,7 +11,8 @@ import {
|
||||
import {
|
||||
setToken,
|
||||
setUserInfo,
|
||||
getUserInfo
|
||||
getUserInfo,
|
||||
getToken
|
||||
} from "@/common/common";
|
||||
import {
|
||||
get_base_url
|
||||
@@ -71,7 +72,6 @@ export const queryCurrentUser = (data) => request({
|
||||
method: 'post',
|
||||
data
|
||||
}).then(res => {
|
||||
|
||||
// deptId: ""
|
||||
// deptName: null
|
||||
// loginName: "ADMIN" // todo id
|
||||
@@ -87,6 +87,7 @@ export const queryCurrentUser = (data) => request({
|
||||
})
|
||||
// console.log('预加载头像');
|
||||
const base_url = get_base_url()
|
||||
const token = getToken()
|
||||
// 预加载头像
|
||||
// #ifdef APP-PLUS
|
||||
// 更新用户信息中的头像路径
|
||||
@@ -175,22 +176,25 @@ export const queryCurrentUser = (data) => request({
|
||||
(async () => {
|
||||
try {
|
||||
const pathName = res.body.imageAddr
|
||||
const fileUrl = base_url + pathName
|
||||
if (pathName) {
|
||||
const fileUrl = base_url + pathName + '?tk=' + token
|
||||
console.log('fileUrl', fileUrl);
|
||||
// 生成保存路径
|
||||
const filename = generateUniqueFilename(pathName)
|
||||
const localFilePath = '_doc/avatar/' + filename
|
||||
|
||||
// 生成保存路径
|
||||
const filename = generateUniqueFilename(pathName)
|
||||
const localFilePath = '_doc/avatar/' + filename
|
||||
|
||||
// 检查文件是否存在
|
||||
const exists = await checkFileExists(localFilePath)
|
||||
|
||||
if (exists) {
|
||||
// console.log('头像已存在,无需下载')
|
||||
updateUserAvatar(localFilePath)
|
||||
} else {
|
||||
const savedPath = await downloadAndSaveAvatar(fileUrl, localFilePath)
|
||||
updateUserAvatar(savedPath)
|
||||
// 检查文件是否存在
|
||||
const exists = await checkFileExists(localFilePath)
|
||||
|
||||
if (exists) {
|
||||
// console.log('头像已存在,无需下载')
|
||||
updateUserAvatar(localFilePath)
|
||||
} else {
|
||||
const savedPath = await downloadAndSaveAvatar(fileUrl, localFilePath)
|
||||
updateUserAvatar(savedPath)
|
||||
}
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('头像预加载过程发生错误:', error)
|
||||
}
|
||||
|
||||
+5
-4
@@ -2,7 +2,7 @@ import request from '@/api/request'
|
||||
import {
|
||||
get_base_url
|
||||
} from '@/api/request.js'
|
||||
|
||||
import { getToken } from '@/common/common.js'
|
||||
const app_url = '/traapp'
|
||||
|
||||
|
||||
@@ -77,8 +77,9 @@ export const queryCurrentValidMascotInfo = (data) => {
|
||||
if (body.imgAddr) {
|
||||
console.log('body.imgAddrmascotNo');
|
||||
const base_url = get_base_url()
|
||||
const token = getToken()
|
||||
const pathName = body.imgAddr
|
||||
const fileUrl = base_url + pathName
|
||||
const fileUrl = base_url + pathName + '?tk=' + token
|
||||
const localFilePath = '_doc/mascot/' + body.mascotNo + '.png'
|
||||
console.log('fileUrl', fileUrl);
|
||||
// 将 Promise 回调函数声明为 async
|
||||
@@ -86,10 +87,10 @@ export const queryCurrentValidMascotInfo = (data) => {
|
||||
// 现在可以在这里使用 await 了
|
||||
const exists = await checkFileExists(localFilePath)
|
||||
if (exists) {
|
||||
console.log('已存在,无需下载')
|
||||
// console.log('已存在,无需下载吉祥物')
|
||||
resolve({...body, imgAddr:localFilePath})
|
||||
} else {
|
||||
console.log('开始下载吉祥物:', fileUrl)
|
||||
// console.log('开始下载吉祥物:', fileUrl)
|
||||
const dtask = plus.downloader.createDownload(fileUrl, {
|
||||
filename: localFilePath
|
||||
}, (d, status) => {
|
||||
|
||||
Reference in New Issue
Block a user