2024-06-30 15:03:37 +08:00
|
|
|
|
import { computed } from 'vue';
|
|
|
|
|
|
|
|
|
|
import { preferences } from '@vben-core/preferences';
|
2024-07-05 23:51:50 +08:00
|
|
|
|
import { useCoreAccessStore } from '@vben-core/stores';
|
2024-06-30 15:03:37 +08:00
|
|
|
|
|
|
|
|
|
function useAccess() {
|
2024-07-05 23:51:50 +08:00
|
|
|
|
const coreAccessStore = useCoreAccessStore();
|
2024-07-05 23:15:46 +08:00
|
|
|
|
const accessMode = computed(() => {
|
2024-06-30 15:03:37 +08:00
|
|
|
|
return preferences.app.accessMode;
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-05 23:51:50 +08:00
|
|
|
|
/**
|
|
|
|
|
* 基于角色判断是否有权限
|
|
|
|
|
* @description: Determine whether there is permission,The role is judged by the user's role
|
|
|
|
|
* @param roles
|
|
|
|
|
*/
|
|
|
|
|
function hasAuthByRole(roles: string[]) {
|
|
|
|
|
const userRoleSet = new Set(coreAccessStore.getUserRoles);
|
|
|
|
|
const intersection = roles.filter((item) => userRoleSet.has(item));
|
|
|
|
|
return intersection.length > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { accessMode, hasAuthByRole };
|
2024-06-30 15:03:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export { useAccess };
|