import { Ref, defineComponent, onMounted, reactive, ref } from 'vue'; import styles from '../index.module.less'; import { NButton, NDataTable, NForm, NFormItem, NNumberAnimation, NSpace } from 'naive-ui'; import numeral from 'numeral'; import { useECharts } from '@/hooks/web/useECharts'; import Pagination from '/src/components/pagination'; import { getTrainingStat } from '../api'; import { getTrainingStatList } from '@/views/classList/api' import { getNowDateAndMonday, getNowDateAndSunday, getTimes, getMinutes, getSecend } from '/src/utils/dateFormat'; import CDatePicker from '/src/components/CDatePicker'; export default defineComponent({ name: 'student-practiceData', props: { studentId: { type: String, default: '' } }, setup(props) { const chartRef = ref(null); const { setOptions } = useECharts(chartRef as Ref); const practiceFlag = ref(true); const payForm = reactive({ height: '360px', width: '100%', practiceDurationAvg: 0, practiceDays: 0, practiceDurationTotal: 0, dateList: [], timeList: [] }); const state = reactive({ loading: false, pagination: { page: 1, rows: 10, pageTotal: 4 }, tableList: [] as any, goCourseVisiable: false }); const timer = ref<[number, number]>([ getNowDateAndMonday(new Date().getTime()), getNowDateAndSunday(new Date().getTime()) ]); const columns = () => { return [ { title: '日期', key: 'date' }, { title: '练习时长(分钟)', key: 'practiceDuration', render(row: any) { return ( <> {' '} <> {row.practiceDuration ? getMinutes(row.practiceDuration) > 0 ? getMinutes(row.practiceDuration) + '分' + getSecend(row.practiceDuration) + '秒' : getSecend(row.practiceDuration) + '秒' : 0 + '分钟'} ); } } ]; }; const getList = async () => { try{ const res = await getTrainingStatList({ page:1, rows:999, studentId: props.studentId, ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD') }) state.tableList = res.data.rows; }catch(e){ console.log(e) } }; const setChart = () => { setOptions({ tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } }, legend: { show: false, selected: { //在这里设置默认展示就ok了 '练习时长(分钟)': practiceFlag.value } }, xAxis: { type: 'category', boundaryGap: true, axisLabel: { show: true, interval: 0 }, data: payForm.dateList }, yAxis: [ { type: 'value', axisLabel: { formatter: (value: any) => { return getMinutes(value) + 'min'; } }, axisTick: { show: false }, splitArea: { show: false, areaStyle: { color: ['rgba(255,255,255,0.2)'] } } } ], grid: { left: '1%', right: '1%', top: '2%', bottom: 0, containLabel: true }, series: [ { // smooth: true, data: payForm.timeList, type: 'bar', barWidth: '48px', stack: 'total', // label: { // // 柱图头部显示值 // formatter: (value: any) => { // console.log(value); // return getMinutes(value.value); // }, // show: true, // position: 'top', // color: '#333', // fontSize: '12px', // fontWeight: 600 // }, itemStyle: { normal: { //这里设置柱形图圆角 [左上角,右上角,右下角,左下角] barBorderRadius: [8, 8, 0, 0], color: '#D5E9FF' }, emphasis: { focus: 'series', color: '#3583FA' //hover时改变柱子颜色 // borderWidth: 4, // borderColor: 'rgba(213, 233, 255,.4)', // borderType: 'solid' } } as any } ], formatter: (item: any) => { if (Array.isArray(item)) { return [ item[0].axisValueLabel, ...item.map((d: any) => { let str; getMinutes(d.value) > 0 ? (str = getMinutes(d.value) + '分' + getSecend(d.value) + '秒') : (str = getSecend(d.value) + '秒'); return `
${d.marker}练习时长: ${str} `; }) ].join(''); } else { return item; } } // dataZoom: [ // { // type: 'slider', // start: 5, // end: 100, // filterMode: 'empty' // } // ] }); }; const getChartDetail = async () => { try { const res = await getTrainingStat({ studentId: props.studentId, ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD') }); payForm.practiceDays = res.data.practiceDays; payForm.practiceDurationAvg = res.data.practiceDurationAvg; payForm.practiceDurationTotal = res.data.practiceDurationTotal; payForm.dateList = res.data.trainingStatDetailList.map((item: any) => { return item.date; }); payForm.timeList = res.data.trainingStatDetailList.map((item: any) => { return item.practiceDuration; }); setChart(); console.log(payForm); } catch (e) { console.log(e); } }; const search = () => { state.pagination.page = 1; getChartDetail(); getList() console.log('search'); }; const onReset = () => { timer.value = [ getNowDateAndMonday(new Date().getTime()), getNowDateAndSunday(new Date().getTime()) ]; search(); getList() console.log('onReset'); }; onMounted(() => { console.log(props.studentId); getChartDetail(); getList() }); return () => ( <> 搜索 重置

{getMinutes(payForm.practiceDurationTotal) > 0 ? (

{' '} 分
) : null}
{' '} 秒

累计练习时长

{getMinutes(payForm.practiceDurationAvg) > 0 ? (

{' '} 分
) : null}
{' '} 秒

平均练习时长

{' '} 天

练习天数

{ // practiceFlag.value = !practiceFlag.value; // setChart(); // }} class={[ styles.DataTopRightItem, practiceFlag.value ? '' : styles.DataTopRightItemDis ]}>

练习时长(分钟)

{/* */}
); } });