Commit 3b4a134a authored by 王能飞's avatar 王能飞

Merge branch 'c_client_taro-pack' into 'c_client_taro'

C client taro pack

See merge request !54
parents 1cc32d85 8132299c
...@@ -19,7 +19,8 @@ function GoodsList(props) { ...@@ -19,7 +19,8 @@ function GoodsList(props) {
color: '#181818' color: '#181818'
}, },
onOpenDetail, onOpenDetail,
onCompleteTask onCompleteTask,
onScrollToLower=()=>{}
} = props } = props
const goToGoodsDetail = async(item) => { const goToGoodsDetail = async(item) => {
...@@ -43,7 +44,7 @@ function GoodsList(props) { ...@@ -43,7 +44,7 @@ function GoodsList(props) {
}) })
} }
return ( return (
<ScrollView scrollY className={styles['container__scroll']}> <ScrollView scrollY onScrollToLower={onScrollToLower} className={styles['container__scroll']}>
<View className={styles['container__content-list']}> <View className={styles['container__content-list']}>
{ {
goodsList.map((item, i) => { goodsList.map((item, i) => {
......
export default { export default {
env: 'test', // 云函数环境 test 测试环境 online 线上环境 env: 'test', // 云函数环境 test 测试环境 online 线上环境
requestType: 'cloud', // cloud: 云函数, yapi: yapi 接口, ams: ams接口,tornadoAPI: 风驰台接口 requestType: 'cloud', // cloud: 云函数, yapi: yapi 接口, ams: ams接口,tornadoAPI: 风驰台接口
cloudName: 'testNewS', // 主云函数项目名 CommonToC cloudName: 'HipPopGame', // 主云函数项目名 CommonToC
sellerId: '2401530034', sellerId: '4004811045',
tornadoAPI: 'https://tornado.duibadev.com.cn/tbServer/api?db=db3000000038851072&proxyIp=172.16.130.158', // 新增:当requestType: 'tornadoAPI'时,找服务端提供地址 tornadoAPI: 'https://tornado.duibadev.com.cn/tbServer/api?db=db3000000038851072&proxyIp=172.16.130.158', // 新增:当requestType: 'tornadoAPI'时,找服务端提供地址
defaultActivityId: '610cff3f086e659a96b7336c' // 默认活动id defaultActivityId: '617629e4e5c0d73da5bb50db' // 默认活动id
} }
\ No newline at end of file
import {useState, useEffect, useRef} from 'react'
import API from '@/api'
import {goodsListInfoModel} from '@/store'
import { useThrottle } from './useThrottle';
const pageSize = 8;
export const useGoods = (props) => {
const {key, itemIds} = props;
const itemIdsArray = useRef(itemIds.split(','));
// 当前索引值
const itemIndex = useRef(0)
const {listStorage, setListStorage} = goodsListInfoModel();
const [goodsList, setGoodsList] = useState([]);
useEffect(()=>{
// 小于分页 请求商品数
if(itemIdsArray.current.length < pageSize){
getGoodsList(itemIds)
return
}
// 存储当前标识
itemIndex.current = pageSize;
// 多于分页请求商品数量
getGoodsList(itemIdsArray.current.slice(0, pageSize).join(','))
},[])
// 商品列表请求
const getGoodsList = async (itemIds,isReset = false) => {
// 判断是否存在listStorage[key]
if(listStorage?.[key] && listStorage?.[key]?.length > goodsList.length){
setGoodsList(listStorage?.[key]);
return;
}
const { data } = await API.getCollectGoods({ key, itemIds })
if(data?.list){
const list = isReset ? [...data?.list] : [...goodsList, ...data?.list];
// 缓存当前key对应的goodslist
setListStorage({
...listStorage,
[key]:list
})
setGoodsList(list || [])
}
}
// 下一页 商品列表请求
const scrollToNextList = useThrottle(()=>{
console.log(itemIdsArray.current.length , pageSize,itemIndex.current, itemIdsArray.current.length);
// 没有第二页
if(itemIdsArray.current.length < pageSize || itemIndex.current == itemIdsArray.current.length) return
let curretnIndex = 0;
// 第二页是不是最后一页
if(itemIndex.current + pageSize > itemIdsArray.current.length) {
curretnIndex = itemIdsArray.current.length;
} else {
// 第二页满数量
curretnIndex = itemIndex.current + pageSize;
}
// 请求接口
getGoodsList(itemIdsArray.current.slice(itemIndex.current, curretnIndex).join(','));
// 索引值更新
itemIndex.current = curretnIndex;
})
const updateGoodsList = async () => {
if(itemIdsArray.current.length <= pageSize) {
await getGoodsList(itemIds,true)
return;
}
// 当前页面的索引值
const preInx = (Math.ceil(itemIndex.current / pageSize) - 1) * pageSize
// 当前页面的所有itemId
const _itemIds = itemIdStr.current.slice(preInx, itemIdInx.current).join(',')
// 更新当前商品的状态
const goodRes = await getCollectGoods({ key, itemIds: _itemIds })
const newGoodsList = [...(goodList.slice(0,preInx)),...(goodRes?.data?.list || [])]
setListStorage({
...listStorage,
[key]:newGoodsList
})
setGoodList(newGoodsList)
}
// 完成任务
const completeTask = useThrottle( async (callbackFn=()=>{}) => {
const res = await API.completeTask({ key, itemId})
if(res?.success){
updateGoodsList();
callbackFn && callbackFn();
}
})
return {
goodsList,
scrollToNextList,
completeTask,
}
}
\ No newline at end of file
...@@ -46,6 +46,9 @@ export function useTasks(props) { ...@@ -46,6 +46,9 @@ export function useTasks(props) {
const fetchTaskList = async () => { const fetchTaskList = async () => {
const isVip = await checkIsMember() const isVip = await checkIsMember()
const { success, data } = await API.getTaskList({ isVip }) const { success, data } = await API.getTaskList({ isVip })
console.log('fetchTaskList', success, data);
if(success && data) { if(success && data) {
const { list = [] } = data const { list = [] } = data
const _list = list.map(itm => { const _list = list.map(itm => {
......
...@@ -11,6 +11,9 @@ import { TASK_CONFIG, BROSE_GOOD_TYPE } from '@/config/task.config' ...@@ -11,6 +11,9 @@ import { TASK_CONFIG, BROSE_GOOD_TYPE } from '@/config/task.config'
import { BROWSE_CONFIG } from '@/config/browse.config' import { BROWSE_CONFIG } from '@/config/browse.config'
import { GOOD_LIST } from '@/mock' import { GOOD_LIST } from '@/mock'
import {useGoods} from '@/hooks/useGoods'
function BrowseGoodsPage() { function BrowseGoodsPage() {
const { params: { itemIds, keepTime } } = useRouter() const { params: { itemIds, keepTime } } = useRouter()
const { browseType, browseTime = 15 } = TASK_CONFIG const { browseType, browseTime = 15 } = TASK_CONFIG
...@@ -22,11 +25,14 @@ function BrowseGoodsPage() { ...@@ -22,11 +25,14 @@ function BrowseGoodsPage() {
const [accumulateTime, setAccumulateTime] = useState(+keepTime || 15) const [accumulateTime, setAccumulateTime] = useState(+keepTime || 15)
const browserTimer = useRef(null) const browserTimer = useRef(null)
const [goodsList, setGoodsList] = useState(BROWSE_CONFIG.isMock?GOOD_LIST:[]) // const [goodsList, setGoodsList] = useState(BROWSE_CONFIG.isMock?GOOD_LIST:[])
useEffect(() => { const {goodsList, scrollToNextList, completeTask} = useGoods({key:BROWSE_CONFIG.taskType,itemIds})
getGoodsList()
}, [])
// useEffect(() => {
// getGoodsList()
// }, [])
// 浏览集合页15s // 浏览集合页15s
useEffect(() => { useEffect(() => {
if(browseType === BROSE_GOOD_TYPE.PAGE) { if(browseType === BROSE_GOOD_TYPE.PAGE) {
...@@ -66,13 +72,20 @@ function BrowseGoodsPage() { ...@@ -66,13 +72,20 @@ function BrowseGoodsPage() {
} }
}) })
// 浏览记录 // 浏览记录
const onCompleteTask = async(itemId) => { // const onCompleteTask = async(itemId) => {
const { success } = await API.completeTask({ key: BROWSE_CONFIG.taskType, itemId: currentItemId.current, taskType: BROWSE_CONFIG.taskType }) // const { success } = await API.completeTask({ key: BROWSE_CONFIG.taskType, itemId: currentItemId.current, taskType: BROWSE_CONFIG.taskType })
if (success) { // if (success) {
getGoodsList() // getGoodsList()
// showToast({ title: '浏览成功'})
// }
// }
const onCompleteTask = () => {
completeTask(()=>{
showToast({ title: '浏览成功'}) showToast({ title: '浏览成功'})
})
} }
}
// 点击商品 跳转时处理 // 点击商品 跳转时处理
const onOpenDetail = (itemId, collected) => { const onOpenDetail = (itemId, collected) => {
const handleFn = { const handleFn = {
...@@ -118,7 +131,7 @@ function BrowseGoodsPage() { ...@@ -118,7 +131,7 @@ function BrowseGoodsPage() {
<GoodsTitle config={BROWSE_CONFIG.head} position={'bottom'} /> <GoodsTitle config={BROWSE_CONFIG.head} position={'bottom'} />
</View> </View>
<View className={styles['page-content__list']}> <View className={styles['page-content__list']}>
<GoodsList goodsList={goodsList} task={BROWSE_CONFIG} onOpenDetail={(itemId,collected) => onOpenDetail(itemId,collected)} /> <GoodsList onScrollToLower={scrollToNextList} goodsList={goodsList} task={BROWSE_CONFIG} onOpenDetail={(itemId,collected) => onOpenDetail(itemId,collected)} />
</View> </View>
{ {
BROWSE_CONFIG.countDown && BROWSE_CONFIG.countDown &&
......
...@@ -12,24 +12,29 @@ import { CART_CONFIG, CART_TYPE } from '@/config/cart.config' ...@@ -12,24 +12,29 @@ import { CART_CONFIG, CART_TYPE } from '@/config/cart.config'
import { TASK_RATE_TYPE } from '@/config/task.config' import { TASK_RATE_TYPE } from '@/config/task.config'
import { GOOD_LIST } from '@/mock' import { GOOD_LIST } from '@/mock'
import {useGoods} from '@/hooks/useGoods'
const { showSkuModal } = tbccTs.tb const { showSkuModal } = tbccTs.tb
function CartGoodsPage() { function CartGoodsPage() {
const router = useRouter() const router = useRouter()
const [goodsList, setGoodsList] = useState(GOOD_LIST) // const [goodsList, setGoodsList] = useState(GOOD_LIST)
const { item } = router?.params const { item } = router?.params
const { itemIds, todayCompleteTimes, rateType, times, completeTimes = 0 } = JSON.parse(item) const { itemIds, todayCompleteTimes, rateType, times, completeTimes = 0 } = JSON.parse(item)
// 加购状态 // 加购状态
const initCompleteTimes = rateType === TASK_RATE_TYPE.EVERYDAY? +(todayCompleteTimes || completeTimes) : +completeTimes const initCompleteTimes = rateType === TASK_RATE_TYPE.EVERYDAY? +(todayCompleteTimes || completeTimes) : +completeTimes
const collectFlag = useRef(initCompleteTimes) const collectFlag = useRef(initCompleteTimes)
useEffect(() => {
getGoodsList()
}, [])
const getGoodsList = async () => { // useEffect(() => {
const { data } = await API.getCollectGoods({ key: CART_CONFIG.taskType, taskType: CART_CONFIG.taskType, itemIds }) // getGoodsList()
data?.list && setGoodsList(data?.list || []) // }, [])
}
const {goodsList, scrollToNextList, completeTask} = useGoods({key:CART_CONFIG.taskType,itemIds})
// const getGoodsList = async () => {
// const { data } = await API.getCollectGoods({ key: CART_CONFIG.taskType, taskType: CART_CONFIG.taskType, itemIds })
// data?.list && setGoodsList(data?.list || [])
// }
// 加入购物车 // 对应itemId为 574141925233 skuId为4018047819826 数量为4 // 加入购物车 // 对应itemId为 574141925233 skuId为4018047819826 数量为4
const onCompleteTask = useThrottle(async (itemId, collected) => { const onCompleteTask = useThrottle(async (itemId, collected) => {
if (collected && CART_CONFIG.type === CART_TYPE.ONE) { if (collected && CART_CONFIG.type === CART_TYPE.ONE) {
...@@ -42,12 +47,16 @@ function CartGoodsPage() { ...@@ -42,12 +47,16 @@ function CartGoodsPage() {
} }
const { status, quantity } = await showSkuModal(String(itemId)) const { status, quantity } = await showSkuModal(String(itemId))
if (status == "addCartSuccess") { if (status == "addCartSuccess") {
const { success } = await API.completeTask({ key: CART_CONFIG.taskType, taskType: CART_CONFIG.taskType, itemId, count: quantity }) // const { success } = await API.completeTask({ key: CART_CONFIG.taskType, taskType: CART_CONFIG.taskType, itemId, count: quantity })
if (success) { // if (success) {
// collectFlag.current += 1
// getGoodsList()
// }
completeTask(()=>{
collectFlag.current += 1 collectFlag.current += 1
getGoodsList() })
// showToast({ title: '加购成功'})
}
} }
}, 2000); }, 2000);
...@@ -57,7 +66,7 @@ function CartGoodsPage() { ...@@ -57,7 +66,7 @@ function CartGoodsPage() {
<TitleImg config={CART_CONFIG.head} position={'bottom'} /> <TitleImg config={CART_CONFIG.head} position={'bottom'} />
</View> </View>
<View className={styles['page-content__list']}> <View className={styles['page-content__list']}>
<GoodsList goodsList={goodsList} task={CART_CONFIG} onCompleteTask={(itemId,collected) => onCompleteTask(itemId,collected)} /> <GoodsList onScrollToLower={scrollToNextList} goodsList={goodsList} task={CART_CONFIG} onCompleteTask={(itemId,collected) => onCompleteTask(itemId,collected)} />
</View> </View>
</ContainerFit> </ContainerFit>
) )
......
...@@ -13,32 +13,42 @@ import COLLECT_CONFIG from '@/config/collect.config' ...@@ -13,32 +13,42 @@ import COLLECT_CONFIG from '@/config/collect.config'
import { TASK_RATE_TYPE } from '@/config/task.config' import { TASK_RATE_TYPE } from '@/config/task.config'
import { GOOD_LIST } from '@/mock' import { GOOD_LIST } from '@/mock'
import {useGoods} from '@/hooks/useGoods'
function CollectGoodsPage() { function CollectGoodsPage() {
const router = useRouter() const router = useRouter()
const [goodsList, setGoodsList] = useState([])
const { item } = router?.params const { item } = router?.params
const { itemIds, todayCompleteTimes = 0, rateType, times, completeTimes = 0 } = JSON.parse(item) const { itemIds, todayCompleteTimes = 0, rateType, times, completeTimes = 0 } = JSON.parse(item)
// 加购状态 // 加购状态
const initCompleteTimes = rateType === TASK_RATE_TYPE.EVERYDAY? +(todayCompleteTimes || completeTimes) : +completeTimes const initCompleteTimes = rateType === TASK_RATE_TYPE.EVERYDAY? +(todayCompleteTimes || completeTimes) : +completeTimes
const collectFlag = useRef(initCompleteTimes) const collectFlag = useRef(initCompleteTimes)
useEffect(() => { const {goodsList, scrollToNextList, completeTask} = useGoods({key:COLLECT_CONFIG.taskType,itemIds})
getGoodsList()
}, []) // const [goodsList, setGoodsList] = useState([])
const getGoodsList = async () => { // useEffect(() => {
const { data } = await API.getCollectGoods({ key: COLLECT_CONFIG.taskType, itemIds, taskType: COLLECT_CONFIG.taskType }) // getGoodsList()
data?.list && setGoodsList(data?.list || []) // }, [])
} // const getGoodsList = async () => {
// const { data } = await API.getCollectGoods({ key: COLLECT_CONFIG.taskType, itemIds, taskType: COLLECT_CONFIG.taskType })
// data?.list && setGoodsList(data?.list || [])
// }
const onCompleteTask = useThrottle(async(itemId,collected) => { const onCompleteTask = useThrottle(async(itemId,collected) => {
const collectFn = async () => { // const collectFn = async () => {
const { success } = await API.completeTask({ key: COLLECT_CONFIG.taskType, itemId, taskType: COLLECT_CONFIG.taskType }) // const { success } = await API.completeTask({ key: COLLECT_CONFIG.taskType, itemId, taskType: COLLECT_CONFIG.taskType })
if (success) { // if (success) {
// collectFlag.current += 1
// getGoodsList()
// showToast({ title: '收藏成功'})
// }
// }
const collectFn = completeTask(()=>{
collectFlag.current += 1 collectFlag.current += 1
getGoodsList()
showToast({ title: '收藏成功'}) showToast({ title: '收藏成功'})
} })
}
// 今日是否已收藏过 // 今日是否已收藏过
if(rateType !== TASK_RATE_TYPE.FOREVER && collectFlag.current >= times) { if(rateType !== TASK_RATE_TYPE.FOREVER && collectFlag.current >= times) {
showToast({title: '任务已完成,请明日再来'}) showToast({title: '任务已完成,请明日再来'})
...@@ -67,7 +77,7 @@ function CollectGoodsPage() { ...@@ -67,7 +77,7 @@ function CollectGoodsPage() {
<TitleImg config={COLLECT_CONFIG.head} position={'bottom'} /> <TitleImg config={COLLECT_CONFIG.head} position={'bottom'} />
</View> </View>
<View className={styles['page-content__list']}> <View className={styles['page-content__list']}>
<GoodsList goodsList={goodsList} task={COLLECT_CONFIG} onCompleteTask={(itemId,collected) => onCompleteTask(itemId,collected)} /> <GoodsList onScrollToLower={scrollToNextList} goodsList={goodsList} task={COLLECT_CONFIG} onCompleteTask={(itemId,collected) => onCompleteTask(itemId,collected)} />
</View> </View>
</ContainerFit> </ContainerFit>
) )
......
...@@ -9,10 +9,14 @@ import API from '@/api' ...@@ -9,10 +9,14 @@ import API from '@/api'
import styles from './orderGoods.module.less' import styles from './orderGoods.module.less'
import ORDER_CONFIG from '@/config/order.config' import ORDER_CONFIG from '@/config/order.config'
import {useGoods} from '@/hooks/useGoods'
function OrderGoodsPage() { function OrderGoodsPage() {
const router = useRouter() const router = useRouter()
const { itemIds } = router?.params const { itemIds } = router?.params
const { data } = useRequest(API.getCollectGoods, { key: ORDER_CONFIG.taskType, itemIds, taskType: ORDER_CONFIG.taskType }) // const { data } = useRequest(API.getCollectGoods, { key: ORDER_CONFIG.taskType, itemIds, taskType: ORDER_CONFIG.taskType })
const {goodsList, scrollToNextList} = useGoods({key:ORDER_CONFIG.taskType,itemIds})
return ( return (
<ContainerFit bg={ORDER_CONFIG.bg} fullScreenFit> <ContainerFit bg={ORDER_CONFIG.bg} fullScreenFit>
...@@ -20,7 +24,8 @@ function OrderGoodsPage() { ...@@ -20,7 +24,8 @@ function OrderGoodsPage() {
<TitleImg config={ORDER_CONFIG.head} position={'bottom'} /> <TitleImg config={ORDER_CONFIG.head} position={'bottom'} />
</View> </View>
<View className={styles['page-content__list']}> <View className={styles['page-content__list']}>
<GoodsList goodsList={data?.list || []} task={ORDER_CONFIG} /> {/* <GoodsList goodsList={data?.list || []} task={ORDER_CONFIG} /> */}
<GoodsList onScrollToLower={scrollToNextList} goodsList={goodsList || []} task={ORDER_CONFIG} />
</View> </View>
</ContainerFit> </ContainerFit>
......
import { useState } from 'react'
import { createModel } from 'hox'
function goodsListInfo(){
const [listStorage,setListStorage] = useState({})
return {
listStorage,
setListStorage
}
}
export const goodsListInfoModel = createModel(goodsListInfo)
\ No newline at end of file
export * from './activityInfo' export * from './activityInfo'
export * from './loginInfo' export * from './loginInfo'
export * from './goodsListInfo'
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment