mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-08-09 07:33:24 +08:00
整合全局设置store,优化PWA模式检测
This commit is contained in:
51
src/stores/globalSettings.ts
Normal file
51
src/stores/globalSettings.ts
Normal 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,
|
||||
},
|
||||
})
|
||||
@@ -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 }
|
||||
|
||||
@@ -21,3 +21,12 @@ export interface userState {
|
||||
// 权限
|
||||
permissions: { [key: string]: any }
|
||||
}
|
||||
|
||||
export interface globalSettingsState {
|
||||
// 全局设置数据
|
||||
data: { [key: string]: any }
|
||||
// 是否已初始化
|
||||
initialized: boolean
|
||||
// 是否正在加载
|
||||
loading: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user