From 084a0652c62e90d0f9d5825fa51f9f9461196d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A6=BA=E7=8B=A8?= <18119604035@163.com> Date: Fri, 24 Mar 2023 14:13:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=AF=BE=E7=A8=8B=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E6=95=B0=E6=8D=AE=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.tsx | 67 +++++++++++++++++++++++++++++++++------ src/utils/index.ts | 2 +- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index cf1942d..7319e1d 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { Tabs } from "antd"; +import { Row, Col, Empty, Spin, Tabs } from "antd"; import type { TabsProps } from "antd"; import { user } from "../../api/index"; import styles from "./index.module.scss"; @@ -10,6 +10,7 @@ import studyTime from "../../assets/images/commen/icon-studytime.png"; import { studyTimeFormat } from "../../utils/index"; const IndexPage = () => { + const [loading, setLoading] = useState(false); const [tabKey, setTabKey] = useState(0); const [coursesList, setCoursesList] = useState([]); const [learnCourseRecords, setLearnCourseRecords] = useState({}); @@ -24,9 +25,11 @@ const IndexPage = () => { }, [tabKey]); const getData = () => { + setLoading(true); user.courses(departments[0].id).then((res: any) => { + const records = res.data.learn_course_records; setStats(res.data.stats); - setLearnCourseRecords(res.data.learn_course_records); + setLearnCourseRecords(records); if (tabKey === 0) { setCoursesList(res.data.courses); } else if (tabKey === 1) { @@ -45,7 +48,27 @@ const IndexPage = () => { } }); setCoursesList(arr); + } else if (tabKey === 3) { + const arr: any = []; + res.data.courses.map((item: any) => { + if (records[item.id] && records[item.id].progress === 100) { + arr.push(item); + } + }); + setCoursesList(arr); + } else if (tabKey === 4) { + const arr: any = []; + res.data.courses.map((item: any) => { + if ( + !records[item.id] || + (records[item.id] && records[item.id].progress !== 100) + ) { + arr.push(item); + } + }); + setCoursesList(arr); } + setLoading(false); }); }; @@ -129,7 +152,10 @@ const IndexPage = () => { 累计: {studyTimeFormat(stats.learn_duration)[0] !== 0 && ( <> - {studyTimeFormat(stats.learn_duration)[0]} + + {" "} + {studyTimeFormat(stats.learn_duration || 0)[0]}{" "} + 天 )} @@ -144,17 +170,38 @@ const IndexPage = () => {
- {coursesList.length === 0 && 暂无数据} + + {loading && ( +
+ +
+ )} + {coursesList.length === 0 && ( + + + + )} +
{coursesList.length > 0 && (
{coursesList.map((item: any) => (
- + {learnCourseRecords[item.id] && ( + + )} + {!learnCourseRecords[item.id] && ( + + )}
))}
diff --git a/src/utils/index.ts b/src/utils/index.ts index e56df3e..f858540 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -17,7 +17,7 @@ export function dateFormat(dateStr: string) { } export function studyTimeFormat(dateStr: number) { - var d = moment.duration(dateStr, "seconds"); + var d = moment.duration(dateStr/1000, "seconds"); let value = []; value.push(Math.floor(d.asDays())); value.push(d.hours());