|
|
|
@ -5,6 +5,7 @@ import LineChart from "@/components/lineChart/lineChart"; |
|
|
|
|
import {FC, useEffect, useState} from "react"; |
|
|
|
|
import {StatisticsParam, userApi} from "@/api"; |
|
|
|
|
import styles from './learningRecord.module.scss' |
|
|
|
|
import Spin from "@/components/spinner"; |
|
|
|
|
|
|
|
|
|
const tabList: TabList<any>[] = [ |
|
|
|
|
{ |
|
|
|
@ -38,16 +39,19 @@ interface Props { |
|
|
|
|
*/ |
|
|
|
|
const LearningRecord: FC<Props> = ({userId}) => { |
|
|
|
|
const [lineData, setLineData] = useState<any[]>([]) |
|
|
|
|
const [loading, setLoading] = useState(false) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function getStatistics(data: StatisticsParam) { |
|
|
|
|
try { |
|
|
|
|
setLoading(true) |
|
|
|
|
const res = await userApi.statistics(userId, data) |
|
|
|
|
const everyDayValue = everyDay(data.start_time, Number(data.end_time), res.data) |
|
|
|
|
setLineData(everyDayValue) |
|
|
|
|
} catch (e) { |
|
|
|
|
setLineData([]) |
|
|
|
|
} |
|
|
|
|
setLoading(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function tabChange({tab}: OnChangOpt<StatisticsParam>) { |
|
|
|
@ -60,13 +64,16 @@ const LearningRecord: FC<Props> = ({userId}) => { |
|
|
|
|
|
|
|
|
|
return (<View className={styles.box} style={{display: 'block'}}> |
|
|
|
|
<Tabs tabList={tabList} onChange={tabChange} backMode/> |
|
|
|
|
<View className={styles.total}> |
|
|
|
|
总共学习 |
|
|
|
|
<Text style={{margin: '0 10px', color: '#00D6AC'}}> |
|
|
|
|
{formatTime(lineData.reduce((pre, cur) => pre + cur.value, 0) || 0)} |
|
|
|
|
</Text> |
|
|
|
|
<View style={{position: "relative"}}> |
|
|
|
|
<Spin enable={loading} block/> |
|
|
|
|
<View className={styles.total}> |
|
|
|
|
总共学习 |
|
|
|
|
<Text style={{margin: '0 10px', color: '#00D6AC'}}> |
|
|
|
|
{formatTime(lineData.reduce((pre, cur) => pre + cur.value, 0) || 0)} |
|
|
|
|
</Text> |
|
|
|
|
</View> |
|
|
|
|
<LineChart data={lineData}/> |
|
|
|
|
</View> |
|
|
|
|
<LineChart data={lineData}/> |
|
|
|
|
</View>) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|