--添加测试模块
This commit is contained in:
32
src/directives/allPermission.ts
Normal file
32
src/directives/allPermission.ts
Normal file
@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Global authority directive
|
||||
* Used for fine-grained control of component permissions
|
||||
* @Example v-auth="RoleEnum.TEST"
|
||||
*/
|
||||
import type { App, Directive, DirectiveBinding } from 'vue';
|
||||
|
||||
import { usePermission } from '/@/hooks/web/usePermission';
|
||||
|
||||
function isAllAuth(el: Element, binding: any) {
|
||||
const { hasAllPermission } = usePermission();
|
||||
|
||||
const value = binding.value;
|
||||
if (!value) return;
|
||||
if (!hasAllPermission(value)) {
|
||||
el.parentNode?.removeChild(el);
|
||||
}
|
||||
}
|
||||
|
||||
const mounted = (el: Element, binding: DirectiveBinding<any>) => {
|
||||
isAllAuth(el, binding);
|
||||
};
|
||||
|
||||
const allAuthDirective: Directive = {
|
||||
mounted,
|
||||
}
|
||||
|
||||
export function setupAllPermissionDirective(app: App) {
|
||||
app.directive('allAuth', allAuthDirective);
|
||||
}
|
||||
|
||||
export default allAuthDirective;
|
||||
@ -3,9 +3,11 @@
|
||||
*/
|
||||
import type { App } from 'vue';
|
||||
import { setupPermissionDirective } from './permission';
|
||||
import { setupAllPermissionDirective } from './allPermission';
|
||||
import { setupLoadingDirective } from './loading';
|
||||
|
||||
export function setupGlobDirectives(app: App) {
|
||||
setupPermissionDirective(app);
|
||||
setupAllPermissionDirective(app);
|
||||
setupLoadingDirective(app);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user