practiceRanking.tsx 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. state.loading = false;
  64. } catch (e) {
  65. state.loading = false;
  66. console.log(e);
  67. }
  68. };
  69. expose({ getList });
  70. onMounted(async () => {
  71. await getList();
  72. nextTick(() => {
  73. // 把默认的排序删除
  74. const dom = document.querySelectorAll('.n-data-table-sorter');
  75. dom.forEach((item: any) => {
  76. item.style.display = 'none';
  77. });
  78. });
  79. });
  80. const handleSorterChange = (sroter: any) => {
  81. console.log(sroter, '12');
  82. if (!sroter) {
  83. searchForm.ase = 0;
  84. searchForm.sortType = 1;
  85. practiceDaysRef.sortOrder = false;
  86. practiceDurationRef.sortOrder = false;
  87. practiceDurationAvgRef.sortOrder = false;
  88. } else {
  89. const list = {
  90. practiceDuration: 1,
  91. practiceDays: 2,
  92. practiceDurationAvg: 3
  93. };
  94. searchForm.sortType =
  95. list[
  96. sroter.columnKey as
  97. | 'practiceDuration'
  98. | 'practiceDays'
  99. | 'practiceDurationAvg'
  100. ];
  101. if (sroter.columnKey == 'practiceDuration') {
  102. practiceDurationRef.sortOrder = sroter.order;
  103. practiceDaysRef.sortOrder = false;
  104. practiceDurationAvgRef.sortOrder = false;
  105. }
  106. if (sroter.columnKey == 'practiceDays') {
  107. practiceDaysRef.sortOrder = sroter.order;
  108. practiceDurationRef.sortOrder = false;
  109. practiceDurationAvgRef.sortOrder = false;
  110. }
  111. if (sroter.columnKey == 'practiceDurationAvg') {
  112. practiceDurationAvgRef.sortOrder = sroter.order;
  113. practiceDaysRef.sortOrder = false;
  114. practiceDurationRef.sortOrder = false;
  115. }
  116. searchForm.ase = sroter.order == 'ascend' ? 1 : 0;
  117. }
  118. getList();
  119. };
  120. const practiceDaysRef = reactive({
  121. title() {
  122. return (
  123. <NTooltip showArrow={false} placement="top-start">
  124. {{
  125. trigger: () => (
  126. <div class={styles.cell}>
  127. 练习天数
  128. <img
  129. class={styles.sortIcon}
  130. src={
  131. practiceDaysRef.sortOrder === 'descend'
  132. ? iconSortDesc
  133. : practiceDaysRef.sortOrder === 'ascend'
  134. ? iconSortAsc
  135. : iconSortDefault
  136. }
  137. />
  138. </div>
  139. ),
  140. default:
  141. practiceDaysRef.sortOrder === 'descend'
  142. ? '点击升序'
  143. : practiceDaysRef.sortOrder === 'ascend'
  144. ? '取消排序'
  145. : '点击降序'
  146. }}
  147. </NTooltip>
  148. );
  149. },
  150. key: 'practiceDays',
  151. sorter: true,
  152. sortOrder: false as any,
  153. render(row: any) {
  154. return <>{row.practiceDays ? row.practiceDays : 0}天</>;
  155. }
  156. });
  157. const practiceDurationRef = reactive({
  158. // title: '练习总时长',
  159. title() {
  160. return (
  161. <NTooltip showArrow={false} placement="top-start">
  162. {{
  163. trigger: () => (
  164. <div class={styles.cell}>
  165. 练习总时长
  166. <img
  167. class={styles.sortIcon}
  168. src={
  169. practiceDurationRef.sortOrder === 'descend'
  170. ? iconSortDesc
  171. : practiceDurationRef.sortOrder === 'ascend'
  172. ? iconSortAsc
  173. : iconSortDefault
  174. }
  175. />
  176. </div>
  177. ),
  178. default:
  179. practiceDaysRef.sortOrder === 'descend'
  180. ? '点击升序'
  181. : practiceDaysRef.sortOrder === 'ascend'
  182. ? '取消排序'
  183. : '点击降序'
  184. }}
  185. </NTooltip>
  186. );
  187. },
  188. key: 'practiceDuration',
  189. sorter: true,
  190. sortOrder: false as any,
  191. render(row: any) {
  192. return (
  193. <>
  194. {row.practiceDuration
  195. ? getMinutes(row.practiceDuration) > 0
  196. ? getMinutes(row.practiceDuration) +
  197. '分' +
  198. getSecend(row.practiceDuration) +
  199. '秒'
  200. : getSecend(row.practiceDuration) + '秒'
  201. : 0}
  202. </>
  203. );
  204. }
  205. });
  206. const practiceDurationAvgRef = reactive({
  207. // title: '平均练习时长',
  208. title() {
  209. return (
  210. <NTooltip showArrow={false} placement="top-start">
  211. {{
  212. trigger: () => (
  213. <div class={styles.cell}>
  214. 平均练习时长
  215. <img
  216. class={styles.sortIcon}
  217. src={
  218. practiceDurationAvgRef.sortOrder === 'descend'
  219. ? iconSortDesc
  220. : practiceDurationAvgRef.sortOrder === 'ascend'
  221. ? iconSortAsc
  222. : iconSortDefault
  223. }
  224. />
  225. </div>
  226. ),
  227. default:
  228. practiceDaysRef.sortOrder === 'descend'
  229. ? '点击升序'
  230. : practiceDaysRef.sortOrder === 'ascend'
  231. ? '取消排序'
  232. : '点击降序'
  233. }}
  234. </NTooltip>
  235. );
  236. },
  237. key: 'practiceDurationAvg',
  238. sorter: true,
  239. sortOrder: false as any,
  240. render(row: any) {
  241. return (
  242. <>
  243. {row.practiceDurationAvg
  244. ? getMinutes(row.practiceDurationAvg) > 0
  245. ? getMinutes(row.practiceDurationAvg) +
  246. '分' +
  247. getSecend(row.practiceDurationAvg) +
  248. '秒'
  249. : getSecend(row.practiceDurationAvg) + '秒'
  250. : 0}
  251. </>
  252. );
  253. }
  254. });
  255. const columns: any = () => {
  256. return [
  257. {
  258. title: '姓名',
  259. key: 'studentName'
  260. },
  261. {
  262. title: '手机号',
  263. key: 'studentPhone'
  264. },
  265. practiceDaysRef as any,
  266. practiceDurationRef as any,
  267. practiceDurationAvgRef as any
  268. ];
  269. };
  270. return () => (
  271. <div class={styles.listWrap}>
  272. <div class={styles.tableWrap}>
  273. <NDataTable
  274. v-slots={{
  275. empty: () => <TheEmpty></TheEmpty>
  276. }}
  277. class={styles.classTable}
  278. loading={state.loading}
  279. columns={columns()}
  280. data={state.tableList}
  281. onUpdate:sorter={handleSorterChange}></NDataTable>
  282. <Pagination
  283. v-model:page={state.pagination.page}
  284. v-model:pageSize={state.pagination.rows}
  285. v-model:pageTotal={state.pagination.pageTotal}
  286. onList={getList}
  287. sync
  288. />
  289. </div>
  290. </div>
  291. );
  292. }
  293. });