parent
9f17e4c886
commit
5e6375cd4f
@ -1,5 +1,5 @@ |
||||
#TARO_APP_API=https://yjx.dev.yaojiankang.top |
||||
TARO_APP_API=https://mooc.yaojiankang.top |
||||
TARO_APP_API=https://yjx.dev.yaojiankang.top |
||||
#TARO_APP_API=https://mooc.yaojiankang.top |
||||
#TARO_APP_API=https://shopfix.yaojiankang.top |
||||
#TARO_APP_API=https://playedu.yaojiankang.top |
||||
TARO_APP_LGOIN=true |
||||
|
@ -0,0 +1,4 @@ |
||||
export default definePageConfig({ |
||||
navigationBarTitleText: '推荐文章', |
||||
onReachBottomDistance: 50 |
||||
}) |
@ -0,0 +1,51 @@ |
||||
import {FC, useEffect, useState} from "react"; |
||||
import {View} from "@tarojs/components"; |
||||
import {publicApi} from "@/api"; |
||||
import Spin from "@/components/spinner"; |
||||
import ArticlesBox from "@/components/articlesBox/articlesBox"; |
||||
import {useReachBottom} from "@tarojs/taro"; |
||||
|
||||
const JumpArticlesConfig: FC = () => { |
||||
const [page, setPage] = useState(1) |
||||
const [total, setTotal] = useState(0) |
||||
const [enable, setEnable] = useState(true) |
||||
const [data, setData] = useState<Articles[]>([]) |
||||
|
||||
useEffect(() => { |
||||
publicApi.articlesPush(page, 10).then(res => { |
||||
setTotal(res.total) |
||||
const result = res.list.reduce((pre, cur) => { |
||||
const index = pre.findIndex(d => d.id === cur.id) |
||||
if (index === -1) { |
||||
pre.push(cur) |
||||
} else { |
||||
pre.splice(index, 1, cur) |
||||
} |
||||
return pre |
||||
}, data) |
||||
setData(result) |
||||
}).finally(() => { |
||||
setEnable(false) |
||||
}) |
||||
}, [page]) |
||||
|
||||
useReachBottom(() => { |
||||
if (data.length < total) { |
||||
setPage(page + 1) |
||||
} |
||||
}) |
||||
|
||||
|
||||
return ( |
||||
<View> |
||||
<Spin enable={enable} overlay/> |
||||
<View className='bg-white rounded-20 clip m-3 px-3'> |
||||
{ |
||||
data.map(d => <ArticlesBox data={d}/>) |
||||
} |
||||
</View> |
||||
</View> |
||||
) |
||||
} |
||||
|
||||
export default JumpArticlesConfig |
Loading…
Reference in new issue