2025-04-29 08:37:17 +00:00
|
|
|
|
import { createPinia, defineStore } from 'pinia'
|
|
|
|
|
import { createPersistedState } from 'pinia-plugin-persistedstate' // 数据持久化
|
2025-05-09 01:42:19 +00:00
|
|
|
|
|
2025-04-29 08:37:17 +00:00
|
|
|
|
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=灰化
|
2025-05-09 01:42:19 +00:00
|
|
|
|
position: null, //市
|
|
|
|
|
location: null, //省市区
|
|
|
|
|
temperature: null, //温度
|
|
|
|
|
weather: null //天气
|
2025-04-29 08:37:17 +00:00
|
|
|
|
}),
|
|
|
|
|
actions: {
|
|
|
|
|
setIsGray(value : 0 | 1) {
|
|
|
|
|
this.isGray = value
|
|
|
|
|
},
|
2025-05-09 01:42:19 +00:00
|
|
|
|
setPosition(value : string) {
|
|
|
|
|
this.position = value
|
|
|
|
|
},
|
|
|
|
|
setLocation(value : string) {
|
|
|
|
|
this.location = value
|
|
|
|
|
},
|
|
|
|
|
setTemperature(value : number) {
|
|
|
|
|
this.temperature = value
|
|
|
|
|
},
|
|
|
|
|
setWeather(value : string) {
|
|
|
|
|
this.weather = value
|
|
|
|
|
},
|
2025-04-29 08:37:17 +00:00
|
|
|
|
},
|
|
|
|
|
persist: true, // 启用持久化
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default store
|
|
|
|
|
|
|
|
|
|
// 模块统一导出
|
|
|
|
|
export * from './user'
|