Jacob
4 天以前 bf50dc43351d1a9781a84faf775913e813ea6ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
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
};