You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
shop-app/common/store/index.js

58 lines
1.2 KiB

/*
* @Author: ch
* @Date: 2022-03-22 18:28:52
* @LastEditors: ch
* @LastEditTime: 2022-05-21 11:38:51
* @Description: file content
*/
import Vue from 'vue'
import Vuex from 'vuex';
Vue.use(Vuex);
const
// token
TOKEN = 'tk',
// 用户信息
USER_INFO = 'ui',
// 地址列表
ADDRESS = 'ads',
// oppenId
OPPED_ID = 'oi';
export default new Vuex.Store({
state : {
token : uni.getStorageSync(TOKEN) || '',
userInfo : JSON.parse(uni.getStorageSync(USER_INFO) || '{}'),
address : JSON.parse(uni.getStorageSync(ADDRESS) || '[]'),
imData : [],
imMsgCount : 0,
openId : uni.getStorageSync(OPPED_ID) || ''
},
mutations:{
SET_TOKEN (state, token = ''){
state.token = token;
uni.setStorageSync(TOKEN, token);
},
SET_USER_INFO (state, userInfo = {}){
state.userInfo = userInfo;
uni.setStorageSync(USER_INFO, JSON.stringify(userInfo));
},
SET_ADDRESS (state, address = []){
state.address = address;
uni.setStorageSync(ADDRESS, JSON.stringify(address));
},
SET_IM_DATA (state, data){
state.imData = data ;
},
SET_IM_MSG_COUNT (state, data){
state.imMsgCount = data;
},
SET_OPEN_ID (state, data){
state.openId = data;
uni.setStorageSync(OPPED_ID, data);
}
},
actions : {
}
})