wupengfei
4 天以前 5b0401fea3c339aa45feb0d165f36b1b7a76fdaf
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
import { useUserStore } from '@/store/modules/user';
import { UserUtils } from '@bole-core/core';
import * as userRoleServices from '@/services/api/UserRole';
import * as userServices from '@/services/api/User';
import { useQuery, useQueryClient } from '@tanstack/vue-query';
import { formatRoleName } from '@/utils';
import { EnumMenuScene } from '@/constants';
 
export function useIsSystemAdmin() {
  const userStore = useUserStore();
  const { accountInfo } = storeToRefs(userStore);
  const isSystemAdmin = computed(() => UserUtils.isSystemRole(accountInfo.value));
  return isSystemAdmin;
}
 
export function useUser() {
  const userStore = useUserStore();
 
  const { userId, userInfo } = storeToRefs(userStore);
 
  return {
    user: userInfo,
    userId: userId,
  };
}
 
type UseAllRoleListOptions = {
  menuScene?: EnumMenuScene;
};
 
export function useAllRoleList(options: UseAllRoleListOptions = {}) {
  const { menuScene = EnumMenuScene.Goverment } = options;
  const { data: allRoleList } = useQuery({
    queryKey: ['userRoleServices/getRoles', menuScene],
    queryFn: async () => {
      let res = await userRoleServices.getRoles({ menuScene }, { showLoading: false });
      return res.data;
    },
    select(data) {
      return data.map((x) => ({
        ...x,
        name: formatRoleName(x.name),
        realName: x.name,
      }));
    },
  });
 
  const enableRoleList = computed(() => {
    return allRoleList.value.filter((x) => x.isEnable);
  });
 
  return {
    allRoleList,
    enableRoleList,
  };
}