|
|
|
@ -6,24 +6,42 @@ export interface CommonStoreState {
|
|
|
|
|
showWarning: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const useCommonStore = defineStore('commonStore', () => {
|
|
|
|
|
const storeMap = ref({})
|
|
|
|
|
const showWarning = ref(true);
|
|
|
|
|
const getStore = (key) => {
|
|
|
|
|
return key === 'showWarning' ? showWarning.value : storeMap.value[key];
|
|
|
|
|
return storeMap.value[key]
|
|
|
|
|
}
|
|
|
|
|
const setStore = (key, value) => {
|
|
|
|
|
if (key === 'showWarning') {
|
|
|
|
|
showWarning.value = value;
|
|
|
|
|
} else {
|
|
|
|
|
storeMap.value[key] = value;
|
|
|
|
|
export const useCommonStore = defineStore(
|
|
|
|
|
'commonStore',
|
|
|
|
|
{
|
|
|
|
|
state: (): CommonStoreState => {
|
|
|
|
|
return {
|
|
|
|
|
storeMap: {},
|
|
|
|
|
showWarning: true
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
actions: {
|
|
|
|
|
setStore(key: String, value: any) {
|
|
|
|
|
if(key == 'showWarning'){
|
|
|
|
|
this.showWarning = value;
|
|
|
|
|
}else{
|
|
|
|
|
this.storeMap[key] = value;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
getStore(key: string){
|
|
|
|
|
if(key == 'showWarning'){
|
|
|
|
|
return this.showWarning;
|
|
|
|
|
}else{
|
|
|
|
|
return this.storeMap[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
persist: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
strategies: [
|
|
|
|
|
{
|
|
|
|
|
key: "commonStore",
|
|
|
|
|
storage: localStorage
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
return storeMap.value[key] = value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {getStore, setStore,showWarning}
|
|
|
|
|
})
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
export const useCommonStateWithOut = () => {
|
|
|
|
|
return useCommonStore(store)
|
|
|
|
|