import { Ref, defineComponent, onMounted, reactive, ref } from 'vue'; import styles from '../index.module.less'; import { NButton, NDataTable, NNumberAnimation } from 'naive-ui'; import numeral from 'numeral'; import { useECharts } from '@/hooks/web/useECharts'; import Pagination from '/src/components/pagination'; import { getTrainingStat } from '@/views/data-module/api' import { getTimes } from '/src/utils/dateFormat'; export default defineComponent({ name: 'home-practiceData', props:{ timer:{ type:Array, defaut:()=>[] } }, setup(props,{expose}) { const chartRef = ref(null); const { setOptions } = useECharts(chartRef as Ref); const practiceFlag = ref(true); const payForm = reactive({ height: '360px', width: '100%', studentNum: 0, paymentAmount: 0, dateList: [ '2022-10-10', '2022-10-11', '2022-10-12', '2022-10-13', '2022-10-14', '2022-10-15', '2022-10-16' ], timeList: [90, 128, 242, 120, 186, 77, 148] }); const state = reactive({ loading: false, pagination: { page: 1, rows: 10, pageTotal: 4 }, tableList: [ { teacherName: '孙忆枫', createTime: '2023-06-27', endTime: '2023-06-30', status: 'ing', studentNum: 100, submitNum: 100, quantityNum: 60, submitRate: 100, quantityRate: 60 }, { teacherName: '孙忆枫', createTime: '2023-06-27', endTime: '2023-06-30', status: 'ing', studentNum: 100, submitNum: 100, quantityNum: 60, submitRate: 100, quantityRate: 60 }, { teacherName: '孙忆枫', createTime: '2023-06-27', endTime: '2023-06-30', status: 'ing', studentNum: 100, submitNum: 100, quantityNum: 60, submitRate: 100, quantityRate: 60 }, { teacherName: '孙忆枫', createTime: '2023-06-25', endTime: '2023-06-26', status: 'end', studentNum: 100, submitNum: 100, quantityNum: 60, submitRate: 100, quantityRate: 60 } ] as any, goCourseVisiable: false }); const columns = () => { return [ { title: '日期', key: 'createTime' }, { title: '练习人数', key: 'quantityNum', render(row: any) { return {row.quantityNum}人; } }, { title: '平均练习时长(分钟)', key: 'submitNum', render(row: any) { return {row.submitNum}分钟; } } ]; }; const getList = async () => { try{ const res = await getTrainingStat({ ...getTimes(props.timer, ['startTime', 'endTime'], 'YYYY-MM-DD')}) }catch(e){ console.log(e) } }; expose({getList}) const setChart = () => { setOptions({ tooltip: { trigger: 'axis', axisPointer: { type: 'none' } }, 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} 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', label: { // 柱图头部显示值 show: true, position: 'top', color: '#333', fontSize: '12px', fontWeight: 600 }, itemStyle: { normal: { //这里设置柱形图圆角 [左上角,右上角,右下角,左下角] barBorderRadius: [8, 8, 0, 0], color: '#D5E9FF' }, emphasis: { 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) => `
${ d.marker }练习时长: ${d.value}${'分钟'} ` ) ].join(''); } else { return item; } } // dataZoom: [ // { // type: 'slider', // start: 5, // end: 100, // filterMode: 'empty' // } // ] }); }; onMounted(()=>{ getList() setChart(); }) return () => ( <>

练习人数

分钟

平均练习时长

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

练习时长(分钟)

); } });