From aee74e0418a86b12f1b99056c531b7a0b99fd493 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Wed, 19 Jul 2023 14:19:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.ts | 7 ++++++ src/pages/index/components/videoList.tsx | 30 +++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/api/user.ts b/src/api/user.ts index 9ce1bd5..6fd92f0 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -31,6 +31,10 @@ interface DepListData { user: User } +interface LearningRecord { + user_course_records: LearnRecord[] +} + export const userApi = { login(code: string) { @@ -51,5 +55,8 @@ export const userApi = { }, code(catch_key: string) { return request<{ code: Code }>(`/api/v1/auth/login/code`, "POST", {openid: catch_key}) + }, + learningRecord(courseId = 0) { + return request(`/api/v1/user/record/course`, "GET", {courseId}) } } diff --git a/src/pages/index/components/videoList.tsx b/src/pages/index/components/videoList.tsx index 0c3445c..51c21a9 100644 --- a/src/pages/index/components/videoList.tsx +++ b/src/pages/index/components/videoList.tsx @@ -5,6 +5,7 @@ import {CoursesKey, Cur, publicApi} from "@/api/public"; import VideoCover from "@/components/videoCover/videoCover"; import styles from '../index.module.scss' import {formatMinute} from "@/utils/time"; +import {userApi} from "@/api"; interface Props { categoryId: CoursesKey @@ -13,6 +14,7 @@ interface Props { export const VideoList: FC = ({categoryId}: Props) => { const [data, setDta] = useState(null) const [index, setIndex] = useState(3) + const [records, setRecords] = useState([]) async function getData() { try { @@ -35,10 +37,29 @@ export const VideoList: FC = ({categoryId}: Props) => { Taro.hideLoading() } + async function getRecords() { + try { + const {user_course_records} = await userApi.learningRecord() + setRecords(user_course_records) + } catch (e) { + } + } + function rateOfLearning(id: number, class_hour: number): JSX.Element { - console.log(id) - return ({`共${class_hour}节/已学${0}节`}) + switch (categoryId) { + case "is_finished": + case "is_not_required": + const find = records.find(d => d.course_id === id) + if (find) { + return ({`共${class_hour}节/已学${find.finished_count}节`}) + } + return ({`共${class_hour}节/已学0节`}) + case "is_not_finished": + return ({`共${class_hour}节/已学0节`}) + case "is_required": + return ({`共${class_hour}节/已学${class_hour}节`}) + } } function jumpCategoryCur(id: number) { @@ -51,7 +72,10 @@ export const VideoList: FC = ({categoryId}: Props) => { } }) - Taro.useDidShow(getData) + Taro.useDidShow(() => { + getData() + getRecords() + }) return ( <> {data?.slice(0, index).map(d => (