mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-12-26 15:00:16 +08:00
feat(projects): 添加常用组件、composables函数
This commit is contained in:
31
src/composables/events/auth.ts
Normal file
31
src/composables/events/auth.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { onMounted, onUnmounted } from 'vue';
|
||||
import { useAuthStore } from '@/store';
|
||||
|
||||
/** 添加用户权益变更的全局点击事件监听 */
|
||||
export function useAuthChangeEvent() {
|
||||
const { getIsAuthChange } = useAuthStore();
|
||||
|
||||
function eventHandler(event: MouseEvent) {
|
||||
const change = getIsAuthChange();
|
||||
if (change) {
|
||||
event.stopPropagation();
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
function addAuthChangeListener() {
|
||||
document.addEventListener('click', eventHandler, { capture: true });
|
||||
}
|
||||
|
||||
function removeAuthChangeListener() {
|
||||
document.removeEventListener('click', eventHandler);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
addAuthChangeListener();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
removeAuthChangeListener();
|
||||
});
|
||||
}
|
||||
12
src/composables/events/global.ts
Normal file
12
src/composables/events/global.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useAuthChangeEvent } from './auth';
|
||||
|
||||
export function useGlobalEvent() {
|
||||
/** 初始化全局监听事件 */
|
||||
function initGlobalListener() {
|
||||
useAuthChangeEvent();
|
||||
}
|
||||
|
||||
return {
|
||||
initGlobalListener
|
||||
};
|
||||
}
|
||||
1
src/composables/events/index.ts
Normal file
1
src/composables/events/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './global';
|
||||
Reference in New Issue
Block a user