update 重构 头像上传改为先上传oss后更新用户数据
This commit is contained in:
@@ -59,7 +59,8 @@
|
||||
import 'vue-cropper/dist/index.css';
|
||||
import { UploadRawFile } from 'element-plus';
|
||||
import { VueCropper } from 'vue-cropper';
|
||||
import { uploadAvatar } from '@/api/system/user';
|
||||
import { uploadOss } from '@/api/system/oss';
|
||||
import { updateUserProfile } from '@/api/system/user';
|
||||
import modal from '@/plugins/modal';
|
||||
import { useUserStore } from '@/store/modules/user';
|
||||
|
||||
@@ -135,10 +136,11 @@ const beforeUpload = (file: UploadRawFile): any => {
|
||||
const uploadImg = async () => {
|
||||
cropper.value.getCropBlob(async (data: any) => {
|
||||
const formData = new FormData();
|
||||
formData.append('avatarfile', data, options.fileName);
|
||||
const res = await uploadAvatar(formData);
|
||||
formData.append('file', data, options.fileName || 'avatar.png');
|
||||
const res = await uploadOss(formData);
|
||||
await updateUserProfile({ avatar: res.data.ossId });
|
||||
open.value = false;
|
||||
options.img = res.data.imgUrl;
|
||||
options.img = res.data.url;
|
||||
userStore.setAvatar(options.img);
|
||||
modal.msgSuccess('修改成功');
|
||||
visible.value = false;
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { updateUserProfile } from '@/api/system/user';
|
||||
import type { UserProfileForm } from '@/api/system/user/types';
|
||||
import modal from '@/plugins/modal';
|
||||
import tab from '@/plugins/tab';
|
||||
import { useDict } from '@/utils/dict';
|
||||
@@ -65,7 +66,13 @@ const rules = ref<ElFormRules>(rule);
|
||||
const submit = () => {
|
||||
userRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
await updateUserProfile(props.user);
|
||||
const profile: UserProfileForm = {
|
||||
nickName: props.user.nickName,
|
||||
phoneNumber: props.user.phoneNumber,
|
||||
email: props.user.email,
|
||||
gender: props.user.gender
|
||||
};
|
||||
await updateUserProfile(profile);
|
||||
modal.msgSuccess('修改成功');
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user