mirror of
https://github.com/yudaocode/yudao-ui-admin-vue3.git
synced 2026-04-19 13:58:38 +00:00
fix:前端上传头像名称取值错误以及用户保存个人信息时还使用的是旧的头像数据
This commit is contained in:
@@ -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
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传类型
|
* 上传类型
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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()
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user