feat: Improve the front-end permission access logic and sample code

This commit is contained in:
vince
2024-07-05 23:51:50 +08:00
parent dd71988253
commit a60467b01c
6 changed files with 163 additions and 11 deletions

View File

@@ -1,13 +1,26 @@
import { computed } from 'vue';
import { preferences } from '@vben-core/preferences';
import { useCoreAccessStore } from '@vben-core/stores';
function useAccess() {
const coreAccessStore = useCoreAccessStore();
const accessMode = computed(() => {
return preferences.app.accessMode;
});
return { accessMode };
/**
* 基于角色判断是否有权限
* @description: Determine whether there is permissionThe 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 };
}
export { useAccess };