34 lines
1015 B
TypeScript
34 lines
1015 B
TypeScript
import { useDispatch } from 'react-redux'
|
|
import { SET_SHOPCOUNT, CLEAR_SHOPCOUNT } from '@/constants/common'
|
|
import { DataParam } from '@/reducers/commonData'
|
|
import { useCallback, useState } from 'react'
|
|
// import { GetShoppingCartApi } from '@/api/shopCart'
|
|
import { useSelector } from '@/reducers/hooks'
|
|
export default () => {
|
|
const commonData = useSelector((state) => state.commonData)
|
|
const dispatch = useDispatch()
|
|
|
|
const setShopCount = (shopCount: number) => {
|
|
dispatch({ type: SET_SHOPCOUNT, data: { shopCount } })
|
|
}
|
|
|
|
const removeShopCount = () => {
|
|
dispatch({ type: CLEAR_SHOPCOUNT })
|
|
}
|
|
|
|
// const { fetchData: fetchDataShopCount } = GetShoppingCartApi()
|
|
const getShopCount = async () => {
|
|
//获取购物车数据数量
|
|
// const { data } = await fetchDataShopCount()
|
|
let color_list = data.color_list || []
|
|
setShopCount(color_list.length)
|
|
}
|
|
|
|
return {
|
|
setShopCount,
|
|
removeShopCount,
|
|
getShopCount,
|
|
commonData,
|
|
}
|
|
}
|