globalData.js
1.48 KB
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
import Taro from '@tarojs/taro';
import * as global from '../constants/globalData'
const INITIAL_STATE = {
systemInfo: {},
userInfo: {},
unionInfo: {
userUnionType: '',
userUnionTypeImageUrl: '',
shareId: '',
userNounionTypeImageUrl: ''
},
wxUnionId: '',
WXThirdSession: '',
openId: '',
sessionKey: '',
udid: ''
}
export default function globalData (state = INITIAL_STATE, action) {
switch (action.type) {
case global.USERINFO:
let userInfo = {...state.userInfo, ...action.userInfo};
Taro.setStorage({key:'userInfo', data: userInfo});
return {
...state,
userInfo: userInfo
}
case global.SYSTEMINFO:
return {
...state,
systemInfo: action.systemInfo
}
case global.WXUNIONID:
Taro.setStorage({key: 'unionID', data: action.wxUnionId});
return {
...state,
wxUnionId: action.wxUnionId
}
case global.UNIONINFO:
return {
...state,
unionInfo: action.unionInfo
}
case global.WXTHIRDSESSION:
Taro.setStorage({key: 'WXThird_session', data: action.WXThirdSession});
return {
...state,
WXThirdSession: action.WXThirdSession
}
case global.OPENID:
return {
...state,
openId: action.id
}
case global.SESSIONKEY:
Taro.setStorage({key: 'session_key', data: action.sessionKey});
return {
...state,
sessionKey: action.sessionKey
}
case global.UDID:
Taro.setStorage({key: 'udid', data: action.udid});
return {
...state,
udid: action.udid
}
default:
return state
}
}