|
@@ -3,22 +3,26 @@ import { Directive, ObjectDirective } from 'vue';
|
|
|
// 权限控制
|
|
|
const PermissionDirective: Directive = {
|
|
|
mounted(el: HTMLElement, binding: { value: string[] }, vnode: any) {
|
|
|
- const routePath = vnode.ctx.appContext.config.globalProperties.$route.path;
|
|
|
- console.log(extractPath(routePath))
|
|
|
- // const currentRoute = getCurrentInstance()?.appContext.config.globalProperties.$route;
|
|
|
- // console.log('Current Route:', currentRoute);
|
|
|
-
|
|
|
- // const permissions = binding.value;
|
|
|
- // if (!Array.isArray(permissions)) {
|
|
|
- // console.error('Permissions must be provided as an array.');
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // if (!permissions.some((permission: string) => permission === 'admin')) {
|
|
|
- // el.parentNode && el.parentNode.removeChild(el)
|
|
|
- // }
|
|
|
+ const routePath: string = vnode.ctx.appContext.config.globalProperties.$route.path;
|
|
|
+ const userInfo: { userInfo: { functionList: { code: string }[] } } | null = JSON.parse(localStorage.getItem('storeInfo') || '');
|
|
|
+ const authorityCodes: string[] = (userInfo?.userInfo?.functionList || []).map(({ code }) => code);
|
|
|
+ const permissions: string[] = binding.value;
|
|
|
+
|
|
|
+ if (!Array.isArray(permissions)) {
|
|
|
+ console.error('权限必须以数组形式提供');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!permissions.every(permission => authorityCodes.includes(permission))) {
|
|
|
+ el.parentNode && el.parentNode.removeChild(el);
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(extractPath(routePath), authorityCodes);
|
|
|
+ console.log(permissions, !permissions.every(permission => authorityCodes.includes(permission)))
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+// input 字符串数字
|
|
|
const PositiveIntegerDirective: ObjectDirective = {
|
|
|
mounted(el: HTMLElement) {
|
|
|
el.addEventListener('input', handleInput);
|