update 重构 头像上传改为先上传oss后更新用户数据
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import type { PageResult } from '@/api/types';
|
import type { PageResult } from '@/api/types';
|
||||||
import type { AxiosPromise } from '@/utils/api-types';
|
import type { AxiosPromise } from '@/utils/api-types';
|
||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import type { OssQuery, OssVO } from './types';
|
import type { OssQuery, OssUploadVO, OssVO } from './types';
|
||||||
|
|
||||||
// 查询OSS对象存储列表
|
// 查询OSS对象存储列表
|
||||||
export function listOss(query: OssQuery): AxiosPromise<PageResult<OssVO>> {
|
export function listOss(query: OssQuery): AxiosPromise<PageResult<OssVO>> {
|
||||||
@@ -20,6 +20,15 @@ export function listByIds(ossId: string | number): AxiosPromise<OssVO[]> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 上传OSS对象存储
|
||||||
|
export function uploadOss(data: FormData): AxiosPromise<OssUploadVO> {
|
||||||
|
return request({
|
||||||
|
url: '/resource/oss/upload',
|
||||||
|
method: 'post',
|
||||||
|
data
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 删除OSS对象存储
|
// 删除OSS对象存储
|
||||||
export function delOss(ossId: string | number | Array<string | number>) {
|
export function delOss(ossId: string | number | Array<string | number>) {
|
||||||
return request({
|
return request({
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ export interface OssVO extends BaseEntity {
|
|||||||
service: string;
|
service: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface OssUploadVO {
|
||||||
|
url: string;
|
||||||
|
fileName: string;
|
||||||
|
ossId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface OssQuery extends PageQuery {
|
export interface OssQuery extends PageQuery {
|
||||||
fileName: string;
|
fileName: string;
|
||||||
originalName: string;
|
originalName: string;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { AxiosPromise } from '@/utils/api-types';
|
|||||||
import request from '@/utils/request';
|
import request from '@/utils/request';
|
||||||
import { parseStrEmpty } from '@/utils/ruoyi';
|
import { parseStrEmpty } from '@/utils/ruoyi';
|
||||||
import type { DeptTreeVO } from './../dept/types';
|
import type { DeptTreeVO } from './../dept/types';
|
||||||
import type { UserForm, UserInfoVO, UserQuery, UserVO } from './types';
|
import type { UserForm, UserInfoVO, UserProfileForm, UserQuery, UserVO } from './types';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询用户列表
|
* 查询用户列表
|
||||||
@@ -136,7 +136,7 @@ export const getUserProfile = (): AxiosPromise<UserInfoVO> => {
|
|||||||
* 修改用户个人信息
|
* 修改用户个人信息
|
||||||
* @param data 用户信息
|
* @param data 用户信息
|
||||||
*/
|
*/
|
||||||
export const updateUserProfile = (data: UserForm) => {
|
export const updateUserProfile = (data: UserProfileForm) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/system/user/profile',
|
url: '/system/user/profile',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
@@ -165,18 +165,6 @@ export const updateUserPwd = (oldPassword: string, newPassword: string) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* 用户头像上传
|
|
||||||
* @param data 头像文件
|
|
||||||
*/
|
|
||||||
export const uploadAvatar = (data: FormData) => {
|
|
||||||
return request({
|
|
||||||
url: '/system/user/profile/avatar',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询授权角色
|
* 查询授权角色
|
||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
@@ -234,7 +222,6 @@ export default {
|
|||||||
getUserProfile,
|
getUserProfile,
|
||||||
updateUserProfile,
|
updateUserProfile,
|
||||||
updateUserPwd,
|
updateUserPwd,
|
||||||
uploadAvatar,
|
|
||||||
getAuthRole,
|
getAuthRole,
|
||||||
updateAuthRole,
|
updateAuthRole,
|
||||||
deptTreeSelect,
|
deptTreeSelect,
|
||||||
|
|||||||
@@ -71,6 +71,17 @@ export interface UserForm {
|
|||||||
roleIds: string[];
|
roleIds: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 个人资料表单类型
|
||||||
|
*/
|
||||||
|
export interface UserProfileForm {
|
||||||
|
nickName?: string;
|
||||||
|
phoneNumber?: string;
|
||||||
|
email?: string;
|
||||||
|
gender?: string;
|
||||||
|
avatar?: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface UserInfoVO {
|
export interface UserInfoVO {
|
||||||
user: UserVO;
|
user: UserVO;
|
||||||
roles: RoleVO[];
|
roles: RoleVO[];
|
||||||
|
|||||||
@@ -59,7 +59,8 @@
|
|||||||
import 'vue-cropper/dist/index.css';
|
import 'vue-cropper/dist/index.css';
|
||||||
import { UploadRawFile } from 'element-plus';
|
import { UploadRawFile } from 'element-plus';
|
||||||
import { VueCropper } from 'vue-cropper';
|
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 modal from '@/plugins/modal';
|
||||||
import { useUserStore } from '@/store/modules/user';
|
import { useUserStore } from '@/store/modules/user';
|
||||||
|
|
||||||
@@ -135,10 +136,11 @@ const beforeUpload = (file: UploadRawFile): any => {
|
|||||||
const uploadImg = async () => {
|
const uploadImg = async () => {
|
||||||
cropper.value.getCropBlob(async (data: any) => {
|
cropper.value.getCropBlob(async (data: any) => {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('avatarfile', data, options.fileName);
|
formData.append('file', data, options.fileName || 'avatar.png');
|
||||||
const res = await uploadAvatar(formData);
|
const res = await uploadOss(formData);
|
||||||
|
await updateUserProfile({ avatar: res.data.ossId });
|
||||||
open.value = false;
|
open.value = false;
|
||||||
options.img = res.data.imgUrl;
|
options.img = res.data.url;
|
||||||
userStore.setAvatar(options.img);
|
userStore.setAvatar(options.img);
|
||||||
modal.msgSuccess('修改成功');
|
modal.msgSuccess('修改成功');
|
||||||
visible.value = false;
|
visible.value = false;
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { updateUserProfile } from '@/api/system/user';
|
import { updateUserProfile } from '@/api/system/user';
|
||||||
|
import type { UserProfileForm } from '@/api/system/user/types';
|
||||||
import modal from '@/plugins/modal';
|
import modal from '@/plugins/modal';
|
||||||
import tab from '@/plugins/tab';
|
import tab from '@/plugins/tab';
|
||||||
import { useDict } from '@/utils/dict';
|
import { useDict } from '@/utils/dict';
|
||||||
@@ -65,7 +66,13 @@ const rules = ref<ElFormRules>(rule);
|
|||||||
const submit = () => {
|
const submit = () => {
|
||||||
userRef.value?.validate(async (valid: boolean) => {
|
userRef.value?.validate(async (valid: boolean) => {
|
||||||
if (valid) {
|
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('修改成功');
|
modal.msgSuccess('修改成功');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user