123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- import { defineComponent, reactive, onMounted, computed, nextTick } from 'vue';
- import styles from '../index2.module.less';
- import { NDataTable, NTooltip } from 'naive-ui';
- import Pagination from '@/components/pagination';
- import { getMinutes, getSecend, getTimes } from '/src/utils/dateFormat';
- import { getTestList } 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';
- export default defineComponent({
- name: 'student-studentList',
- props: {
- timer: {
- type: Array,
- defaut: () => []
- }
- },
- setup(props, { emit, expose }) {
- const state = reactive({
- searchWord: '',
- orchestraType: null,
- courseTypeCode: null,
- subjectId: null,
- classId: null,
- studentType: null,
- loading: false,
- pagination: {
- page: 1,
- rows: 10,
- pageTotal: 4
- },
- tableList: [] as any
- });
- const searchForm = reactive({
- ase: 0,
- sortType: 1
- });
- const currentTimer = computed(() => {
- console.log('ranking===>');
- return props.timer;
- });
- // const search = () => {
- // console.log('search', state);
- // };
- // const onReset = () => {
- // console.log('search');
- // };
- const getList = async () => {
- state.loading = true;
- try {
- const res = await getTestList({
- ...state.pagination,
- ...searchForm,
- ...getTimes(
- currentTimer.value,
- ['startTime', 'endTime'],
- 'YYYY-MM-DD'
- )
- });
- state.tableList = res.data.rows;
- state.pagination.pageTotal = res.data.total;
- } catch (e) {
-
- console.log(e);
- }
- state.loading = false;
- };
- expose({ getList });
- getList()
- onMounted(async () => {
- nextTick(() => {
- // 把默认的排序删除
- const dom = document.querySelectorAll('.n-data-table-sorter');
- dom.forEach((item: any) => {
- item.style.display = 'none';
- });
- });
- });
- const handleSorterChange = (sroter: any) => {
- if (!sroter) {
- searchForm.ase = 0;
- searchForm.sortType = 1;
- practiceDaysRef.sortOrder = false;
- practiceDurationRef.sortOrder = false;
- practiceDurationAvgRef.sortOrder = false;
- } else {
- const list = {
- practiceDuration: 1,
- practiceDays: 2,
- practiceDurationAvg: 3
- };
- searchForm.sortType =
- list[
- sroter.columnKey as
- | 'practiceDuration'
- | 'practiceDays'
- | 'practiceDurationAvg'
- ];
- if (sroter.columnKey == 'practiceDuration') {
- practiceDurationRef.sortOrder = sroter.order;
- practiceDaysRef.sortOrder = false;
- practiceDurationAvgRef.sortOrder = false;
- }
- if (sroter.columnKey == 'practiceDays') {
- practiceDaysRef.sortOrder = sroter.order;
- practiceDurationRef.sortOrder = false;
- practiceDurationAvgRef.sortOrder = false;
- }
- if (sroter.columnKey == 'practiceDurationAvg') {
- practiceDurationAvgRef.sortOrder = sroter.order;
- practiceDaysRef.sortOrder = false;
- practiceDurationRef.sortOrder = false;
- }
- searchForm.ase = sroter.order == 'ascend' ? 1 : 0;
- }
- getList();
- };
- const practiceDaysRef = reactive({
- title() {
- return (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- 练习天数
- <img
- class={styles.sortIcon}
- src={
- practiceDaysRef.sortOrder === 'descend'
- ? iconSortDesc
- : practiceDaysRef.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- practiceDaysRef.sortOrder === 'descend'
- ? '点击升序'
- : practiceDaysRef.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- );
- },
- key: 'practiceDays',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return <>{row.practiceDays ? row.practiceDays : 0}天</>;
- }
- });
- const practiceDurationRef = reactive({
- // title: '练习总时长',
- title() {
- return (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- 练习总时长
- <img
- class={styles.sortIcon}
- src={
- practiceDurationRef.sortOrder === 'descend'
- ? iconSortDesc
- : practiceDurationRef.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- practiceDurationRef.sortOrder === 'descend'
- ? '点击升序'
- : practiceDurationRef.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- );
- },
- key: 'practiceDuration',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return (
- <>
- {row.practiceDuration
- ? getMinutes(row.practiceDuration) > 0
- ? getMinutes(row.practiceDuration) +
- '分' +
- getSecend(row.practiceDuration) +
- '秒'
- : getSecend(row.practiceDuration) + '秒'
- : 0}
- </>
- );
- }
- });
- const practiceDurationAvgRef = reactive({
- // title: '平均练习时长',
- title() {
- return (
- <NTooltip showArrow={false} placement="top-start">
- {{
- trigger: () => (
- <div class={styles.cell}>
- 平均每天练习时长
- <img
- class={styles.sortIcon}
- src={
- practiceDurationAvgRef.sortOrder === 'descend'
- ? iconSortDesc
- : practiceDurationAvgRef.sortOrder === 'ascend'
- ? iconSortAsc
- : iconSortDefault
- }
- />
- </div>
- ),
- default:
- practiceDurationAvgRef.sortOrder === 'descend'
- ? '点击升序'
- : practiceDurationAvgRef.sortOrder === 'ascend'
- ? '取消排序'
- : '点击降序'
- }}
- </NTooltip>
- );
- },
- key: 'practiceDurationAvg',
- sorter: true,
- sortOrder: false as any,
- render(row: any) {
- return (
- <>
- {row.practiceDurationAvg
- ? getMinutes(row.practiceDurationAvg) > 0
- ? getMinutes(row.practiceDurationAvg) +
- '分' +
- getSecend(row.practiceDurationAvg) +
- '秒'
- : getSecend(row.practiceDurationAvg) + '秒'
- : 0}
- </>
- );
- }
- });
- const columns: any = () => {
- return [
- {
- title: '姓名',
- key: 'studentName'
- },
- {
- title: '手机号',
- key: 'studentPhone'
- },
- practiceDaysRef as any,
- practiceDurationRef as any,
- practiceDurationAvgRef as any
- ];
- };
- return () => (
- <div class={styles.listWrap}>
- <div class={styles.tableWrap}>
- <NDataTable
- v-slots={{
- empty: () => <TheEmpty></TheEmpty>
- }}
- class={styles.classTable}
- loading={state.loading}
- columns={columns()}
- data={state.tableList}
- onUpdate:sorter={handleSorterChange}></NDataTable>
- <Pagination
- v-model:page={state.pagination.page}
- v-model:pageSize={state.pagination.rows}
- v-model:pageTotal={state.pagination.pageTotal}
- onList={getList}
- sync
- />
- </div>
- </div>
- );
- }
- });
|