import {
|
LOGIN_STATUS,
|
UID,
|
PLATFORM
|
} from '../../config/cache';
|
import Cache from '../../utils/cache';
|
import {
|
USER_INFO
|
} from '../../config/cache';
|
import Routine from '@/libs/routine.js';
|
const state = {
|
token: Cache.get(LOGIN_STATUS) || '',
|
backgroundColor: "#fff",
|
userInfo: Cache.get(USER_INFO)?JSON.parse(Cache.get(USER_INFO)):null,
|
uid: Cache.get(UID) || null,
|
homeActive: false,
|
chatUrl: Cache.get('chatUrl') || '',
|
systemPlatform: Cache.get(PLATFORM)?Cache.get(PLATFORM):'',
|
productType: Cache.get('productType') || '',
|
unionId: Cache.get('unionId') || '',
|
careBeanRate:Cache.get('careBeanRate')||'',
|
myCareBean:Cache.get('myCareBean')||0,
|
myParams:Cache.get('myParams')||null,
|
switchParams:Cache.get('switchParams')||'',
|
belong:Cache.get('belong')||null,
|
isBelong:Cache.get('isBelong')||false,
|
isSystemHide:Cache.get('isSystemHide')||false,
|
showPopActivity:Cache.get('showPopActivity')||false,
|
homeExpiring:Cache.get('homeExpiring')||false,
|
excludedByCouponUsage:Cache.get('excludedByCouponUsage')||false
|
};
|
|
const mutations = {
|
UPDATE_showPopActivity(state,data) {
|
state.showPopActivity = data;
|
Cache.set('showPopActivity', data);
|
},
|
UPDATE_isSystemHide(state, data) {
|
state.isSystemHide = data.isSystemHide;
|
Cache.set('isSystemHide', data.isSystemHide);
|
},
|
updateSwitchParams(state, data) {
|
console.log('updateSwitchParams',data.switchParams);
|
state.switchParams = data.switchParams;
|
Cache.set('switchParams', data.switchParams);
|
},
|
UPDATE_CAREBEANRATE(state, data) {
|
state.careBeanRate = data.careBeanRate;
|
Cache.set('careBeanRate', data.careBeanRate);
|
},
|
UPDATE_myCareBean(state, data) {
|
state.myCareBean = data.myCareBean;
|
Cache.set('myCareBean', data.myCareBean);
|
},
|
UPDATE_LOGINSTATUS(state, opt) {
|
if(opt.token){
|
state.token = opt.token;
|
Cache.set(LOGIN_STATUS, opt.token);
|
}
|
if(opt.uid){
|
state.uid = opt.uid;
|
Cache.set(UID,opt.uid);
|
}
|
if(opt.unionId){
|
console.log('设置union',opt.unionId);
|
state.unionId = opt.unionId;
|
Cache.set('unionId',opt.unionId);
|
}
|
console.log(opt);
|
console.log('store update login and unionid');
|
uni.$emit('UPDATE_LOGINSTATUS', opt);
|
},
|
UPDATE_PARAMS(state,opt){
|
state.myParams = opt.myParams;
|
Cache.set('myParams', opt.myParams);
|
},
|
UPDATE_LOGIN(state, token) {
|
state.token = token;
|
},
|
UPDATE_UNIONID(state, unionId) {
|
console.log('store update unionid');
|
state.unionId = unionId;
|
},
|
LOGOUT(state) {
|
state.isBelong = false;
|
Cache.clear('isBelong');
|
console.log('login out')
|
state.token = undefined;
|
Cache.clear(LOGIN_STATUS);
|
state.unionId=undefined;
|
Cache.clear('unionId');
|
state.uid = undefined;
|
Cache.clear(UID);
|
state.userInfo={};
|
Cache.clear(USER_INFO);
|
state.belong=undefined;
|
Cache.clear('belong');
|
},
|
BACKGROUND_COLOR(state, color) {
|
state.color = color;
|
document.body.style.backgroundColor = color;
|
},
|
UPDATE_USERINFO(state, userInfo) {
|
state.userInfo = userInfo;
|
Cache.set(USER_INFO, userInfo);
|
},
|
OPEN_HOME(state) {
|
state.homeActive = true;
|
},
|
CLOSE_HOME(state) {
|
state.homeActive = false;
|
},
|
SET_CHATURL(state, chatUrl){
|
state.chatUrl = chatUrl;
|
},
|
// AuthorizeType(state, authorizeType){
|
// state.authorizeType = authorizeType;
|
// },
|
SYSTEM_PLATFORM(state, systemPlatform){
|
state.systemPlatform = systemPlatform;
|
Cache.set(PLATFORM, systemPlatform);
|
},
|
//更新useInfo数据
|
changInfo(state, payload) {
|
state.userInfo[payload.amount1] = payload.amount2;
|
Cache.set(USER_INFO, state.userInfo);
|
},
|
//商品类型,用于区分视频号商品与一般商品
|
PRODUCT_TYPE(state, productType) {
|
state.productType = productType;
|
Cache.set('productType', productType);
|
},
|
CLEAR_BELONG(state){
|
state.isBelong=false;
|
Cache.set('isBelong', '');
|
state.belong='';
|
Cache.set('belong', '');
|
},
|
UPDATE_BELONG(state,belong){
|
state.isBelong=true;
|
Cache.set('isBelong', 'true');
|
state.belong=belong;
|
Cache.set('belong', belong);
|
},
|
UPDATE_homeExpiring(state,expiring){
|
state.homeExpiring=expiring
|
Cache.set('homeExpiring', expiring);
|
},
|
UPDATE_excludedByCouponUsage(state,expiring){
|
state.excludedByCouponUsage=expiring
|
Cache.set('excludedByCouponUsage', expiring);
|
}
|
};
|
|
const actions = {
|
USERINFO({
|
state,
|
commit
|
}, force) {
|
return new Promise((resolve, reject) => {
|
Routine.getLastUserInfo().then(res => {
|
resolve(res.data);
|
});
|
}).catch(e => {
|
reject(e)
|
});
|
}
|
};
|
|
export default {
|
state,
|
mutations,
|
actions
|
};
|