优化商城
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
import Taro from '@tarojs/taro'
|
||||
import {
|
||||
SET_SHOPCOUNT,
|
||||
CLEAR_SHOPCOUNT
|
||||
CLEAR_SHOPCOUNT,
|
||||
STORAGE_SHOPCOUNT
|
||||
} from '../constants/common'
|
||||
|
||||
export type DataParam = {
|
||||
shopCount: number
|
||||
shopCount: number //购物车数量
|
||||
}
|
||||
|
||||
type Action = {
|
||||
@@ -14,21 +15,19 @@ type Action = {
|
||||
data?: DataParam
|
||||
}
|
||||
|
||||
|
||||
|
||||
const INIT = {
|
||||
shopCount: Taro.getStorageSync('shopCount')?JSON.parse(Taro.getStorageSync('shopCount')):null,
|
||||
shopCount: Taro.getStorageSync(STORAGE_SHOPCOUNT)?JSON.parse(Taro.getStorageSync(STORAGE_SHOPCOUNT)).shopCount:0,
|
||||
}
|
||||
|
||||
export default function counter (state = INIT, action: Action) {
|
||||
const {type, data} = action
|
||||
switch (type) {
|
||||
case SET_SHOPCOUNT:
|
||||
Taro.setStorageSync('shopCount',JSON.stringify(data))
|
||||
Taro.setStorageSync(STORAGE_SHOPCOUNT,JSON.stringify(data?.shopCount))
|
||||
return {...state,...data}
|
||||
case CLEAR_SHOPCOUNT:
|
||||
Taro.removeStorageSync('shopCount')
|
||||
return {...state, shopCount: null}
|
||||
Taro.removeStorageSync(STORAGE_SHOPCOUNT)
|
||||
return {...state, shopCount: 0}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user