import {FC, ReactNode, useEffect, useState} from "react"; import {Image, Text, View} from "@tarojs/components"; import {HomeApi} from "@/api"; import Taro, {useReachBottom} from "@tarojs/taro"; import styles from "../home.module.scss"; import VideoCover from "@/components/videoCover/videoCover"; import courseTag from '@/static/img/courseTag.png' import ArticlesBox from "@/components/articlesBox/articlesBox"; import PageScript from "@/components/pageScript/pageScript"; import IconFont from "@/components/IconFont"; const CurRecommended: FC = () => { const [page, setPage] = useState(1) const [data, setData] = useState([]) const [total, setTotal] = useState(0) const [articles, setArticles] = useState([]) async function getData() { const res = await HomeApi.home() setArticles(res.articles) setTotal(res.courses.total) const newData = res.courses.data?.reduce((pre, cut) => { const index = pre.findIndex(d => d.id === cut.id) if (index === -1) { pre.push(cut) } else { pre.splice(index, 1, cut) } return pre }, JSON.parse(JSON.stringify(data)) as Curriculum[]) setData(newData ?? []) } function jumpArticles() { Taro.navigateTo({url: '/pages/preview/jumpArticles/jumpArticles'}) } useEffect(() => { getData() }, [page]) useReachBottom(() => { data.length < total && setPage(page + 1) }) let examines: ReactNode | undefined if (articles.length > 0) { examines = ( 推荐文章 查看更多 {articles.map(d => )} ) } let videos: ReactNode | undefined if (data.length > 0) { videos = ( { data.map(c => ) } ) } return ( <> {examines} {videos} ) } export default CurRecommended