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