feat(projects): 添加常用组件、composables函数

This commit is contained in:
Soybean
2021-12-12 17:28:39 +08:00
parent e755caabf2
commit 230a50a4cf
87 changed files with 5424 additions and 2071 deletions

View 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();
});
}

View File

@@ -0,0 +1,12 @@
import { useAuthChangeEvent } from './auth';
export function useGlobalEvent() {
/** 初始化全局监听事件 */
function initGlobalListener() {
useAuthChangeEvent();
}
return {
initGlobalListener
};
}

View File

@@ -0,0 +1 @@
export * from './global';