2023-05-10 13:19:01 +08:00
|
|
|
import { defineStore } from 'pinia'
|
2023-08-10 13:46:33 +08:00
|
|
|
import type { AppState, Language, Theme, AudioSettings} from './helper'
|
2023-05-10 13:19:01 +08:00
|
|
|
import { getLocalSetting, setLocalSetting } from './helper'
|
2023-08-10 13:46:33 +08:00
|
|
|
|
2023-05-10 13:19:01 +08:00
|
|
|
import { store } from '@/store'
|
|
|
|
|
|
|
|
|
|
export const useAppStore = defineStore('app-store', {
|
|
|
|
|
state: (): AppState => getLocalSetting(),
|
|
|
|
|
actions: {
|
|
|
|
|
setSiderCollapsed(collapsed: boolean) {
|
|
|
|
|
this.siderCollapsed = collapsed
|
|
|
|
|
this.recordState()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setTheme(theme: Theme) {
|
|
|
|
|
this.theme = theme
|
|
|
|
|
this.recordState()
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
setLanguage(language: Language) {
|
|
|
|
|
if (this.language !== language) {
|
|
|
|
|
this.language = language
|
|
|
|
|
this.recordState()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2023-08-10 13:46:33 +08:00
|
|
|
setAudio(audioSettings: AudioSettings) {
|
|
|
|
|
this.audioSettings = audioSettings
|
|
|
|
|
this.recordState()
|
|
|
|
|
},
|
|
|
|
|
|
2023-05-10 13:19:01 +08:00
|
|
|
recordState() {
|
|
|
|
|
setLocalSetting(this.$state)
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export function useAppStoreWithOut() {
|
|
|
|
|
return useAppStore(store)
|
|
|
|
|
}
|