feat: 前端添加完善头像功能

This commit is contained in:
陈淳
2023-02-23 14:37:33 +08:00
parent 272466bbbf
commit 93de208ac0
9 changed files with 50 additions and 9 deletions

View File

@@ -1,9 +1,9 @@
import request from '@/utils/request'
export function
upload(type,data){
upload(data){
return request({
url: `/file/upload/${type}`,
url: `/file`,
headers:{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"},
method: 'POST',
data:data

View File

@@ -82,6 +82,15 @@ export function updateUserProfile(data) {
data: data
})
}
// 只修改用户头像
export function updateUserIcon(data) {
return request({
url: `/account/icon`,
method: 'put',
data:{icon:data}
})
}
// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {

View File

@@ -54,7 +54,7 @@
import "vue-cropper/dist/index.css";
import { VueCropper } from "vue-cropper";
import { upload } from "@/api/file";
import { updateUserProfile } from "@/api/system/user";
import { updateUserIcon } from "@/api/system/user";
import useUserStore from '@/store/modules/user'
const userStore = useUserStore()
@@ -116,14 +116,11 @@ function uploadImg() {
proxy.$refs.cropper.getCropBlob(data => {
let formData = new FormData();
formData.append("file", data);
upload("image",formData).then(response => {
upload(formData).then(response => {
open.value = false;
options.img = import.meta.env.VITE_APP_BASE_API +"/file/"+response.data[0];
options.img = import.meta.env.VITE_APP_BASE_API +"/file/"+response.data[0].id;
userStore.avatar = options.img;
updateUserProfile({icon:response.data[0]}).then(response2=>{
updateUserIcon(response.data[0].id).then(response2=>{
proxy.$modal.msgSuccess("修改成功");
visible.value = false;
})