- Change the method of open dialog - Fix the problem of open dialog disappearing due to virtual scrolling - Float the active dialog to the top
55 lines
967 B
TypeScript
55 lines
967 B
TypeScript
import { defineStore } from 'hooks/store'
|
|
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 = ref(false)
|
|
|
|
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 }
|
|
}
|