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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* eslint-disable class-methods-use-this */
import { post, get, put, _delete } from '@/lin/plugin/axios'
 
export default class Admin {
  constructor(uPage = 0, uCount = 10, gPage = 0, gCount = 5) {
    this.uPage = uPage
    this.uCount = uCount
    this.lPage = gPage
    this.gCount = gCount
  }
 
  async increaseUPage() {
    this.uPage += 1
  }
 
  async increaseGPage() {
    this.lPage += 1
  }
 
  async decreaseUPage() {
    this.uPage -= 1
    if (this.uPage < 0) {
      this.uPage = 0
    }
  }
 
  async decreaseGPage() {
    this.lPage -= 1
    if (this.lPage < 0) {
      this.lPage = 0
    }
  }
 
  static getAllPermissions() {
    return get('cms/admin/permission')
  }
 
  static async getAdminUsers({ groupId, count = this.uCount, page = this.uPage }) {
    let res
    if (groupId) {
      res = await get('cms/admin/users', {
        count,
        page,
        group_id: groupId,
      })
    } else {
      res = await get('cms/admin/users', {
        count,
        page,
      })
    }
    return res
  }
 
  async nextUsersPage() {
    await this.increaseUPage()
    return this.getAdminUsers({})
  }
 
  async preUsersPage() {
    await this.decreaseUPage()
    return this.getAdminUsers({})
  }
 
  async getGroupsWithPermissions({ count = this.uCount, page = this.uPage }) {
    const res = await get('cms/admin/groups', {
      count,
      page,
    })
    return res
  }
 
  async nextGroupsPage() {
    await this.increaseGPage()
    return this.getGroupsWithPermissions({})
  }
 
  async preGroupsPage() {
    await this.decreaseGPage()
    return this.getGroupsWithPermissions({})
  }
 
  static async getAllGroups() {
    const groups = await get('cms/admin/group/all')
    return groups
  }
 
  static async getOneGroup(id) {
    const group = await get(`cms/admin/group/${id}`)
    return group
  }
 
  // eslint-disable-next-line camelcase
  static async createOneGroup(name, info, permission_ids) {
    const res = await post('cms/admin/group', {
      name,
      info,
      permission_ids,
    })
    return res
  }
 
  static async updateOneGroup(name, info, id) {
    const res = await put(`cms/admin/group/${id}`, {
      name,
      info,
    })
    return res
  }
 
  static async deleteOneGroup(id) {
    const res = await _delete(`cms/admin/group/${id}`)
    return res
  }
 
  static async deleteOneUser(id) {
    const res = await _delete(`cms/admin/user/${id}`)
    return res
  }
 
  // eslint-disable-next-line camelcase
  static async updateOneUser(email,staff_status,show_board_flag,hiredate,unhiredate,send_email_flag, group_ids, id) {
    const res = await put(`cms/admin/user/${id}`, {
      email,
      staff_status,      
      show_board_flag,   
      hiredate,          
      unhiredate,        
      send_email_flag, 
      group_ids,
    })
    return res
  }
 
  // eslint-disable-next-line camelcase
  static async dispatchPermissions(group_id, permission_ids) {
    const res = await post('cms/admin/permission/dispatch/batch', {
      group_id,
      permission_ids,
    })
    return res
  }
 
  // eslint-disable-next-line camelcase
  static async changePassword(new_password, confirm_password, id) {
    const res = await put(`cms/admin/user/${id}/password`, {
      new_password,
      confirm_password,
    })
    return res
  }
 
  // eslint-disable-next-line camelcase
  static async removePermissions(group_id, permission_ids) {
    const res = await post('cms/admin/permission/remove', {
      group_id,
      permission_ids,
    })
    return res
  }
}