Files
web-temp/layers/stores/useLoadingStore.ts
2025-09-09 03:34:09 +00:00

68 lines
1.3 KiB
TypeScript

import { defineStore } from "pinia";
export const useLoadingStore = defineStore("loadingStore", () => {
// 글로벌 로딩 표기
const fullLoading = ref(false);
// 컴포넌트별 로딩 표기
const localLoadings = ref<
Map<string, { active: boolean; element?: HTMLElement }>
>(new Map());
// 로딩 상태만 표기
const isLoading = ref(false);
/**
* 모든 로딩 상태 초기화
*/
const initializeStore = () => {
fullLoading.value = false;
localLoadings.value.clear();
};
/**
* Full 로딩
*/
const startFullLoading = () => {
fullLoading.value = true;
};
const stopFullLoading = () => {
fullLoading.value = false;
};
/**
* Local 로딩
*/
const startLocalLoading = (localId: string) => {
localLoadings.value.set(localId, { active: true });
};
const stopLocalLoading = (localId: string) => {
localLoadings.value.delete(localId);
};
const isLocalLoading = (localId: string) => {
return localLoadings.value.get(localId)?.active || false;
};
/**
* 로딩 상태 변경
*/
const setLoading = (state: boolean) => {
isLoading.value = state;
};
return {
fullLoading,
localLoadings,
isLoading,
initializeStore,
startFullLoading,
stopFullLoading,
startLocalLoading,
stopLocalLoading,
isLocalLoading,
setLoading,
};
});