jeecgBootUniapp/src/store/index.ts
2025-06-16 16:17:33 +08:00

44 lines
943 B
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createPinia, defineStore } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
const store = createPinia()
store.use(
createPersistedState({
storage: {
getItem: uni.getStorageSync,
setItem: uni.setStorageSync,
},
}),
)
export const useAppStore = defineStore('app', {
state: () => ({
isGray: 0 as 0 | 1, // 0=正常1=灰化
position: null, //市
location: null, //省市区
temperature: null, //温度
weather: null //天气
}),
actions: {
setIsGray(value : 0 | 1) {
this.isGray = value
},
setPosition(value : string) {
this.position = value
},
setLocation(value : string) {
this.location = value
},
setTemperature(value : number) {
this.temperature = value
},
setWeather(value : string) {
this.weather = value
},
},
persist: true, // 启用持久化
})
export default store
// 模块统一导出
export * from './user'