index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="container">
  3. <a-card class="general-card" title="">
  4. <a-table
  5. row-key="name"
  6. :loading="loading"
  7. :pagination="pagination"
  8. :columns="(cloneColumns as TableColumnData[])"
  9. :data="renderData"
  10. :bordered="false"
  11. :size="size"
  12. @page-change="onPageChange"
  13. >
  14. <template #index="{ rowIndex }">
  15. {{ rowIndex + 1 + (pagination.current - 1) * pagination.pageSize }}
  16. </template>
  17. <template #picture="{ record }">
  18. <div :key="record.id">
  19. <a-image width="40" :src="record.picture" />
  20. </div>
  21. </template>
  22. </a-table>
  23. </a-card>
  24. </div>
  25. </template>
  26. <script lang="ts" name="RecordListPage" setup>
  27. import { computed, ref, reactive, watch, nextTick } from 'vue';
  28. import type { TableColumnData } from '@arco-design/web-vue/es/table/interface';
  29. import { useI18n } from 'vue-i18n';
  30. import useLoading from '@/hooks/loading';
  31. import { Pagination } from '@/types/global';
  32. import { queryRecordList } from '@/api/record';
  33. import type { RecordParams, DataList } from '@/api/record';
  34. import { useIntervalFn } from '@vueuse/core';
  35. interface FaceParams {
  36. pageIndex: number;
  37. personNumber: number;
  38. }
  39. type SizeProps = 'mini' | 'small' | 'medium' | 'large';
  40. type Column = TableColumnData & { checked?: true };
  41. const { loading, setLoading } = useLoading(true);
  42. const { t } = useI18n();
  43. const renderData = ref<DataList[]>([]);
  44. const generateFormModel = () => {
  45. return {
  46. pageIndex: 1,
  47. personNumber: 20,
  48. } as FaceParams;
  49. };
  50. const formModel = ref<FaceParams>(generateFormModel());
  51. const cloneColumns = ref<Column[]>([
  52. {
  53. title: t('recordList.columns.index'),
  54. dataIndex: 'index',
  55. slotName: 'index',
  56. ellipsis: true,
  57. tooltip: true,
  58. width: 60,
  59. },
  60. {
  61. title: t('recordList.columns.time'),
  62. dataIndex: 'time',
  63. ellipsis: true,
  64. tooltip: true,
  65. width: 180,
  66. },
  67. {
  68. title: t('recordList.columns.picture'),
  69. dataIndex: 'picture',
  70. slotName: 'picture',
  71. width: 100,
  72. },
  73. {
  74. title: t('recordList.columns.name'),
  75. dataIndex: 'name',
  76. ellipsis: true,
  77. tooltip: true,
  78. },
  79. {
  80. title: t('recordList.columns.nameCh'),
  81. dataIndex: 'nameCh',
  82. },
  83. {
  84. title: t('recordList.columns.company'),
  85. dataIndex: 'company',
  86. ellipsis: true,
  87. },
  88. {
  89. title: t('recordList.columns.Position'),
  90. dataIndex: 'Position',
  91. ellipsis: true,
  92. tooltip: { position: 'left' },
  93. },
  94. {
  95. title: t('recordList.columns.id'),
  96. dataIndex: 'id',
  97. ellipsis: true,
  98. },
  99. {
  100. title: t('recordList.columns.result'),
  101. dataIndex: 'result',
  102. ellipsis: true,
  103. },
  104. ]);
  105. const size = ref<SizeProps>('medium');
  106. const basePagination: Pagination = {
  107. current: 1,
  108. pageSize: 20,
  109. };
  110. const pagination = reactive({
  111. ...basePagination,
  112. });
  113. const fetchData = async () => {
  114. setLoading(true);
  115. try {
  116. queryRecordList(formModel.value).then(res => {
  117. renderData.value = res.data;
  118. pagination.current = formModel.value.pageIndex;
  119. pagination.pageSize = pagination.pageSize;
  120. pagination.total = res.total;
  121. });
  122. } catch (err) {
  123. // you can report use errorHandler or other
  124. } finally {
  125. setLoading(false);
  126. }
  127. };
  128. fetchData();
  129. const { pause, resume, isActive } = useIntervalFn(() => {
  130. /* your function */
  131. formModel.value.pageIndex = 1;
  132. fetchData();
  133. }, 50000);
  134. const onPageChange = (current: number) => {
  135. formModel.value.pageIndex = current;
  136. fetchData();
  137. };
  138. </script>
  139. <style scoped lang="less">
  140. .container {
  141. padding: 10px;
  142. :deep(.arco-list-content) {
  143. overflow-x: hidden;
  144. }
  145. :deep(.arco-card-meta-title) {
  146. font-size: 14px;
  147. }
  148. .general-card {
  149. padding-top: 10px;
  150. }
  151. }
  152. </style>