优化商城

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 -11
View File
@@ -4,12 +4,17 @@ import { ReactElement, useEffect, useRef, useState } from "react"
import classnames from "classnames";
import styles from './index.module.scss'
import { GetShoppingCartApi } from "@/api/shopCart";
import useCommonData from "@/use/useCommonData";
import { useSelector } from "@/reducers/hooks";
type param = {
children?: ReactElement|null,
onClick?: () => void
}
export default ({children = null, onClick}:param) => {
//获取购物车数据数量
const {getShopCount, commonData} = useCommonData()
const [screenHeight, setScreenHeight] = useState(0)
const [showMoveBtn, setShowMoveBtn] = useState(false)
const screenWidthRef = useRef(0)
@@ -23,17 +28,8 @@ export default ({children = null, onClick}:param) => {
setShowMoveBtn(true)
})
//获取数据
const [list, setList] = useState<any[]>([])
const {fetchData} = GetShoppingCartApi()
const getShoppingCart = async () => {
const {data} = await fetchData()
let color_list = data.color_list||[]
setList(color_list)
}
useEffect(() => {
getShoppingCart()
getShopCount()
}, [])
const dragEnd = (e) => {
@@ -45,7 +41,7 @@ export default ({children = null, onClick}:param) => {
{children}
{showMoveBtn&&<MovableView onClick={onClick} className={styles.moveBtn} direction="all" inertia={true} x="630rpx" y={screenHeight+'rpx'} onTouchEnd={(e) => dragEnd(e)}>
<View className={classnames('iconfont','icon-gouwuche', styles.shop_icon) } ></View>
{(list.length > 0)&&<View className={styles.product_num}>{list.length > 99?'99+':list.length}</View>}
{(commonData.shopCount > 0)&&<View className={styles.product_num}>{commonData.shopCount > 99?'99+':commonData.shopCount}</View>}
</MovableView>}
</MovableArea>
)