From 88db099a7d9b75d2ffd4a5302a12b58d1bf68ffe Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Fri, 11 Aug 2023 15:52:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5onshow=20=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lineChart/lineChart.module.scss | 1 - src/components/lineChart/lineChart.tsx | 2 +- src/components/topic/judge.tsx | 5 ++-- src/components/video/video.tsx | 4 ++- src/pages/index/components/videoList.tsx | 25 +++++++++++++++++-- src/pages/manage/userInfo/userInfo.tsx | 9 ++++--- 6 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/components/lineChart/lineChart.module.scss b/src/components/lineChart/lineChart.module.scss index 553911a..cf32a2d 100644 --- a/src/components/lineChart/lineChart.module.scss +++ b/src/components/lineChart/lineChart.module.scss @@ -5,7 +5,6 @@ flex-wrap: nowrap; height: 420px; position: relative; - margin-top: 30rpx; } .empty { diff --git a/src/components/lineChart/lineChart.tsx b/src/components/lineChart/lineChart.tsx index dad4a8e..f29b97b 100644 --- a/src/components/lineChart/lineChart.tsx +++ b/src/components/lineChart/lineChart.tsx @@ -30,7 +30,7 @@ const LineChart: FC = ({data}) => { return ( <> - {maxHeight.time && {maxHeight.time}日最努力,学习了{formatMinute(maxHeight.value)}} + {maxHeight.time}日最努力,学习了{formatMinute(maxHeight.value)} {!maxHeight.value && 暂无数据} diff --git a/src/components/topic/judge.tsx b/src/components/topic/judge.tsx index 6def01c..c8444e6 100644 --- a/src/components/topic/judge.tsx +++ b/src/components/topic/judge.tsx @@ -1,5 +1,5 @@ import {FC, useEffect, useState} from "react"; -import { Radio, RadioGroup, Text, View} from "@tarojs/components"; +import {Radio, RadioGroup, Text, View} from "@tarojs/components"; import './topic.scss' interface Props { @@ -11,7 +11,7 @@ interface Props { const Judge: FC = ({data, onAnswer, validate, frequency}) => { const [rightAnswer, setRightAnswer] = useState(null) //答案 - const rightKey = data.right_answer ? 'correct' : 'error' // 正确答案数组 + const rightKey = data.right_answer === 'true' ? 'correct' : 'error' // 正确答案数组 const [error, setError] = useState(false) @@ -55,7 +55,6 @@ const Judge: FC = ({data, onAnswer, validate, frequency}) => { - {error && frequency == 0 && 正确答案:{data.right_answer ? '正确' : '错误'} 题目解析 diff --git a/src/components/video/video.tsx b/src/components/video/video.tsx index fd9aeaf..9190a13 100644 --- a/src/components/video/video.tsx +++ b/src/components/video/video.tsx @@ -45,7 +45,9 @@ const HVideo: FC = (opt: HVideoOptions) => { video?.pause() video?.seek(d - deviation) if (process.env.TARO_ENV === 'h5') { - document?.exitFullscreen() + try { + document?.exitFullscreen().then() + } catch (e) {} } video?.exitFullScreen() diff --git a/src/pages/index/components/videoList.tsx b/src/pages/index/components/videoList.tsx index 38f104f..5890586 100644 --- a/src/pages/index/components/videoList.tsx +++ b/src/pages/index/components/videoList.tsx @@ -24,10 +24,29 @@ export const VideoList: FC = ({categoryKey, ready}) => { const [page, setPage] = useState(1) const [records, setRecords] = useState([]) + function screen(oldData: Curriculum[], data: Curriculum[]): Curriculum[] { + return data.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 + }, oldData) + } + async function getData() { try { - const res = await publicApi.course({page: 1, pageSize: 10 * page}) - setData(res) + const res = await publicApi.course({page: page, pageSize: 10}) + + const old: Courses = JSON.parse(JSON.stringify(data)) + setData({ + is_finished: screen(old.is_finished, res.is_finished || []), + is_required: screen(old.is_required, res.is_required || []), + is_not_finished: screen(old.is_not_finished, res.is_not_finished || []), + is_not_required: screen(old.is_not_required, res.is_not_required || []), + }) } catch (e) { } } @@ -64,6 +83,7 @@ export const VideoList: FC = ({categoryKey, ready}) => { }) eventsIndex.on(({id}) => { + if (id == null) return; for (const [index, notFinished] of data.is_not_finished.entries()) { if (notFinished.id === id) { data.is_finished.push(notFinished) @@ -75,6 +95,7 @@ export const VideoList: FC = ({categoryKey, ready}) => { useDidShow(() => { if (ready) { + getData().then() getRecords().then() } }) diff --git a/src/pages/manage/userInfo/userInfo.tsx b/src/pages/manage/userInfo/userInfo.tsx index 2157018..608cbcc 100644 --- a/src/pages/manage/userInfo/userInfo.tsx +++ b/src/pages/manage/userInfo/userInfo.tsx @@ -7,7 +7,7 @@ import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; import MyButton from "@/components/button/MyButton"; import {ManageApi, StatisticsParam, userApi} from "@/api"; import {Profile} from "@/store"; -import {everyDay, getMonday, getSunday, monthEnd, monthFirst} from "@/utils/time"; +import {everyDay, formatMinute, getMonday, getSunday, monthEnd, monthFirst} from "@/utils/time"; import LineChart from "@/components/lineChart/lineChart"; @@ -74,7 +74,8 @@ const UserInfo: FC = () => { await ManageApi.del(userId) Taro.showToast({title: '删除成功'}) Taro.navigateBack() - } catch (e) {} + } catch (e) { + } } } }) @@ -117,7 +118,9 @@ const UserInfo: FC = () => { 总共学习 - {lineData.reduce((pre, cur) => pre + cur.value, 0)} + + {formatMinute(lineData.reduce((pre, cur) => pre + cur.value, 0) || 0)} + 分钟