123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- let lifeData = {};
- try {
-
- lifeData = uni.getStorageSync('lifeData');
- } catch (e) {}
- let saveStateKeys = ['userInfo', 'goods',
- 'isHaveService'
- ];
- const saveLifeData = function(key, value) {
-
- if (saveStateKeys.indexOf(key) != -1) {
-
- let tmp = uni.getStorageSync('lifeData');
-
- tmp = tmp ? tmp : {};
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- tmp[key] = value;
-
- uni.setStorageSync('lifeData', tmp);
- }
- }
- const store = new Vuex.Store({
- modules: {},
- state: {
- sysinfo: uni.getSystemInfoSync(),
- hasLogin: false,
- isHaveService: false,
- goods: []
- },
- mutations: {
- $uStore(state, payload) {
-
- let nameArr = payload.name.split('.');
- let saveKey = '';
- let len = nameArr.length;
- if (nameArr.length >= 2) {
- let obj = state[nameArr[0]];
- for (let i = 1; i < len - 1; i++) {
- obj = obj[nameArr[i]];
- }
- obj[nameArr[len - 1]] = payload.value;
- saveKey = nameArr[0];
- } else {
-
- state[payload.name] = payload.value;
- saveKey = payload.name;
- }
-
- saveLifeData(saveKey, state[saveKey])
- },
- login(state, provider) {
- state.hasLogin = true;
- state.userInfo = provider;
- uni.setStorageSync('userInfo', provider)
- },
- logout(state) {
- state.hasLogin = false;
- state.userInfo = {};
- uni.removeStorageSync('userInfo')
- },
- goodCar(state, provider) {
-
- state.goods = provider;
- uni.setStorageSync('goods', provider)
- },
- goodService(state, provider) {
- state.isHaveService = provider;
- uni.setStorageSync('isHaveService', provider)
- },
- },
- actions: {
- },
- getters: {
- getUserInfo(state) {
- return state.userInfo
- }
- }
- })
- export default store
|