tj
2025-06-05 bba272999cc546f65781bf3d20245a3f819af67f
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import store from '@/store'
import _axios, { get, put } from '@/lin/plugin/axios'
import { saveTokens } from '../util/token'
 
export default class User {
  /**
   * 分配用户
   * @param {object} user 注册信息
   */
  static register(user) {
    return _axios({
      method: 'post',
      url: 'cms/user/register',
      data: {
        email: user.email,
        username: user.username,
        nickname: user.nickname,
        password: user.password,
        group_ids: user.groupIds,
        confirm_password: user.confirmPassword,
 
        staff_status:user.staff_status,
        show_board_flag:user.show_board_flag,
        hiredate:user.hiredate,
        unhiredate:user.unhiredate,
        send_email_flag:user.send_email_flag,
 
      },
      handleError: true,
    })
  }
 
  /**
   * 登陆获取tokens
   * @param { String } username 用户名
   * @param { String } password 密码
   * @param { String } captcha 验证码
   * @param { String } tag 验证码签名
   */
  static async getToken(username, password, captcha, tag) {
    const tokens = await _axios({
      url: 'cms/user/login',
      method: 'POST',
      data: {
        captcha,
        username,
        password,
      },
      headers: {
        tag,
      },
    })
    saveTokens(tokens.access_token, tokens.refresh_token)
    return tokens
  }
 
  /**
   * 获取当前用户信息,并返回User实例
   */
  static async getInformation() {
    const info = await get('cms/user/information')
    const storeUser = store.getters.user === null ? {} : store.getters.user
    return Object.assign({ ...storeUser }, info)
  }
 
  /**
   * 获取当前用户信息和所拥有的权限
   */
  static async getPermissions() {
    const info = await get('cms/user/permissions')
    const storeUser = store.getters.user === null ? {} : store.getters.user
    return Object.assign({ ...storeUser }, info)
  }
 
  /**
   * 用户修改密码
   * @param {string} newPassword 新密码
   * @param {string} confirmPassword 确认新密码
   * @param {string} oldPassword 旧密码
   */
  // eslint-disable-next-line camelcase
  static updatePassword({ old_password, new_password, confirm_password }) {
    return put('cms/user/change_password', {
      new_password,
      confirm_password,
      old_password,
    })
  }
 
}