优化商城

This commit is contained in:
2022-07-08 15:30:30 +08:00
parent 3637447ab6
commit 757289558f
18 changed files with 107 additions and 108 deletions
+7 -8
View File
@@ -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
}