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';
|
|
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,
|
};
|
}
|
|
export function useAllRoleList() {
|
const { data: allRoleList, refetch } = useQuery({
|
queryKey: ['userServices/getAllRoles'],
|
queryFn: async () => {
|
let res = await userServices.getAllRoles({ showLoading: false });
|
return res;
|
},
|
placeholderData: () => [] as API.RoleInfo[],
|
select(data) {
|
return data.map((x) => ({
|
...x,
|
name: formatRoleName(x.name),
|
realName: x.name,
|
}));
|
},
|
});
|
|
return {
|
allRoleList,
|
refetch,
|
};
|
}
|