对接完添加购物车
This commit is contained in:
+47
-23
@@ -2,11 +2,13 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import {
|
||||
SET_USERINFO,
|
||||
SET_ADMINUSERINFO,
|
||||
SET_TOKEN,
|
||||
SET_SESSIONKEY,
|
||||
CLEAR_TOKEN,
|
||||
CLEAR_USERINFO,
|
||||
CLEAR_SESSIONKEY
|
||||
CLEAR_SESSIONKEY,
|
||||
CLEAR_ADMINUSERINFO,
|
||||
} from '../constants/userInfo'
|
||||
|
||||
export type UserParam = {
|
||||
@@ -18,13 +20,28 @@ export type UserParam = {
|
||||
province?: string,
|
||||
gender?: number,
|
||||
language?: string,
|
||||
timestamp?: number
|
||||
timestamp?: number,
|
||||
physical_warehouse?: number,
|
||||
physical_warehouse_name?: string,
|
||||
}
|
||||
|
||||
export type UserAdminParam = {
|
||||
avatar_url?: string,
|
||||
open_id?: string,
|
||||
physical_warehouse?: number,
|
||||
physical_warehouse_name?: string,
|
||||
union_id?: string,
|
||||
user_code?: string,
|
||||
user_id?: number,
|
||||
user_name?: string,
|
||||
wechat_user_open_id?: number
|
||||
}
|
||||
|
||||
export type DataParam = {
|
||||
token?: string
|
||||
session_key?: string,
|
||||
userInfo: UserParam
|
||||
userInfo: UserParam,
|
||||
adminUserInfo: UserAdminParam
|
||||
}
|
||||
|
||||
type Action = {
|
||||
@@ -36,6 +53,7 @@ type Action = {
|
||||
|
||||
const INIT_USER = {
|
||||
userInfo: Taro.getStorageSync('userInfo')?JSON.parse(Taro.getStorageSync('userInfo')):null,
|
||||
adminUserInfo: Taro.getStorageSync('adminUserInfo')?JSON.parse(Taro.getStorageSync('adminUserInfo')):null,
|
||||
token: Taro.getStorageSync('token')||'',
|
||||
session_key: Taro.getStorageSync('session_key')||'',
|
||||
}
|
||||
@@ -43,25 +61,31 @@ const INIT_USER = {
|
||||
export default function counter (state = INIT_USER, action: Action) {
|
||||
const {type, data} = action
|
||||
switch (type) {
|
||||
case SET_USERINFO:
|
||||
Taro.setStorageSync('userInfo',JSON.stringify(data?.userInfo))
|
||||
return {...state,...data}
|
||||
case SET_TOKEN:
|
||||
Taro.setStorageSync('token',data?.token)
|
||||
return {...state,...data}
|
||||
case SET_SESSIONKEY:
|
||||
Taro.setStorageSync('session_key',data?.session_key)
|
||||
return {...state,...data}
|
||||
case CLEAR_TOKEN:
|
||||
Taro.removeStorageSync('token')
|
||||
return {...state, token:''}
|
||||
case CLEAR_SESSIONKEY:
|
||||
Taro.removeStorageSync('session_key')
|
||||
return {...state, session_key:''}
|
||||
case CLEAR_USERINFO:
|
||||
Taro.removeStorageSync('userInfo')
|
||||
return {...state, userInfo: null}
|
||||
default:
|
||||
return state
|
||||
case SET_USERINFO:
|
||||
Taro.setStorageSync('userInfo',JSON.stringify(data?.userInfo))
|
||||
return {...state,...data}
|
||||
case SET_ADMINUSERINFO:
|
||||
Taro.setStorageSync('adminUserInfo',JSON.stringify(data?.adminUserInfo))
|
||||
return {...state,...data}
|
||||
case SET_TOKEN:
|
||||
Taro.setStorageSync('token',data?.token)
|
||||
return {...state,...data}
|
||||
case SET_SESSIONKEY:
|
||||
Taro.setStorageSync('session_key',data?.session_key)
|
||||
return {...state,...data}
|
||||
case CLEAR_TOKEN:
|
||||
Taro.removeStorageSync('token')
|
||||
return {...state, token:''}
|
||||
case CLEAR_SESSIONKEY:
|
||||
Taro.removeStorageSync('session_key')
|
||||
return {...state, session_key:''}
|
||||
case CLEAR_USERINFO:
|
||||
Taro.removeStorageSync('userInfo')
|
||||
return {...state, userInfo: null}
|
||||
case CLEAR_ADMINUSERINFO:
|
||||
Taro.removeStorageSync('adminUserInfo')
|
||||
return {...state, adminUserInfo: null}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user