practiceRanking.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { defineComponent, reactive } from 'vue';
  2. import styles from '../index.module.less';
  3. import {
  4. NButton,
  5. NDataTable,
  6. NForm,
  7. NFormItem,
  8. NImage,
  9. NSelect,
  10. NSpace
  11. } from 'naive-ui';
  12. import SearchInput from '@/components/searchInput';
  13. import CSelect from '@/components/CSelect';
  14. import Pagination from '@/components/pagination';
  15. import add from './images/add.png';
  16. import { getMinutes, getSecend, getTimes } from '/src/utils/dateFormat';
  17. import { getTestList } from '../../classList/api';
  18. export default defineComponent({
  19. name: 'student-studentList',
  20. props: {
  21. timer: {
  22. type: Array,
  23. defaut: () => []
  24. }
  25. },
  26. setup(props, { emit, expose }) {
  27. const state = reactive({
  28. searchWord: '',
  29. orchestraType: null,
  30. courseTypeCode: null,
  31. subjectId: null,
  32. classId: null,
  33. studentType: null,
  34. loading: false,
  35. pagination: {
  36. page: 1,
  37. rows: 10,
  38. pageTotal: 4
  39. },
  40. tableList: [] as any
  41. });
  42. const search = () => {
  43. console.log('search', state);
  44. };
  45. const onReset = () => {
  46. console.log('search');
  47. };
  48. const getList = async () => {
  49. state.loading = true;
  50. try {
  51. const res = await getTestList({
  52. ...state.pagination,
  53. ...getTimes(props.timer, ['startTime', 'endTime'], 'YYYY-MM-DD')
  54. });
  55. state.tableList = res.data.rows;
  56. state.pagination.pageTotal = res.data.total;
  57. state.loading = false;
  58. } catch (e) {
  59. state.loading = false;
  60. console.log(e);
  61. }
  62. };
  63. expose({ getList });
  64. const handleSorterChange = (sroter: any) => {
  65. if(!sroter){
  66. practiceDaysRef.sortOrder = false
  67. practiceDurationRef.sortOrder = false
  68. practiceDurationAvgRef.sortOrder = false
  69. }
  70. console.log(sroter, 'sroter');
  71. // getList()
  72. };
  73. const practiceDaysRef = reactive({
  74. title: '练习天数',
  75. key: 'practiceDays',
  76. sorter: true,
  77. sortOrder: false,
  78. render(row: any) {
  79. return <>{row.practiceDays ? row.practiceDays : 0}天</>;
  80. }
  81. });
  82. const practiceDurationRef = reactive({
  83. title: '练习总时长',
  84. key: 'practiceDuration',
  85. sorter: true,
  86. sortOrder: false,
  87. render(row: any) {
  88. return (
  89. <>
  90. {row.practiceDuration
  91. ? getMinutes(row.practiceDuration) > 0
  92. ? getMinutes(row.practiceDuration) +
  93. '分' +
  94. getSecend(row.practiceDuration) +
  95. '秒'
  96. : getSecend(row.practiceDuration) + '秒'
  97. : 0}
  98. </>
  99. );
  100. }
  101. });
  102. const practiceDurationAvgRef = reactive({
  103. title: '平均练习时长',
  104. key: 'practiceDurationAvg',
  105. sorter: true,
  106. sortOrder: false,
  107. render(row: any) {
  108. return (
  109. <>
  110. {row.practiceDurationAvg
  111. ? getMinutes(row.practiceDurationAvg) > 0
  112. ? getMinutes(row.practiceDurationAvg) +
  113. '分' +
  114. getSecend(row.practiceDurationAvg) +
  115. '秒'
  116. : getSecend(row.practiceDurationAvg) + '秒'
  117. : 0}
  118. </>
  119. );
  120. }
  121. });
  122. const columns = () => {
  123. return [
  124. {
  125. title: '姓名',
  126. key: 'studentName'
  127. },
  128. {
  129. title: '手机号',
  130. key: 'studentPhone'
  131. },
  132. practiceDaysRef,
  133. practiceDurationRef,
  134. practiceDurationAvgRef
  135. ];
  136. };
  137. return () => (
  138. <div class={styles.listWrap}>
  139. <div class={styles.tableWrap}>
  140. <NDataTable
  141. class={styles.classTable}
  142. loading={state.loading}
  143. columns={columns()}
  144. data={state.tableList}
  145. onUpdate:sorter={handleSorterChange}></NDataTable>
  146. <Pagination
  147. v-model:page={state.pagination.page}
  148. v-model:pageSize={state.pagination.rows}
  149. v-model:pageTotal={state.pagination.pageTotal}
  150. onList={getList}
  151. sync
  152. saveKey="orchestraRegistration-key"
  153. />
  154. </div>
  155. </div>
  156. );
  157. }
  158. });