chore: save

This commit is contained in:
zyronon
2023-09-19 18:44:29 +08:00
parent f06069ee6c
commit 7b125bbaa4
14 changed files with 71 additions and 4891 deletions

View File

@@ -2,11 +2,27 @@ import {onMounted, onUnmounted} from "vue";
import {emitter, EventKey} from "@/utils/eventBus.ts";
export function useWindowClick(cb: () => void) {
onMounted(() => {
emitter.on(EventKey.closeOther, cb)
window.addEventListener('click', cb)
})
onUnmounted(() => {
window.removeEventListener('click', cb)
})
onMounted(() => {
emitter.on(EventKey.closeOther, cb)
window.addEventListener('click', cb)
})
onUnmounted(() => {
window.removeEventListener('click', cb)
})
}
export function useEventListener(type: string, listener: EventListenerOrEventListenerObject) {
onMounted(() => window.addEventListener(type, listener))
onUnmounted(() => window.removeEventListener(type, listener))
}
export function useEsc(can: boolean) {
onMounted(() => {
window.addEventListener('keyup', (e: KeyboardEvent) => {
if (e.key === 'Escape' && can) {
close()
}
})
})
return []
}

View File

@@ -1,12 +0,0 @@
import {onMounted} from "vue"
export function useEsc(can: boolean) {
onMounted(() => {
window.addEventListener('keyup', (e: KeyboardEvent) => {
if (e.key === 'Escape' && can) {
close()
}
})
})
return []
}

View File

@@ -1,7 +0,0 @@
// event.js
import {onMounted, onUnmounted} from 'vue'
export function useEventListener(type: string, listener: EventListenerOrEventListenerObject) {
onMounted(() => window.addEventListener(type, listener))
onUnmounted(() => window.removeEventListener(type, listener))
}