OncoLit: a multi-tenant oncology literature search, feed, and collaboration platform. Built with FastAPI + Vue 3 + PostgreSQL. Includes PubMed pipeline, drug approvals, AI summaries, and systematic review tools.
31 lines
898 B
TypeScript
31 lines
898 B
TypeScript
/** 全局请求加载状态 — 由 axios 拦截器自动维护 */
|
|
import { ref, watch } from 'vue'
|
|
|
|
/** 当前在途请求数 */
|
|
const pendingCount = ref(0)
|
|
|
|
/** 是否显示加载条(延迟 300ms 后为 true,避免闪烁) */
|
|
const showBar = ref(false)
|
|
|
|
let timer: ReturnType<typeof setTimeout> | null = null
|
|
|
|
watch(pendingCount, (count) => {
|
|
if (count > 0) {
|
|
// 请求开始后 300ms 才显示(快请求不闪条)
|
|
if (timer === null) {
|
|
timer = setTimeout(() => { showBar.value = true }, 300)
|
|
}
|
|
} else {
|
|
// 所有请求完成 → 立即隐藏
|
|
showBar.value = false
|
|
if (timer !== null) { clearTimeout(timer); timer = null }
|
|
}
|
|
})
|
|
|
|
export function useGlobalLoading() {
|
|
function increment() { pendingCount.value++ }
|
|
function decrement() { if (pendingCount.value > 0) pendingCount.value-- }
|
|
|
|
return { pendingCount, showBar, increment, decrement }
|
|
}
|