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