mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
refactor(projects): 精简版+动态路由权限初步
This commit is contained in:
@ -1,27 +0,0 @@
|
||||
import type { App, Directive } from 'vue';
|
||||
import { useAuthStore } from '@/store';
|
||||
import { useRouterPush } from '@/composables';
|
||||
|
||||
export default function setupLoginDirective(app: App) {
|
||||
const auth = useAuthStore();
|
||||
const { toLogin } = useRouterPush(false);
|
||||
function listenerHandler(event: MouseEvent) {
|
||||
if (!auth.isLogin) {
|
||||
event.stopPropagation();
|
||||
toLogin();
|
||||
}
|
||||
}
|
||||
|
||||
const loginDirective: Directive<HTMLElement, boolean | undefined> = {
|
||||
mounted(el: HTMLElement, binding) {
|
||||
if (binding.value === false) return;
|
||||
el.addEventListener('click', listenerHandler, { capture: true });
|
||||
},
|
||||
unmounted(el: HTMLElement, binding) {
|
||||
if (binding.value === false) return;
|
||||
el.removeEventListener('click', listenerHandler);
|
||||
}
|
||||
};
|
||||
|
||||
app.directive('login', loginDirective);
|
||||
}
|
Reference in New Issue
Block a user