ny
22 小时以前 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
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
import { defineStore } from 'pinia';
 
import { getGroupSelector } from '#/api/permission/group';
import { getRoleSelector } from '#/api/permission/role';
 
interface BaseState {
  groupList: any[];
  roleList: any[];
}
 
/**
 * 组织权限相关
 */
export const useOrganizeStore = defineStore('organize', {
  getters: {},
  actions: {
    async getGroupList(): Promise<any[]> {
      try {
        if (this.groupList.length > 0) return this.groupList;
        const res = await getGroupSelector();
        if (!res) return [];
        this.groupList = (res.data || []).map((o) => ({ ...o, type: 'group' }));
        return this.groupList;
      } catch {
        return [];
      }
    },
    async getAllRoleList(): Promise<any[]> {
      try {
        if (this.roleList.length > 0) return this.roleList;
        const res = await getRoleSelector();
        if (!res) return [];
        this.roleList = (res.data.list || []).map((o) => ({ ...o, roleType: o.type, type: 'role' }));
        return this.roleList;
      } catch {
        return [];
      }
    },
    async getRoleList(data: any = {}): Promise<any[]> {
      const { type = 'user', isSystem = 0 } = data;
      // type : user-用户角色 organize-组织角色 position-岗位角色
      // isSystem : 0-过滤系统角色 1-只有系统角色 2-全部角色
      try {
        const list = this.roleList.length ? this.roleList : await this.getAllRoleList();
        let result = list.filter((o) => o.roleType === type);
        if (!isSystem) result = result.filter((o) => o.globalMark !== 1);
        if (isSystem === 1) result = result.filter((o) => o.globalMark === 1);
        return result;
      } catch {
        return [];
      }
    },
    $reset() {
      this.groupList = [];
      this.roleList = [];
    },
  },
  state: (): BaseState => ({
    groupList: [],
    roleList: [],
  }),
});