cultivationApp/store/index.js

44 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-11-27 18:23:17 +08:00
import {
2024-01-31 11:16:49 +08:00
createStore
2023-11-27 18:23:17 +08:00
} from 'vuex'
const store = createStore({
2024-01-31 11:16:49 +08:00
state: {
userInfo: uni.getStorageSync("SY_USER") || null,
farm: JSON.parse(uni.getStorageSync("farm") || "{}"),
house: JSON.parse(uni.getStorageSync("house") || "{}"),
tabbrIndex: 0,
},
2023-11-27 18:23:17 +08:00
2024-01-31 11:16:49 +08:00
mutations: {
saveUserInfo(state, info) {
state.userInfo = info
uni.setStorageSync("SY_USER", info)
},
setFarm(state, data) {
2024-01-26 17:29:25 +08:00
state.farm = data;
uni.setStorageSync('farm', JSON.stringify(data));
},
2024-01-31 11:16:49 +08:00
setHouse(state, data) {
2024-01-26 17:29:25 +08:00
state.house = data;
uni.setStorageSync('house', JSON.stringify(data));
2024-01-31 11:16:49 +08:00
},
changeTabbar(state, index) {
state.tabbrIndex = +index
},
},
actions: {
saveUserInfo({ commit }, info) {
commit('saveUserInfo', info);
},
setFarm({ commit }, info) {
2024-01-26 17:29:25 +08:00
commit('setFarm', info)
},
2024-01-31 11:16:49 +08:00
setHouse({ commit }, info) {
2024-01-26 17:29:25 +08:00
commit('setHouse', info)
2024-01-31 11:16:49 +08:00
},
changeTabbar({ commit }, info) {
commit('changeTabbar', info)
},
}
2023-11-27 18:23:17 +08:00
})
export default store