整合全局设置store,优化PWA模式检测

This commit is contained in:
jxxghp
2025-07-04 16:19:50 +08:00
parent e45919cac1
commit 85780917c2
31 changed files with 294 additions and 116 deletions

View File

@@ -0,0 +1,51 @@
import { defineStore } from 'pinia'
import type { globalSettingsState } from '@/stores/types'
import { fetchGlobalSettings } from '@/utils/globalSetting'
export const useGlobalSettingsStore = defineStore('globalSettings', {
state: (): globalSettingsState => ({
data: {},
initialized: false,
loading: false,
}),
actions: {
async initialize() {
if (this.initialized || this.loading) return
this.loading = true
try {
const result = await fetchGlobalSettings()
this.data = result || {}
this.initialized = true
} catch (error) {
console.error('Failed to initialize global settings', error)
} finally {
this.loading = false
}
},
setData(data: { [key: string]: any }) {
this.data = data
this.initialized = true
},
get(key: string) {
return this.data[key]
},
reset() {
this.data = {}
this.initialized = false
this.loading = false
},
},
getters: {
isInitialized: state => state.initialized,
isLoading: state => state.loading,
getData: state => state.data,
// 直接返回data对象避免使用.value
globalSettings: state => state.data,
},
})

View File

@@ -12,5 +12,6 @@ export default pinia
// 所有的 store
import { useAuthStore } from './auth'
import { useUserStore } from './user'
import { useGlobalSettingsStore } from './globalSettings'
export { useAuthStore, useUserStore }
export { useAuthStore, useUserStore, useGlobalSettingsStore }

View File

@@ -21,3 +21,12 @@ export interface userState {
// 权限
permissions: { [key: string]: any }
}
export interface globalSettingsState {
// 全局设置数据
data: { [key: string]: any }
// 是否已初始化
initialized: boolean
// 是否正在加载
loading: boolean
}