diff --git a/src/api/base/profile.ts b/src/api/base/profile.ts index 6594eeda..fd5fc9e4 100644 --- a/src/api/base/profile.ts +++ b/src/api/base/profile.ts @@ -1,3 +1,4 @@ +import { ContentTypeEnum } from '@/enums/httpEnum' import { defHttp } from '@/utils/http/axios' export interface ProfileDept { @@ -86,7 +87,15 @@ export function updateUserPwdApi(oldPassword: string, newPassword: string) { // 用户头像上传 export function uploadAvatarApi(data) { - return defHttp.put({ url: Api.uploadAvatarApi, data: { file: data } }) + return defHttp.put({ + url: Api.uploadAvatarApi, + headers: { + 'Content-type': ContentTypeEnum.FORM_DATA, + // @ts-ignore + ignoreCancelToken: true + }, + data + }) } // 社交绑定,使用 code 授权码 diff --git a/src/components/Cropper/src/CopperModal.vue b/src/components/Cropper/src/CopperModal.vue index fc6f396d..7859de68 100644 --- a/src/components/Cropper/src/CopperModal.vue +++ b/src/components/Cropper/src/CopperModal.vue @@ -158,16 +158,18 @@ function handlerToolbar(event: string, arg?: number) { async function handleOk() { const uploadApi = props.uploadApi - if (uploadApi && isFunction(uploadApi)) { + try { + setModalProps({ confirmLoading: true }) const blob = dataURLtoBlob(previewSource.value) - try { - setModalProps({ confirmLoading: true }) + if (uploadApi && isFunction(uploadApi)) { const result = await uploadApi({ name: 'file', file: blob, filename }) emit('uploadSuccess', { source: previewSource.value, data: result.url }) - closeModal() - } finally { - setModalProps({ confirmLoading: false }) + } else { + emit('uploadSuccess', { source: previewSource.value, data: blob, filename: filename }) } + closeModal() + } finally { + setModalProps({ confirmLoading: false }) } } diff --git a/src/views/base/profile/BaseSetting.vue b/src/views/base/profile/BaseSetting.vue index 6c36b05d..5c11c7c9 100644 --- a/src/views/base/profile/BaseSetting.vue +++ b/src/views/base/profile/BaseSetting.vue @@ -9,7 +9,6 @@
头像
{ return avatar || headerImg }) -async function updateAvatar({ src, data }) { - await uploadAvatarApi({ avatarFile: data }) +async function updateAvatar({ data }) { + const res = await uploadAvatarApi({ avatarFile: data }) const userinfo = userStore.getUserInfo - userinfo.user.avatar = src + userinfo.user.avatar = res userStore.setUserInfo(userinfo) }