|
|
|
@ -8,7 +8,8 @@ import Empty from "@/components/empty/empty"; |
|
|
|
|
const BrandList: FC = () => { |
|
|
|
|
const params = useRouter().params as unknown as { id: number } |
|
|
|
|
const [page, setPage] = useState(1) |
|
|
|
|
const [brands, setBrands] = useState<any[]>([]) |
|
|
|
|
const [articles, setArticles] = useState<any[]>([]) |
|
|
|
|
const [illness,setIllness] = useState<{name:string;description:string;resource:any;album:string[]}>() |
|
|
|
|
const [total, setTotal] = useState(0) |
|
|
|
|
const [fetchDone, setFetchDone] = useState(false) |
|
|
|
|
|
|
|
|
@ -20,8 +21,10 @@ const BrandList: FC = () => { |
|
|
|
|
const getData = useCallback(async () => { |
|
|
|
|
try { |
|
|
|
|
const data = await illnessApi.articleInfo(params.id, page, 20) |
|
|
|
|
setTotal(data.total) |
|
|
|
|
setBrands([...brands, ...data.list]) |
|
|
|
|
Taro.setNavigationBarTitle({title:data.illness.name}) |
|
|
|
|
setIllness(data.illness) |
|
|
|
|
setTotal(data.list.total) |
|
|
|
|
setArticles([...articles, ...data.list.list]) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
setFetchDone(true) |
|
|
|
@ -34,17 +37,17 @@ const BrandList: FC = () => { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useReachBottom(useCallback(() => { |
|
|
|
|
if (brands?.length < total) { |
|
|
|
|
if (articles?.length < total) { |
|
|
|
|
setPage(page + 1) |
|
|
|
|
} |
|
|
|
|
}, [total, brands])) |
|
|
|
|
}, [total, articles])) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<View style={{display: fetchDone ? 'block' : 'none'}} className='px-2 mt-2 bg-white'> |
|
|
|
|
{ |
|
|
|
|
brands.length > 0 ? |
|
|
|
|
brands.map((d, index) => <View key={d.id} className={styles.brands} onClick={() => jump(d.id)}> |
|
|
|
|
articles.length > 0 ? |
|
|
|
|
articles.map((d, index) => <View key={d.id} className={styles.articles} onClick={() => jump(d.id)}> |
|
|
|
|
{index + 1} . {d.title} |
|
|
|
|
</View>) |
|
|
|
|
: <Empty name='暂无文章'/> |
|
|
|
|