123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671 |
- import { Ref, computed, defineComponent, reactive, ref } from 'vue';
- import styles from '../index2.module.less';
- import { NButton, NDataTable, NIcon, NNumberAnimation, NTooltip, useMessage } from 'naive-ui';
- import { useECharts } from '@/hooks/web/useECharts';
- // import Pagination from '/src/components/pagination';
- import { getPracticePageStat, getTestStat } from '@/views/data-module/api';
- import { formateSeconds, getHours, getLastMinutes, getMinutes, getSecend, getTimes } from '/src/utils/dateFormat';
- import { api_practiceStatPage } from '../../classList/api';
- import TheEmpty from '/src/components/TheEmpty';
- import iconSortDefault from '@/common/images/icon-sort-default.png';
- import iconSortDesc from '@/common/images/icon-sort-desc.png';
- import iconSortAsc from '@/common/images/icon-sort-asc.png';
- import { convertToChineseNumeral } from '/src/utils';
- import { useRouter } from 'vue-router';
- import { setTabsCaches } from '/src/hooks/use-async';
- import iconQuestion from '/src/common/images/icon-question.png'
- export default defineComponent({
- name: 'home-practiceData',
- props: {
- timer: {
- type: Array,
- defaut: () => []
- }
- },
- setup(props, { expose }) {
- const router = useRouter()
- const message = useMessage()
- const chartRef = ref<HTMLDivElement | null>(null);
- const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
- const practiceFlag = ref(true);
- const payForm = reactive({
- height: '360px',
- width: '100%',
- practiceDuration: 0,
- evaluateUserCount: 0,
- evaluateFrequency: 0,
- publishUserCount: 0,
- publishCount: 0,
- practiceUserCount: 0,
- paymentAmount: 0,
- practiceDurationAvg: 0,
- practiceDays: 0,
- practiceDurationTotal: 0,
- dateList: [],
- timeList: []
- });
- const state = reactive({
- loading: false,
- pagination: {
- page: 1,
- rows: 10,
- pageTotal: 4
- },
- searchForm: {
- orderBy: null as any,
- sort: null as any,
- },
- tableList: [] as any,
- goCourseVisiable: false
- });
- const currentTimer = computed(() => {
- return props.timer;
- });
- const toolTitleTips = (title: string, item: any) => {
- return <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- {title}
- <img
- class={styles.sortIcon}
- src={
- item.sortOrder === 'descend'
- ? iconSortDesc
- : item.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- item.sortOrder === 'descend'
- ? '点击升序'
- : item.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- }
- const practiceDurationRef = reactive({
- title() {
- return (
- toolTitleTips('练习总时长', practiceDurationRef)
- );
- },
- key: 'practiceDuration',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return <>{formateSeconds((row.practiceDuration as any) || 0)}</>
- }
- });
- const practiceDaysRef = reactive({
- title() {
- return (
- toolTitleTips('练习天数', practiceDaysRef)
- );
- },
- key: 'practiceDays',
- sorter: true,
- sortOrder: false as any
- });
- const practiceDurationAvgRef = reactive({
- title() {
- return (
- toolTitleTips('平均练习时长', practiceDurationAvgRef)
- );
- },
- key: 'practiceDurationAvg',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return <>{formateSeconds((row.practiceDurationAvg as any) || 0)}</>
- }
- });
- const evaluateFrequencyRef = reactive({
- title() {
- return (
- toolTitleTips('评测次数', evaluateFrequencyRef)
- );
- },
- key: 'evaluateFrequency',
- sorter: true,
- sortOrder: false as any
- });
- const publishCountRef = reactive({
- title() {
- return (
- toolTitleTips('作品数量', publishCountRef)
- );
- },
- key: 'publishCount',
- sorter: true,
- sortOrder: false as any
- });
- const publishScoreRef = reactive({
- title() {
- return (
- toolTitleTips('最新作品分数', publishScoreRef)
- );
- },
- key: 'publishScore',
- sorter: true,
- sortOrder: false as any
- });
- const publishTimeRef = reactive({
- title() {
- return (
- toolTitleTips('最新作品时间', publishTimeRef)
- );
- },
- key: 'publishTime',
- sorter: true,
- sortOrder: false as any
- });
- const copyTo = (text: string) => {
- const input = document.createElement('input');
- input.value = text;
- document.body.appendChild(input);
- input.select();
- input.setSelectionRange(0, input.value.length);
- document.execCommand('Copy');
- document.body.removeChild(input);
- message.success('复制成功');
- };
- const columns = () => {
- return [
- {
- title: '学生姓名',
- key: 'studentName',
- render: (row: any) => {
- return (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div
- style={{ userSelect: 'all', cursor: 'pointer' }}
- onClick={() => copyTo(row.studentName)}>
- {row.studentName}
- </div>
- ),
- default: '点击复制'
- }}
- </NTooltip>
- );
- }
- },
- {
- title: '年级班级',
- key: 'date',
- render(row: any) {
- return (
- <>
- {row.currentGradeNum && row.currentClass
- ? convertToChineseNumeral(row.currentGradeNum) + '年级' + row.currentClass + '班'
- : ''}
- </>
- )
- }
- },
- {
- title: '乐器',
- key: 'instrumentName'
- },
- practiceDurationRef,
- practiceDaysRef,
- practiceDurationAvgRef,
- evaluateFrequencyRef,
- {
- title: () => <span style={{ display: 'flex', alignItems: 'center' }}>发布作品 <NTooltip showArrow={false}>
- {{
- trigger: () => (
- <img src={iconQuestion} style={{ width: '16px', height: '16px', marginLeft: '4px', cursor: 'pointer' }} />
- ),
- default: () => '筛选时间段内评测是否发布作品'
- }}
- </NTooltip></span>,
- key: 'publishFlag',
- render: (row: any) => row.publishFlag ? '是' : '否'
- },
- publishCountRef,
- publishScoreRef,
- publishTimeRef,
- {
- title: '操作',
- key: 'titleImg',
- render: (row: any) => (
- <NButton
- type="primary"
- text
- onClick={() => {
- setTabsCaches('evaluatingRcode', 'tabName', {
- path: '/studentDetail'
- });
- router.push({
- path: '/studentDetail',
- query: { studentId: row.studentId, studentName: row.studentName, times: JSON.stringify(currentTimer.value) }
- });
- }}
- >
- 详情
- </NButton>
- )
- }
- ];
- };
- // 统计排序
- const handleSorterChange = (sorter: any) => {
- if (!sorter.order) {
- state.searchForm.orderBy = '' as string
- state.searchForm.sort = '' as string
- practiceDurationRef.sortOrder = false
- practiceDaysRef.sortOrder = false
- practiceDurationAvgRef.sortOrder = false
- evaluateFrequencyRef.sortOrder = false
- publishCountRef.sortOrder = false
- publishScoreRef.sortOrder = false
- publishTimeRef.sortOrder = false
- } else {
- state.searchForm.orderBy = sorter.columnKey
- practiceDurationRef.sortOrder = false
- practiceDaysRef.sortOrder = false
- practiceDurationAvgRef.sortOrder = false
- evaluateFrequencyRef.sortOrder = false
- publishCountRef.sortOrder = false
- publishScoreRef.sortOrder = false
- publishTimeRef.sortOrder = false
- if (sorter.columnKey == 'practiceDuration') {
- practiceDurationRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'practiceDays') {
- practiceDaysRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'practiceDurationAvg') {
- practiceDurationAvgRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'evaluateFrequency') {
- evaluateFrequencyRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'publishCount') {
- publishCountRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'publishScore') {
- publishScoreRef.sortOrder = sorter.order
- }
- if (sorter.columnKey == 'publishTime') {
- publishTimeRef.sortOrder = sorter.order
- }
- state.searchForm.sort = sorter.order == 'ascend' ? 'asc' : 'desc'
- }
- getList2()
- }
- const getList2 = async () => {
- state.loading = true
- try {
- const res = await api_practiceStatPage({
- page: 1,
- rows: 999,
- ...state.searchForm,
- ...getTimes(
- currentTimer.value,
- ['startTime', 'endTime'],
- 'YYYY-MM-DD'
- )
- });
- state.tableList = res.data.rows;
- } catch (e) {
- console.log(e);
- }
- state.loading = false
- };
- const getTestStatList = async () => {
- state.loading = true
- try {
- const res2 = await getTestStat({
- page: 1,
- rows: 999,
- ...getTimes(
- currentTimer.value,
- ['startTime', 'endTime'],
- 'YYYY-MM-DD'
- )
- });
- payForm.dateList = res2.data.trainingStatDetailList.map((item: any) => {
- return item.date;
- });
- payForm.timeList = res2.data.trainingStatDetailList.map((item: any) => {
- return item.practiceUserCount;
- });
- setChart();
- } catch {
- //
- }
- state.loading = false
- }
- const getPracticePageStatList = async () => {
- state.loading = true
- try {
- const {data} = await getPracticePageStat({
- page: 1,
- rows: 999,
- ...getTimes(
- currentTimer.value,
- ['startTime', 'endTime'],
- 'YYYY-MM-DD'
- )
- });
- payForm.practiceDuration = data.practiceDuration;
- payForm.practiceDurationAvg = data.practiceDurationAvg;
- payForm.practiceUserCount = data.practiceUserCount;
- payForm.evaluateUserCount = data.evaluateUserCount
- payForm.evaluateFrequency = data.evaluateFrequency
- payForm.publishUserCount = data.publishUserCount
- payForm.publishCount = data.publishCount
- } catch {
- //
- }
- state.loading = false
- }
- const getList = async () => {
- await getPracticePageStatList()
- await getTestStatList()
- await getList2()
- }
- expose({ getList });
- 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}人'
- },
- axisTick: {
- show: false
- },
- splitArea: {
- show: false,
- areaStyle: {
- color: ['rgba(255,255,255,0.2)']
- }
- },
- minInterval: 1,
- splitNumber: 5
- }
- ],
- grid: {
- left: '1%',
- right: '1%',
- top: '2%',
- bottom: 0,
- containLabel: true
- },
- series: [
- {
- data: payForm.timeList,
- type: 'bar',
- barWidth: '48px',
- itemStyle: {
- normal: {
- //这里设置柱形图圆角 [左上角,右上角,右下角,左下角]
- barBorderRadius: [8, 8, 0, 0],
- color: '#CDE5FF'
- },
- emphasis: {
- focus: 'series',
- color: '#3583FA' //hover时改变柱子颜色
- }
- } as any
- }
- ],
- formatter: (item: any) => {
- if (Array.isArray(item)) {
- return [
- item[0].axisValueLabel,
- ...item.map((d: any) => {
- return `<br/>${d.marker}<span style="margin-top:10px;margin-left:5px;font-size: 13px;font-weight: 500;
- color: #131415;font-weight: 600;
- margin-top:12px
- line-height: 18px;">练习人数: ${d.value}人 </span>`;
- })
- ].join('');
- } else {
- return item;
- }
- }
- });
- };
- getList();
- return () => (
- <>
- <div class={styles.homeTrainData}>
- <div class={styles.TrainDataTop}>
- <div class={styles.TrainDataTopLeft}>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={payForm.practiceUserCount}></NNumberAnimation>
- </span>
- 人
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>练习人数</p>
- </div>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- {getHours(payForm.practiceDurationAvg) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getHours(
- payForm.practiceDurationAvg
- )}></NNumberAnimation>
- </span>
- 时
- </div>
- ) : null}
-
- {getHours(payForm.practiceDurationAvg) > 0 || getLastMinutes(payForm.practiceDurationAvg) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getLastMinutes(
- payForm.practiceDurationAvg
- )}></NNumberAnimation>
- </span>
- 分
- </div>
- ) : null}
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getSecend(
- payForm.practiceDurationAvg
- )}></NNumberAnimation>
- </span>
- 秒
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>平均每天练习时长</p>
- </div>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- {getHours(payForm.practiceDuration) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getHours(
- payForm.practiceDuration
- )}></NNumberAnimation>
- </span>
- 时
- </div>
- ) : null}
- {getHours(payForm.practiceDuration) > 0 || getLastMinutes(payForm.practiceDuration) > 0 ? (
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getLastMinutes(
- payForm.practiceDuration
- )}></NNumberAnimation>
- </span>
- 分
- </div>
- ) : null}
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={getSecend(
- payForm.practiceDuration
- )}></NNumberAnimation>
- </span>
- 秒
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>练习总时长</p>
- </div>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={payForm.evaluateUserCount}></NNumberAnimation>/
- <NNumberAnimation
- from={0}
- to={payForm.evaluateFrequency}></NNumberAnimation>
- </span>
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>评测人数/次数</p>
- </div>
- <div class={styles.TrainDataItem}>
- <p class={styles.TrainDataItemTitle}>
- <div>
- <span>
- <NNumberAnimation
- from={0}
- to={payForm.publishUserCount}></NNumberAnimation>/
- <NNumberAnimation
- from={0}
- to={payForm.publishCount}></NNumberAnimation>
- </span>
- </div>
- </p>
- <p class={styles.TrainDataItemsubTitle}>作品人数/数量</p>
- </div>
- </div>
- <div class={styles.TrainDataTopRight}>
- {/* <div
- onClick={() => {
- practiceFlag.value = !practiceFlag.value;
- setChart();
- }}
- class={[
- styles.DataTopRightItem,
- practiceFlag.value ? '' : styles.DataTopRightItemDis
- ]}>
- <div
- class={[
- styles.DataTopRightDot,
- styles.DataTopRightDotBlue
- ]}></div>
- <p>练习人数</p>
- </div> */}
- </div>
- </div>
- <div class={styles.chatrs}>
- <div
- ref={chartRef}
- style={{ height: payForm.height, width: payForm.width }}></div>
- </div>
- <div class={[styles.tableWrap, styles.noSort]}>
- <NDataTable
- v-slots={{
- empty: () => <TheEmpty></TheEmpty>
- }}
- class={styles.classTable}
- loading={state.loading}
- columns={columns()}
- onUpdate:sorter={handleSorterChange}
- data={state.tableList}></NDataTable>
- {/* <Pagination
- v-model:page={state.pagination.page}
- v-model:pageSize={state.pagination.rows}
- v-model:pageTotal={state.pagination.pageTotal}
- onList={getList}
- sync
- saveKey="orchestraRegistration-key"
- /> */}
- </div>
- </div>
- </>
- );
- }
- });
|