Compare commits
7 Commits
cb88f49e85
...
a43a0fabc2
Author | SHA1 | Date |
---|---|---|
king | a43a0fabc2 | 1 year ago |
king | 9d9506c66e | 1 year ago |
king | ee5741a752 | 1 year ago |
king | 5e6375cd4f | 1 year ago |
king | 9f17e4c886 | 1 year ago |
king | aeb6e1bbc5 | 1 year ago |
king | 3a777d0b57 | 1 year ago |
@ -0,0 +1,18 @@ |
||||
import {CSSProperties, FC} from "react"; |
||||
import {View} from "@tarojs/components"; |
||||
|
||||
interface Props { |
||||
text?: string |
||||
styles?: CSSProperties |
||||
className?: string |
||||
} |
||||
|
||||
const PageScript: FC<Props> = (props) => { |
||||
return <View |
||||
className={'text-center font-24 text-dark py-3 ' + props.className} |
||||
style={props.styles}> |
||||
{props.text || "暂无更多"} |
||||
</View> |
||||
} |
||||
|
||||
export default PageScript |
@ -0,0 +1,4 @@ |
||||
export default definePageConfig({ |
||||
navigationBarTitleText: '推荐文章', |
||||
onReachBottomDistance: 50 |
||||
}) |
@ -0,0 +1,56 @@ |
||||
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"; |
||||
import PageScript from "@/components/pageScript/pageScript"; |
||||
import Empty from "@/components/empty/empty"; |
||||
|
||||
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.length > 0 |
||||
?data.map(d => <ArticlesBox data={d}/>) |
||||
:<Empty name='暂无更多文章'/> |
||||
} |
||||
</View> |
||||
<PageScript/> |
||||
</View> |
||||
) |
||||
} |
||||
|
||||
export default JumpArticlesConfig |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 2.1 KiB |
Loading…
Reference in new issue