5 changed files with 104 additions and 88 deletions
@ -0,0 +1,50 @@ |
|||||
|
import { UnwrapRef } from 'vue' |
||||
|
import { Language, State } from './state' |
||||
|
import { i18n } from '@/i18n' |
||||
|
import { PiniaCustomProperties, _StoreWithGetters, _StoreWithState } from 'pinia' |
||||
|
import { GlobalType } from './storeID' |
||||
|
|
||||
|
/* eslint-disable no-unused-vars */ |
||||
|
export interface Actions { |
||||
|
SET_SHOP_LIST(list: any[]): void |
||||
|
SET_SELECTED_MODULE(moduleName: string): void |
||||
|
SET_LANGUAGE(language: Language): void |
||||
|
SET_CURRENT_FLOOR(currentFloor: Record<string, any>): void |
||||
|
SET_SHOP(shop: Record<string, any>): void |
||||
|
SET_CONFIG(config: Record<string, any>): void |
||||
|
SET_IS_USE_FACE(flag: boolean): void |
||||
|
SET_IS_USE_SPEECH(flag: boolean): void |
||||
|
} |
||||
|
|
||||
|
type __StoreWithState = _StoreWithState<GlobalType, State, Record<string, any>, Actions> |
||||
|
type __StoreWithGetters = _StoreWithGetters<Record<string, any>> |
||||
|
|
||||
|
type MyThis = Actions & ThisType<Actions & UnwrapRef<State> & __StoreWithState & __StoreWithGetters & PiniaCustomProperties> |
||||
|
|
||||
|
export const actions: MyThis = { |
||||
|
SET_LANGUAGE(language) { |
||||
|
i18n.global.locale = language |
||||
|
this.language = language |
||||
|
}, |
||||
|
SET_CONFIG(config) { |
||||
|
this.config = config |
||||
|
}, |
||||
|
SET_SHOP_LIST(list) { |
||||
|
this.shopList = list |
||||
|
}, |
||||
|
SET_SELECTED_MODULE(moduleName) { |
||||
|
this.selectedModule = moduleName |
||||
|
}, |
||||
|
SET_CURRENT_FLOOR(currentFloor) { |
||||
|
this.currentFloor = currentFloor |
||||
|
}, |
||||
|
SET_SHOP(shop) { |
||||
|
this.shop = shop |
||||
|
}, |
||||
|
SET_IS_USE_FACE(flag) { |
||||
|
this.isUseFace = flag |
||||
|
}, |
||||
|
SET_IS_USE_SPEECH(flag) { |
||||
|
this.isUseSpeech = flag |
||||
|
} |
||||
|
} |
||||
@ -1,65 +1,9 @@ |
|||||
import { defineStore } from 'pinia' |
import { defineStore } from 'pinia' |
||||
import { i18n } from '@/i18n' |
|
||||
export type Language = 'zh' | 'en' | 'tw' |
|
||||
|
import { state, State } from './state' |
||||
|
import { Actions, actions } from './actions' |
||||
|
import { GLOBAL_STORE_ID, GlobalType } from './storeID' |
||||
|
|
||||
interface State { |
|
||||
shopList: any[] |
|
||||
selectedModule: string |
|
||||
language: Language |
|
||||
currentFloor: Record<string, any> |
|
||||
shop: Record<string, any> |
|
||||
config: Record<string, any> |
|
||||
isUseFace: boolean |
|
||||
isUseSpeech: boolean |
|
||||
} |
|
||||
/* eslint-disable no-unused-vars */ |
|
||||
interface Actions { |
|
||||
SET_SHOP_LIST(list: any[]): void |
|
||||
SET_SELECTED_MODULE(moduleName: string): void |
|
||||
SET_LANGUAGE(language: Language): void |
|
||||
SET_CURRENT_FLOOR(currentFloor: Record<string, any>): void |
|
||||
SET_SHOP(shop: Record<string, any>): void |
|
||||
SET_CONFIG(config: Record<string, any>): void |
|
||||
SET_IS_USE_FACE(flag: boolean): void |
|
||||
SET_IS_USE_SPEECH(flag: boolean): void |
|
||||
} |
|
||||
|
|
||||
export const useStore = defineStore<string, State, Record<string, any>, Actions>('globalStore', { |
|
||||
state: () => ({ |
|
||||
shopList: [], |
|
||||
selectedModule: '', |
|
||||
language: 'zh', |
|
||||
config: {}, |
|
||||
shop: {}, |
|
||||
currentFloor: {}, |
|
||||
isUseFace: false, |
|
||||
isUseSpeech: false |
|
||||
}), |
|
||||
actions: { |
|
||||
SET_LANGUAGE(language) { |
|
||||
i18n.global.locale = language |
|
||||
this.language = language |
|
||||
}, |
|
||||
SET_CONFIG(config) { |
|
||||
this.config = config |
|
||||
}, |
|
||||
SET_SHOP_LIST(list) { |
|
||||
this.shopList = list |
|
||||
}, |
|
||||
SET_SELECTED_MODULE(moduleName) { |
|
||||
this.selectedModule = moduleName |
|
||||
}, |
|
||||
SET_CURRENT_FLOOR(currentFloor) { |
|
||||
this.currentFloor = currentFloor |
|
||||
}, |
|
||||
SET_SHOP(shop) { |
|
||||
this.shop = shop |
|
||||
}, |
|
||||
SET_IS_USE_FACE(flag) { |
|
||||
this.isUseFace = flag |
|
||||
}, |
|
||||
SET_IS_USE_SPEECH(flag) { |
|
||||
this.isUseSpeech = flag |
|
||||
} |
|
||||
} |
|
||||
|
export const useStore = defineStore<GlobalType, State, Record<string, any>, Actions>(GLOBAL_STORE_ID, { |
||||
|
state, |
||||
|
actions |
||||
}) |
}) |
||||
|
|||||
@ -0,0 +1,23 @@ |
|||||
|
export type Language = 'zh' | 'en' | 'tw' |
||||
|
|
||||
|
export interface State { |
||||
|
shopList: any[] |
||||
|
selectedModule: string |
||||
|
language: Language |
||||
|
currentFloor: Record<string, any> |
||||
|
shop: Record<string, any> |
||||
|
config: Record<string, any> |
||||
|
isUseFace: boolean |
||||
|
isUseSpeech: boolean |
||||
|
} |
||||
|
|
||||
|
export const state = (): State => ({ |
||||
|
shopList: [], |
||||
|
selectedModule: '', |
||||
|
language: 'zh', |
||||
|
config: {}, |
||||
|
shop: {}, |
||||
|
currentFloor: {}, |
||||
|
isUseFace: false, |
||||
|
isUseSpeech: false |
||||
|
}) |
||||
@ -0,0 +1,3 @@ |
|||||
|
export const GLOBAL_STORE_ID = 'globalStore' |
||||
|
|
||||
|
export type GlobalType = typeof GLOBAL_STORE_ID |
||||
Loading…
Reference in new issue