perf: 👌代码优化

This commit is contained in:
wanglihui 2023-09-21 09:12:41 +08:00
parent d17c1fba40
commit 99179834ba
2 changed files with 17 additions and 9 deletions

View File

@ -22,8 +22,8 @@
list-type="picture-card"
:show-file-list="false"
:headers="headers"
:before-upload="beforeAvatarUpload"
:on-success="handleAvatarSuccess"
:before-upload="beforeUploadFile"
:on-success="onFileSuccess"
>
<img v-if="formData.cover" :src="`${BU_DOU_CONFIG.APP_URL}${formData.cover}`" class="avatar" />
<el-icon v-else><Plus /></el-icon>
@ -113,13 +113,16 @@ watch(
}
}
);
//
/**
* 上传图片
*/
const headers = {
token: userStore.token
};
const actionURL = ref('');
//
const beforeAvatarUpload = async (rawFile: any) => {
const beforeUploadFile = async (rawFile: any) => {
const fileData = {
path: `/${rawFile.uid}/${rawFile.name}`,
type: 'report'
@ -133,7 +136,7 @@ const beforeAvatarUpload = async (rawFile: any) => {
}
};
//
const handleAvatarSuccess = (response: any, _uploadFile: any) => {
const onFileSuccess = (response: any, _uploadFile: any) => {
formData.value.cover = response.path;
};
//

View File

@ -22,8 +22,8 @@
list-type="picture-card"
:show-file-list="false"
:headers="headers"
:before-upload="beforeAvatarUpload"
:on-success="handleAvatarSuccess"
:before-upload="beforeUploadFile"
:on-success="onFileSuccess"
>
<img v-if="formData.icon" :src="`${BU_DOU_CONFIG.APP_URL}${formData.icon}`" class="avatar" />
<el-icon v-else><Plus /></el-icon>
@ -133,11 +133,15 @@ watch(
}
);
/**
* 上传图片
*/
const headers = {
token: userStore.token
};
const actionURL = ref('');
const beforeAvatarUpload = async (rawFile: any) => {
//
const beforeUploadFile = async (rawFile: any) => {
const fileData = {
path: `/${rawFile.uid}/${rawFile.name}`,
type: 'report'
@ -150,7 +154,8 @@ const beforeAvatarUpload = async (rawFile: any) => {
return false;
}
};
const handleAvatarSuccess = (response: any, _uploadFile: any) => {
//
const onFileSuccess = (response: any, _uploadFile: any) => {
formData.value.icon = response.path;
};