修改个人中心学习记录

v2
king 1 year ago
parent fd06be84d5
commit 380b7be4fa
  1. 31
      src/pages/my/components/header/time.tsx
  2. 6
      src/pages/my/my.tsx

@ -1,13 +1,11 @@
import {Image, View} from "@tarojs/components"; import {Image, View} from "@tarojs/components";
import styles from '../../my.module.scss' import styles from '../../my.module.scss'
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import {curriculum} from "@/api"; import {Course} from "@/api";
import {FC, useEffect, useState} from "react"; import {FC, useEffect, useState} from "react";
import {formatMinute} from "@/utils/time"; import {formatMinute} from "@/utils/time";
import time1 from "@/static/img/time1.png"; import time1 from "@/static/img/time1.png";
import time2 from "@/static/img/time2.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"; import {Profile} from "@/store";
interface List { interface List {
@ -17,29 +15,24 @@ interface List {
type?: number type?: number
} }
const Time: FC = () => { interface Props {
courseRecord: Course | undefined
}
const Time: FC<Props> = ({courseRecord}) => {
const {token} = Profile.useContainer() const {token} = Profile.useContainer()
const [list, setList] = useState<List[]>([ const [list, setList] = useState<List[]>([
{title: '今日时长', time: '00:00', src: time1}, {title: '今日时长', time: '00:00', src: time1},
{title: '累计时长', time: '00:00', src: time2}, {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(() => { useEffect(() => {
curriculum.course().then(res => { if (!courseRecord) return;
const oldList: List[] = JSON.parse(JSON.stringify(list)) const oldList: List[] = JSON.parse(JSON.stringify(list))
oldList[0].time = formatMinute(res.today_learn_time) oldList[0].time = formatMinute(courseRecord.today_learn_time)
oldList[1].time = formatMinute(res.total_learn_time) oldList[1].time = formatMinute(courseRecord.total_learn_time)
// oldList[2].time = res.required_count setList(oldList)
// oldList[3].time = res.not_required_count }, [courseRecord])
// oldList[2].time = res.finished_count
// oldList[3].time = res.not_finished_count
setList(oldList)
})
}, [])
function jump(type?: number) { function jump(type?: number) {
if (!token) { if (!token) {

@ -8,7 +8,7 @@ import Service from "@/pages/my/components/header/service";
import {Profile} from "@/store"; import {Profile} from "@/store";
import Img from "@/components/image/image"; import Img from "@/components/image/image";
import GreenNike from "@/static/img/greenNike.png" 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 LearningRecord from "@/components/learningRecord/learningRecord";
import NavigationBar from "@/components/navigationBar/navigationBar"; import NavigationBar from "@/components/navigationBar/navigationBar";
import over from "@/static/img/over.png"; import over from "@/static/img/over.png";
@ -36,6 +36,7 @@ const My: FC = () => {
const {token, company, setCompany, user} = Profile.useContainer() const {token, company, setCompany, user} = Profile.useContainer()
const [companyShow, setCompanyShow] = useState(false) const [companyShow, setCompanyShow] = useState(false)
const [companyList, setCompanyList] = useState<Company[]>([]) const [companyList, setCompanyList] = useState<Company[]>([])
const [courseRecord,setCourseRecord] = useState<Course | undefined>(undefined)
const [navbarOpacity, setNavbarOpacity] = useState('0') const [navbarOpacity, setNavbarOpacity] = useState('0')
const navbarHeight = globalData.statusBarHeight + globalData.textBarHeight; const navbarHeight = globalData.statusBarHeight + globalData.textBarHeight;
const [auditMode, setAuditMode] = useState(true) const [auditMode, setAuditMode] = useState(true)
@ -61,6 +62,7 @@ const My: FC = () => {
Taro.useDidShow(async () => { Taro.useDidShow(async () => {
try { try {
const res = await curriculum.course() const res = await curriculum.course()
setCourseRecord(res)
setAuditMode(!!res?.audit_mode) setAuditMode(!!res?.audit_mode)
const oldList: List[] = JSON.parse(JSON.stringify(list)) const oldList: List[] = JSON.parse(JSON.stringify(list))
oldList[0].time = res.finished_count || 0 oldList[0].time = res.finished_count || 0
@ -95,7 +97,7 @@ const My: FC = () => {
{ {
!auditMode && <> !auditMode && <>
<Time/> <Time courseRecord={courseRecord}/>
<View className="bg-white rounded-20 mb-2 clip"> <View className="bg-white rounded-20 mb-2 clip">
<View className="flex p-2"> <View className="flex p-2">
{list.map((d) => ( {list.map((d) => (

Loading…
Cancel
Save