import { defineStore } from 'pinia' import { ref } from 'vue' export interface HomeApp { parentLink: string icon: string link: string name: string } export const useHomeAppStore = defineStore('homeApp', () => { const homeAppList = ref([]) const isInitialized = ref(false) // 设置 homeAppList const setHomeAppList = (apps: HomeApp[]) => { homeAppList.value = apps } // 获取 homeAppList const getHomeAppList = () => { return homeAppList.value } // 清空应用列表 const clearHomeAppList = () => { homeAppList.value = [] } // 初始化 store const init = (apps?: HomeApp[]) => { if (isInitialized.value && !apps) return if (apps) { setHomeAppList(apps) } isInitialized.value = true } return { homeAppList, isInitialized, setHomeAppList, getHomeAppList, clearHomeAppList, init, } }, { // 持久化存储,默认持久化整个 store(主要是 homeAppList) persist: true, }) export default useHomeAppStore