import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useLoadingStore = defineStore('loading', () => {
    // 控制加载页显示状态
    const isLoading = ref(false)
    // 加载页文本
    const loadingText = ref('正在加载...')

    // 显示加载页
    const showLoading = (text?: string) => {
        if (text)
            loadingText.value = text
        isLoading.value = true
    }

    // 隐藏加载页
    const hideLoading = (delay = 100) => {
        setTimeout(() => {
            isLoading.value = false
        }, delay)
    }

    return {
        isLoading,
        loadingText,
        showLoading,
        hideLoading
    }
})
