globalData.js 1.48 KB
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
	}
}