fix:前端上传头像名称取值错误以及用户保存个人信息时还使用的是旧的头像数据

This commit is contained in:
YunaiV
2025-09-21 11:06:28 +08:00
parent f6e9b4c4cf
commit 2c83d1e712
2 changed files with 5 additions and 20 deletions

View File

@@ -1,5 +1,4 @@
import * as FileApi from '@/api/infra/file' import * as FileApi from '@/api/infra/file'
// import CryptoJS from 'crypto-js'
import { UploadRawFile, UploadRequestOptions } from 'element-plus/es/components/upload/src/upload' import { UploadRawFile, UploadRequestOptions } from 'element-plus/es/components/upload/src/upload'
import axios from 'axios' import axios from 'axios'
@@ -20,7 +19,7 @@ export const useUpload = (directory?: string) => {
// 模式一:前端上传 // 模式一:前端上传
if (isClientUpload) { if (isClientUpload) {
// 1.1 生成文件名称 // 1.1 生成文件名称
const fileName = options.filename const fileName = options.file.name || options.filename
// 1.2 获取文件预签名地址 // 1.2 获取文件预签名地址
const presignedInfo = await FileApi.getFilePresignedUrl(fileName, directory) const presignedInfo = await FileApi.getFilePresignedUrl(fileName, directory)
// 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传Minio 不支持) // 1.3 上传文件(不能使用 ElUpload 的 ajaxUpload 方法的原因:其使用的是 FormData 上传Minio 不支持)
@@ -32,7 +31,7 @@ export const useUpload = (directory?: string) => {
}) })
.then(() => { .then(() => {
// 1.4. 记录文件信息到后端(异步) // 1.4. 记录文件信息到后端(异步)
createFile(presignedInfo, options.file,fileName) createFile(presignedInfo, options.file, fileName)
// 通知成功,数据格式保持与后端上传的返回结果一致 // 通知成功,数据格式保持与后端上传的返回结果一致
return { data: presignedInfo.url } return { data: presignedInfo.url }
}) })
@@ -80,22 +79,6 @@ function createFile(vo: FileApi.FilePresignedUrlRespVO, file: UploadRawFile, fil
return fileVo return fileVo
} }
/**
* 生成文件名称使用算法SHA256
* @param file 要上传的文件
*/
async function generateFileName(file: UploadRawFile) {
// // 读取文件内容
// const data = await file.arrayBuffer()
// const wordArray = CryptoJS.lib.WordArray.create(data)
// // 计算SHA256
// const sha256 = CryptoJS.SHA256(wordArray).toString()
// // 拼接后缀
// const ext = file.name.substring(file.name.lastIndexOf('.'))
// return `${sha256}${ext}`
return file.name
}
/** /**
* 上传类型 * 上传类型
*/ */

View File

@@ -102,17 +102,19 @@ const submit = () => {
await updateUserProfile(data) await updateUserProfile(data)
message.success(t('common.updateSuccess')) message.success(t('common.updateSuccess'))
const profile = await init() const profile = await init()
userStore.setUserNicknameAction(profile.nickname) await userStore.setUserNicknameAction(profile.nickname)
// 发送成功事件 // 发送成功事件
emit('success') emit('success')
} }
}) })
} }
const init = async () => { const init = async () => {
const res = await getUserProfile() const res = await getUserProfile()
unref(formRef)?.setValues(res) unref(formRef)?.setValues(res)
return res return res
} }
onMounted(async () => { onMounted(async () => {
await init() await init()
}) })