export const useLoadingStore = defineStore('loadingStore', () => { // 글로벌 로딩 표기 const fullLoading = ref(true) const hasApiCallStarted = ref(false) const isPAssApiLoading = ref(false) // 컴포넌트별 로딩 표기 - Map 대신 일반 객체 사용 const localLoadings = ref>({}) const apiLoadingTimeoutId = ref | null>(null) /** * Full 로딩 */ const startFullLoading = () => { hasApiCallStarted.value = false isPAssApiLoading.value = false fullLoading.value = true } const startApiLoading = () => { hasApiCallStarted.value = true isPAssApiLoading.value = false } const stopFullLoading = () => { if (!hasApiCallStarted.value || isPAssApiLoading.value) { fullLoading.value = false } } const finishApiLoading = () => { // 이전 타이머가 있으면 정리 if (apiLoadingTimeoutId.value) { clearTimeout(apiLoadingTimeoutId.value) apiLoadingTimeoutId.value = null } apiLoadingTimeoutId.value = setTimeout(() => { hasApiCallStarted.value = false isPAssApiLoading.value = true apiLoadingTimeoutId.value = null }, 300) } /** * Local 로딩 */ const startLocalLoading = (localId: string) => { localLoadings.value[localId] = { active: true } } const stopLocalLoading = (localId: string) => { if (localLoadings.value[localId]) { localLoadings.value[localId].active = false } } const isLocalLoading = (localId: string) => { return !!localLoadings.value[localId]?.active } return { fullLoading, localLoadings, hasApiCallStarted, isPAssApiLoading, startApiLoading, finishApiLoading, startFullLoading, stopFullLoading, startLocalLoading, stopLocalLoading, isLocalLoading, } })