practiceRanking.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. import { defineComponent, reactive, onMounted, computed, nextTick } from 'vue';
  2. import styles from '../index2.module.less';
  3. import { NDataTable, NTooltip } from 'naive-ui';
  4. import Pagination from '@/components/pagination';
  5. import { getMinutes, getSecend, getTimes } from '/src/utils/dateFormat';
  6. import { getTestList } from '../../classList/api';
  7. import TheEmpty from '/src/components/TheEmpty';
  8. import iconSortDefault from '@/common/images/icon-sort-default.png';
  9. import iconSortDesc from '@/common/images/icon-sort-desc.png';
  10. import iconSortAsc from '@/common/images/icon-sort-asc.png';
  11. export default defineComponent({
  12. name: 'student-studentList',
  13. props: {
  14. timer: {
  15. type: Array,
  16. defaut: () => []
  17. }
  18. },
  19. setup(props, { emit, expose }) {
  20. const state = reactive({
  21. searchWord: '',
  22. orchestraType: null,
  23. courseTypeCode: null,
  24. subjectId: null,
  25. classId: null,
  26. studentType: null,
  27. loading: false,
  28. pagination: {
  29. page: 1,
  30. rows: 10,
  31. pageTotal: 4
  32. },
  33. tableList: [] as any
  34. });
  35. const searchForm = reactive({
  36. ase: 0,
  37. sortType: 1
  38. });
  39. const currentTimer = computed(() => {
  40. console.log('ranking===>');
  41. return props.timer;
  42. });
  43. // const search = () => {
  44. // console.log('search', state);
  45. // };
  46. // const onReset = () => {
  47. // console.log('search');
  48. // };
  49. const getList = async () => {
  50. state.loading = true;
  51. try {
  52. const res = await getTestList({
  53. ...state.pagination,
  54. ...searchForm,
  55. ...getTimes(
  56. currentTimer.value,
  57. ['startTime', 'endTime'],
  58. 'YYYY-MM-DD'
  59. )
  60. });
  61. state.tableList = res.data.rows;
  62. state.pagination.pageTotal = res.data.total;
  63. } catch (e) {
  64. console.log(e);
  65. }
  66. state.loading = false;
  67. };
  68. expose({ getList });
  69. getList()
  70. onMounted(async () => {
  71. nextTick(() => {
  72. // 把默认的排序删除
  73. const dom = document.querySelectorAll('.n-data-table-sorter');
  74. dom.forEach((item: any) => {
  75. item.style.display = 'none';
  76. });
  77. });
  78. });
  79. const handleSorterChange = (sroter: any) => {
  80. if (!sroter) {
  81. searchForm.ase = 0;
  82. searchForm.sortType = 1;
  83. practiceDaysRef.sortOrder = false;
  84. practiceDurationRef.sortOrder = false;
  85. practiceDurationAvgRef.sortOrder = false;
  86. } else {
  87. const list = {
  88. practiceDuration: 1,
  89. practiceDays: 2,
  90. practiceDurationAvg: 3
  91. };
  92. searchForm.sortType =
  93. list[
  94. sroter.columnKey as
  95. | 'practiceDuration'
  96. | 'practiceDays'
  97. | 'practiceDurationAvg'
  98. ];
  99. if (sroter.columnKey == 'practiceDuration') {
  100. practiceDurationRef.sortOrder = sroter.order;
  101. practiceDaysRef.sortOrder = false;
  102. practiceDurationAvgRef.sortOrder = false;
  103. }
  104. if (sroter.columnKey == 'practiceDays') {
  105. practiceDaysRef.sortOrder = sroter.order;
  106. practiceDurationRef.sortOrder = false;
  107. practiceDurationAvgRef.sortOrder = false;
  108. }
  109. if (sroter.columnKey == 'practiceDurationAvg') {
  110. practiceDurationAvgRef.sortOrder = sroter.order;
  111. practiceDaysRef.sortOrder = false;
  112. practiceDurationRef.sortOrder = false;
  113. }
  114. searchForm.ase = sroter.order == 'ascend' ? 1 : 0;
  115. }
  116. getList();
  117. };
  118. const practiceDaysRef = reactive({
  119. title() {
  120. return (
  121. <NTooltip showArrow={false} placement="top-start">
  122. {{
  123. trigger: () => (
  124. <div class={styles.cell}>
  125. 练习天数
  126. <img
  127. class={styles.sortIcon}
  128. src={
  129. practiceDaysRef.sortOrder === 'descend'
  130. ? iconSortDesc
  131. : practiceDaysRef.sortOrder === 'ascend'
  132. ? iconSortAsc
  133. : iconSortDefault
  134. }
  135. />
  136. </div>
  137. ),
  138. default:
  139. practiceDaysRef.sortOrder === 'descend'
  140. ? '点击升序'
  141. : practiceDaysRef.sortOrder === 'ascend'
  142. ? '取消排序'
  143. : '点击降序'
  144. }}
  145. </NTooltip>
  146. );
  147. },
  148. key: 'practiceDays',
  149. sorter: true,
  150. sortOrder: false as any,
  151. render(row: any) {
  152. return <>{row.practiceDays ? row.practiceDays : 0}天</>;
  153. }
  154. });
  155. const practiceDurationRef = reactive({
  156. // title: '练习总时长',
  157. title() {
  158. return (
  159. <NTooltip showArrow={false} placement="top-start">
  160. {{
  161. trigger: () => (
  162. <div class={styles.cell}>
  163. 练习总时长
  164. <img
  165. class={styles.sortIcon}
  166. src={
  167. practiceDurationRef.sortOrder === 'descend'
  168. ? iconSortDesc
  169. : practiceDurationRef.sortOrder === 'ascend'
  170. ? iconSortAsc
  171. : iconSortDefault
  172. }
  173. />
  174. </div>
  175. ),
  176. default:
  177. practiceDurationRef.sortOrder === 'descend'
  178. ? '点击升序'
  179. : practiceDurationRef.sortOrder === 'ascend'
  180. ? '取消排序'
  181. : '点击降序'
  182. }}
  183. </NTooltip>
  184. );
  185. },
  186. key: 'practiceDuration',
  187. sorter: true,
  188. sortOrder: false as any,
  189. render(row: any) {
  190. return (
  191. <>
  192. {row.practiceDuration
  193. ? getMinutes(row.practiceDuration) > 0
  194. ? getMinutes(row.practiceDuration) +
  195. '分' +
  196. getSecend(row.practiceDuration) +
  197. '秒'
  198. : getSecend(row.practiceDuration) + '秒'
  199. : 0}
  200. </>
  201. );
  202. }
  203. });
  204. const practiceDurationAvgRef = reactive({
  205. // title: '平均练习时长',
  206. title() {
  207. return (
  208. <NTooltip showArrow={false} placement="top-start">
  209. {{
  210. trigger: () => (
  211. <div class={styles.cell}>
  212. 平均每天练习时长
  213. <img
  214. class={styles.sortIcon}
  215. src={
  216. practiceDurationAvgRef.sortOrder === 'descend'
  217. ? iconSortDesc
  218. : practiceDurationAvgRef.sortOrder === 'ascend'
  219. ? iconSortAsc
  220. : iconSortDefault
  221. }
  222. />
  223. </div>
  224. ),
  225. default:
  226. practiceDurationAvgRef.sortOrder === 'descend'
  227. ? '点击升序'
  228. : practiceDurationAvgRef.sortOrder === 'ascend'
  229. ? '取消排序'
  230. : '点击降序'
  231. }}
  232. </NTooltip>
  233. );
  234. },
  235. key: 'practiceDurationAvg',
  236. sorter: true,
  237. sortOrder: false as any,
  238. render(row: any) {
  239. return (
  240. <>
  241. {row.practiceDurationAvg
  242. ? getMinutes(row.practiceDurationAvg) > 0
  243. ? getMinutes(row.practiceDurationAvg) +
  244. '分' +
  245. getSecend(row.practiceDurationAvg) +
  246. '秒'
  247. : getSecend(row.practiceDurationAvg) + '秒'
  248. : 0}
  249. </>
  250. );
  251. }
  252. });
  253. const columns: any = () => {
  254. return [
  255. {
  256. title: '姓名',
  257. key: 'studentName'
  258. },
  259. {
  260. title: '手机号',
  261. key: 'studentPhone'
  262. },
  263. practiceDaysRef as any,
  264. practiceDurationRef as any,
  265. practiceDurationAvgRef as any
  266. ];
  267. };
  268. return () => (
  269. <div class={styles.listWrap}>
  270. <div class={styles.tableWrap}>
  271. <NDataTable
  272. v-slots={{
  273. empty: () => <TheEmpty></TheEmpty>
  274. }}
  275. class={styles.classTable}
  276. loading={state.loading}
  277. columns={columns()}
  278. data={state.tableList}
  279. onUpdate:sorter={handleSorterChange}></NDataTable>
  280. <Pagination
  281. v-model:page={state.pagination.page}
  282. v-model:pageSize={state.pagination.rows}
  283. v-model:pageTotal={state.pagination.pageTotal}
  284. onList={getList}
  285. sync
  286. />
  287. </div>
  288. </div>
  289. );
  290. }
  291. });