// #ifndef VUE3 import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) let { config } = require('../common/util.js'); const store = new Vuex.Store({ // #endif // #ifdef VUE3 import { createStore } from 'vuex' const store = createStore({ // #endif state: { hasLogin: false, isUniverifyLogin: false, loginProvider: "", openid: null, testvuex: false, colorIndex: 0, colorList: ['#FF0000', '#00FF00', '#0000FF'], noMatchLeftWindow: true, active: 'componentPage', leftWinActive: '/pages/component/view/view', activeOpen: '', menu: [], univerifyErrorMsg: '', userInfo: {}, shop: false, geoinfo: {}, redirctCurCate: '' }, mutations: { login(state, data) { state.hasLogin = true; state.signature = data.signature; state.vid = data.vid; state.uid = data.uid; }, setUserInfo(state, userInfo) { state.userInfo = userInfo }, setShop(state, shop) { state.shop = shop.id ? shop : null; }, logout(state) { state.hasLogin = false state.openid = null }, setRedirctCurCate(state, curCate) { state.redirctCurCate = curCate } }, getters: { currentColor(state) { return state.colorList[state.colorIndex] } }, actions: { getUser: async function({ commit, state }) { return await new Promise((resolve, reject) => { if (state.userInfo && state.userInfo.nickName) { resolve(state.userInfo) } else { let baseToken = {}; try { baseToken = uni.getStorageSync('baseToken') } catch(e) { console.error(e) } if(!baseToken.t) { return; } commit('setUserInfo', { ...baseToken }) } }) }, } }) export default store