refactor: Migrate the project functionality and optimize the code structure

This commit is contained in:
hayden
2024-10-12 17:31:11 +08:00
committed by hayden
parent d96aff80c2
commit c1747a79f3
71 changed files with 6741 additions and 1320 deletions

55
src/hooks/loading.ts Normal file
View File

@@ -0,0 +1,55 @@
import { defineStore } from 'hooks/store'
import { useBoolean } from 'hooks/utils'
import { Ref, ref } from 'vue'
class GlobalLoading {
loading: Ref<boolean>
loadingStack = 0
bind(loading: Ref<boolean>) {
this.loading = loading
}
show() {
this.loadingStack++
this.loading.value = true
}
hide() {
this.loadingStack--
if (this.loadingStack <= 0) this.loading.value = false
}
}
export const globalLoading = new GlobalLoading()
export const useGlobalLoading = defineStore('loading', () => {
const [loading] = useBoolean()
globalLoading.bind(loading)
return { loading }
})
export const useLoading = () => {
const timer = ref<NodeJS.Timeout>()
const show = () => {
timer.value = setTimeout(() => {
timer.value = undefined
globalLoading.show()
}, 200)
}
const hide = () => {
if (timer.value) {
clearTimeout(timer.value)
timer.value = undefined
} else {
globalLoading.hide()
}
}
return { show, hide }
}