mirror of
https://gitee.com/JavaLionLi/plus-ui.git
synced 2026-09-14 00:03:42 +08:00
update 重构 头像上传改为先上传oss后更新用户数据
This commit is contained in:
parent
f9e9055a3f
commit
cf53df4f4a
@ -3,7 +3,7 @@ import type { RoleVO } from '@/api/system/role/types';
|
|||||||
import type { PageResult, R } from '@/api/types';
|
import type { PageResult, R } from '@/api/types';
|
||||||
import request from '@/api/request';
|
import request from '@/api/request';
|
||||||
import { parseStrEmpty } from '@/utils/ruoyi';
|
import { parseStrEmpty } from '@/utils/ruoyi';
|
||||||
import type { UserForm, UserInfoVO, UserQuery, UserVO } from './types';
|
import type { UserForm, UserInfoVO, UserProfileForm, UserQuery, UserVO } from './types';
|
||||||
|
|
||||||
export function listUser(query: UserQuery) {
|
export function listUser(query: UserQuery) {
|
||||||
return request<R<PageResult<UserVO>>>({
|
return request<R<PageResult<UserVO>>>({
|
||||||
@ -90,7 +90,7 @@ export function getUserProfile() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function updateUserProfile(data: UserForm) {
|
export function updateUserProfile(data: UserProfileForm) {
|
||||||
return request<R>({
|
return request<R>({
|
||||||
url: '/system/user/profile',
|
url: '/system/user/profile',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
@ -113,14 +113,6 @@ export function updateUserPwd(oldPassword: string, newPassword: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function uploadAvatar(data: FormData) {
|
|
||||||
return request<R<{ imgUrl: string }>>({
|
|
||||||
url: '/system/user/profile/avatar',
|
|
||||||
method: 'post',
|
|
||||||
data
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function importUser(data: FormData, updateSupport: boolean) {
|
export function importUser(data: FormData, updateSupport: boolean) {
|
||||||
return request<R>({
|
return request<R>({
|
||||||
url: '/system/user/importData',
|
url: '/system/user/importData',
|
||||||
|
|||||||
@ -30,6 +30,14 @@ export interface UserForm {
|
|||||||
roleIds?: Array<string | number>;
|
roleIds?: Array<string | number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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[];
|
||||||
|
|||||||
@ -22,10 +22,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|||||||
import Cropper, { type ReactCropperElement } from 'react-cropper';
|
import Cropper, { type ReactCropperElement } from 'react-cropper';
|
||||||
import type { OnlineVO } from '@/api/monitor/online/types';
|
import type { OnlineVO } from '@/api/monitor/online/types';
|
||||||
import type { SocialAuthVO } from '@/api/system/social/types';
|
import type { SocialAuthVO } from '@/api/system/social/types';
|
||||||
import type { UserForm, UserInfoVO } from '@/api/system/user/types';
|
import type { UserInfoVO, UserProfileForm } from '@/api/system/user/types';
|
||||||
import { delOnline, getOnline } from '@/api/monitor/online';
|
import { delOnline, getOnline } from '@/api/monitor/online';
|
||||||
|
import { uploadOss } from '@/api/system/oss';
|
||||||
import { authRouterUrl, authUnlock, getAuthList } from '@/api/system/social/auth';
|
import { authRouterUrl, authUnlock, getAuthList } from '@/api/system/social/auth';
|
||||||
import { getUserProfile, updateUserProfile, updateUserPwd, uploadAvatar } from '@/api/system/user';
|
import { getUserProfile, updateUserProfile, updateUserPwd } from '@/api/system/user';
|
||||||
import giteeIcon from '@/assets/icons/svg/gitee.svg';
|
import giteeIcon from '@/assets/icons/svg/gitee.svg';
|
||||||
import githubIcon from '@/assets/icons/svg/github.svg';
|
import githubIcon from '@/assets/icons/svg/github.svg';
|
||||||
import maxkeyIcon from '@/assets/icons/svg/maxkey.svg';
|
import maxkeyIcon from '@/assets/icons/svg/maxkey.svg';
|
||||||
@ -78,7 +79,7 @@ function normalizeOnlineDevices(payload: OnlineVO[] | { rows?: OnlineVO[] } | un
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const [userForm] = Form.useForm<UserForm>();
|
const [userForm] = Form.useForm<UserProfileForm>();
|
||||||
const [pwdForm] = Form.useForm<{ oldPassword: string; newPassword: string; confirmPassword: string }>();
|
const [pwdForm] = Form.useForm<{ oldPassword: string; newPassword: string; confirmPassword: string }>();
|
||||||
const reloadMenus = usePermissionStore(state => state.reloadMenus);
|
const reloadMenus = usePermissionStore(state => state.reloadMenus);
|
||||||
const dicts = useDict('sys_user_gender', 'sys_device_type');
|
const dicts = useDict('sys_user_gender', 'sys_device_type');
|
||||||
@ -110,7 +111,13 @@ export default function Profile() {
|
|||||||
|
|
||||||
const submitUserInfo = async () => {
|
const submitUserInfo = async () => {
|
||||||
const values = await userForm.validateFields();
|
const values = await userForm.validateFields();
|
||||||
await updateUserProfile(values);
|
const profileForm: UserProfileForm = {
|
||||||
|
nickName: values.nickName,
|
||||||
|
phoneNumber: values.phoneNumber,
|
||||||
|
email: values.email,
|
||||||
|
gender: values.gender
|
||||||
|
};
|
||||||
|
await updateUserProfile(profileForm);
|
||||||
message.success('修改成功');
|
message.success('修改成功');
|
||||||
await reloadMenus();
|
await reloadMenus();
|
||||||
await loadProfile();
|
await loadProfile();
|
||||||
@ -163,10 +170,14 @@ export default function Profile() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('avatarfile', blob, avatarFileName);
|
formData.append('file', blob, avatarFileName || 'avatar.png');
|
||||||
await withAvatarUploading(async () => {
|
await withAvatarUploading(async () => {
|
||||||
try {
|
try {
|
||||||
await uploadAvatar(formData);
|
const res = await uploadOss(formData);
|
||||||
|
if (!res.data.ossId) {
|
||||||
|
throw new Error('头像上传失败');
|
||||||
|
}
|
||||||
|
await updateUserProfile({ avatar: res.data.ossId });
|
||||||
message.success('修改成功');
|
message.success('修改成功');
|
||||||
closeAvatarCrop();
|
closeAvatarCrop();
|
||||||
await reloadMenus();
|
await reloadMenus();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user