办学质量监测教学评价系统
shenrongliang
2025-06-13 11d86cc6c26bb4f709e407acadf4805c2024e79f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { FileCallBack, UpdatePasswordParam, UserProfile } from './model';
 
import { buildUUID } from '@vben/utils';
 
import { requestClient } from '#/api/request';
 
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
 */
export function userUpdatePassword(data: UpdatePasswordParam) {
  return requestClient.putWithMsg<void>(Api.updatePassword, data, {
    encrypt: true,
  });
}
 
/**
 * 用户更新个人头像
 * @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' } },
  );
}