diff --git a/.env b/.env index 86e2b46..3852d45 100644 --- a/.env +++ b/.env @@ -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 diff --git a/src/api/public.ts b/src/api/public.ts index bb20e62..482dce1 100644 --- a/src/api/public.ts +++ b/src/api/public.ts @@ -9,10 +9,6 @@ export interface Category { resource_category?: Category[] } -interface CategoryList { - categories: Record -} - export interface CoursesMode { articles: any[] audit_mode: boolean @@ -20,7 +16,6 @@ export interface CoursesMode { } export interface Courses { - /** 选秀 */ is_not_required: Curriculum[] /** 必修 */ @@ -33,12 +28,11 @@ export type CoursesKey = keyof Omit export const publicApi = { - /** 分类 */ - category() { - return request('/api/v1/category/all', "GET") - }, /** 课程 */ course(data: { page: number, pageSize: number }) { return request('/api/v1/category/course/index', "GET", data) + }, + articlesPush(page: number, page_size: number) { + return request<{ list: Articles[], total: number }>('/home/v1/article/list', "GET", {page, page_size}) } } diff --git a/src/app.config.ts b/src/app.config.ts index 74d8a60..596dcce 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -94,6 +94,7 @@ export default defineAppConfig({ 'webView/webView', 'search/search/index', 'collect/collect', // 收藏列表 + 'jumpArticles/jumpArticles', // 推荐文章 ] }, ], diff --git a/src/pages/home/components/curRecommended.tsx b/src/pages/home/components/curRecommended.tsx index a081971..a8d88e9 100644 --- a/src/pages/home/components/curRecommended.tsx +++ b/src/pages/home/components/curRecommended.tsx @@ -1,11 +1,12 @@ import {FC, ReactNode, useEffect, useState} from "react"; -import {Image, View} from "@tarojs/components"; +import {Image, Text, View} from "@tarojs/components"; import {HomeApi} from "@/api"; -import {useReachBottom} from "@tarojs/taro"; +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 arrowRight from '@/static/img/arrow-right.png' const CurRecommended: FC = () => { const [page, setPage] = useState(1) @@ -29,6 +30,10 @@ const CurRecommended: FC = () => { setData(newData ?? []) } + function jumpArticles() { + Taro.navigateTo({url: '/pages/preview/jumpArticles/jumpArticles'}) + } + useEffect(() => { getData() }, [page]) @@ -40,13 +45,17 @@ const CurRecommended: FC = () => { let examines: ReactNode | undefined if (articles.length > 0) { examines = ( - - - 推荐文章 - { - articles.map(d => ) - } + + + 推荐文章 + + 查看更多 + + + { + articles.map(d => ) + } ) } diff --git a/src/pages/home/home.tsx b/src/pages/home/home.tsx index f30351b..9134c27 100644 --- a/src/pages/home/home.tsx +++ b/src/pages/home/home.tsx @@ -51,7 +51,7 @@ const Home: FC = () => { cancelBack leftNode={ <> - + 信桂 } diff --git a/src/pages/preview/jumpArticles/jumpArticles.config.ts b/src/pages/preview/jumpArticles/jumpArticles.config.ts new file mode 100644 index 0000000..6e337e5 --- /dev/null +++ b/src/pages/preview/jumpArticles/jumpArticles.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '推荐文章', + onReachBottomDistance: 50 +}) diff --git a/src/pages/preview/jumpArticles/jumpArticles.tsx b/src/pages/preview/jumpArticles/jumpArticles.tsx new file mode 100644 index 0000000..b03503d --- /dev/null +++ b/src/pages/preview/jumpArticles/jumpArticles.tsx @@ -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([]) + + 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 ( + + + + { + data.map(d => ) + } + + + ) +} + +export default JumpArticlesConfig