From 380b7be4fa004f8f5c6caba004b86098b06c9f54 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Mon, 11 Sep 2023 17:05:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=AA=E4=BA=BA=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=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/pages/my/components/header/time.tsx | 31 ++++++++++--------------- src/pages/my/my.tsx | 6 +++-- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/pages/my/components/header/time.tsx b/src/pages/my/components/header/time.tsx index 40ade2d..c4cb2ed 100644 --- a/src/pages/my/components/header/time.tsx +++ b/src/pages/my/components/header/time.tsx @@ -1,13 +1,11 @@ import {Image, View} from "@tarojs/components"; import styles from '../../my.module.scss' import Taro from "@tarojs/taro"; -import {curriculum} from "@/api"; +import {Course} from "@/api"; import {FC, useEffect, useState} from "react"; import {formatMinute} from "@/utils/time"; import time1 from "@/static/img/time1.png"; import time2 from "@/static/img/time2.png"; -// import over from '@/static/img/over.png' -// import incomplete from '@/static/img/incomplete.png' import {Profile} from "@/store"; interface List { @@ -17,29 +15,24 @@ interface List { type?: number } -const Time: FC = () => { +interface Props { + courseRecord: Course | undefined +} + +const Time: FC = ({courseRecord}) => { const {token} = Profile.useContainer() const [list, setList] = useState([ {title: '今日时长', time: '00:00', src: time1}, {title: '累计时长', time: '00:00', src: time2}, - // {title: '必修课', time: '0', src: curriculum1, type: 1}, - // {title: '选修课', time: '0', src: curriculum2, type: 2}, - // {title: '已完成', time: '0', src: over, type: 3}, - // {title: '未完成(必修)', time: '0', src: incomplete, type: 4}, ]) useEffect(() => { - curriculum.course().then(res => { - const oldList: List[] = JSON.parse(JSON.stringify(list)) - oldList[0].time = formatMinute(res.today_learn_time) - oldList[1].time = formatMinute(res.total_learn_time) - // oldList[2].time = res.required_count - // oldList[3].time = res.not_required_count - // oldList[2].time = res.finished_count - // oldList[3].time = res.not_finished_count - setList(oldList) - }) - }, []) + if (!courseRecord) return; + const oldList: List[] = JSON.parse(JSON.stringify(list)) + oldList[0].time = formatMinute(courseRecord.today_learn_time) + oldList[1].time = formatMinute(courseRecord.total_learn_time) + setList(oldList) + }, [courseRecord]) function jump(type?: number) { if (!token) { diff --git a/src/pages/my/my.tsx b/src/pages/my/my.tsx index 3b4c2bd..861e9b5 100644 --- a/src/pages/my/my.tsx +++ b/src/pages/my/my.tsx @@ -8,7 +8,7 @@ import Service from "@/pages/my/components/header/service"; import {Profile} from "@/store"; import Img from "@/components/image/image"; import GreenNike from "@/static/img/greenNike.png" -import {curriculum, userApi} from "@/api"; +import {Course, curriculum, userApi} from "@/api"; import LearningRecord from "@/components/learningRecord/learningRecord"; import NavigationBar from "@/components/navigationBar/navigationBar"; import over from "@/static/img/over.png"; @@ -36,6 +36,7 @@ const My: FC = () => { const {token, company, setCompany, user} = Profile.useContainer() const [companyShow, setCompanyShow] = useState(false) const [companyList, setCompanyList] = useState([]) + const [courseRecord,setCourseRecord] = useState(undefined) const [navbarOpacity, setNavbarOpacity] = useState('0') const navbarHeight = globalData.statusBarHeight + globalData.textBarHeight; const [auditMode, setAuditMode] = useState(true) @@ -61,6 +62,7 @@ const My: FC = () => { Taro.useDidShow(async () => { try { const res = await curriculum.course() + setCourseRecord(res) setAuditMode(!!res?.audit_mode) const oldList: List[] = JSON.parse(JSON.stringify(list)) oldList[0].time = res.finished_count || 0 @@ -95,7 +97,7 @@ const My: FC = () => { { !auditMode && <> -