mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加常用组件、composables函数
This commit is contained in:
27
src/directives/login.ts
Normal file
27
src/directives/login.ts
Normal file
@ -0,0 +1,27 @@
|
||||
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