admin-vben5/apps/web-antd/src/api/system/profile/index.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

import type { FileCallBack, UpdatePasswordParam, UserProfile } from './model';
2024-09-03 10:47:33 +08:00
import { requestClient } from '#/api/request';
import { buildUUID } from '#/utils/uuid';
2024-09-03 10:47:33 +08:00
enum Api {
root = '/system/user/profile',
updateAvatar = '/system/user/profile/avatar',
updatePassword = '/system/user/profile/updatePwd',
}
/**
*
* @returns userInformation
*/
export function userProfile() {
return requestClient.get<UserProfile>(Api.root);
}
/**
*
* @param data
* @returns void
*/
export function userProfileUpdate(data: any) {
return requestClient.putWithMsg<void>(Api.root, data);
}
/**
* ()
* @param data
* @returns void
*/
2024-09-03 17:12:27 +08:00
export function userUpdatePassword(data: UpdatePasswordParam) {
return requestClient.putWithMsg<void>(Api.updatePassword, data, {
encrypt: true,
});
2024-09-03 10:47:33 +08:00
}
/**
*
* @param fileCallback data
* @returns void
*/
export function userUpdateAvatar(fileCallback: FileCallBack) {
/** 直接点击头像上传 filename为空 由于后台通过拓展名判断(默认文件名blob) 会上传失败 */
let { file } = fileCallback;
const { filename } = fileCallback;
/**
* Blob转File类型
* 1. filename为空 uuid作为文件名
* 2. File类型 Blob类型上传后台获取文件名为空
*/
file = filename
? new File([file], filename)
: new File([file], `${buildUUID()}.png`);
return requestClient.post(
Api.updateAvatar,
{
avatarfile: file,
},
{ headers: { 'Content-Type': 'multipart/form-data' } },
);
}