ExamList.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="title cl" style="background: #fff">
  3. <span class="y"
  4. >共有<b id="total-count">{{ examList.items.length }}</b
  5. >场考试,请选择</span
  6. >
  7. <h2>考试列表</h2>
  8. </div>
  9. <table cellpadding="0" cellspacing="0" width="100%" class="tablelist">
  10. <thead>
  11. <th>ID</th>
  12. <th>考试名称</th>
  13. <th>创建时间</th>
  14. <th>操作</th>
  15. </thead>
  16. <tbody id="exam-list">
  17. <tr v-for="(exam, index) in showExams.items" :key="index">
  18. <td>{{ exam.id }}</td>
  19. <td>{{ exam.name }}</td>
  20. <td>{{ exam.examTime }}</td>
  21. <td>
  22. <a-button @click="selectExam(exam)">进入考试</a-button>
  23. <a-button @click="downloadImg(exam)">图片下载</a-button>
  24. </td>
  25. </tr>
  26. </tbody>
  27. </table>
  28. <a-pagination
  29. style="margin-top: 20px; float: right"
  30. v-model:current="currentPage"
  31. :total="examList.items.length"
  32. show-less-items
  33. @change="pageChange"
  34. />
  35. </template>
  36. <script setup lang="ts">
  37. import { store } from "@/store";
  38. import { onMounted, reactive, ref } from "vue";
  39. import { getExams } from "@/api/api";
  40. import { useRouter } from "vue-router";
  41. import { Store } from "@/types";
  42. const router = useRouter();
  43. let currentPage = ref(1);
  44. let pageSize = 10;
  45. let examList = reactive({ items: [] as Array<Store["env"]["exam"]> });
  46. let showExams = reactive({ items: [] as Array<Store["env"]["exam"]> });
  47. onMounted(async () => {
  48. await fetchData();
  49. });
  50. const fetchData = async () => {
  51. const exams = await getExams(currentPage.value, 1000);
  52. examList.items = exams.data;
  53. currentPage.value = store.env.pageNumber || 1;
  54. showExams.items = examList.items.slice(
  55. (currentPage.value - 1) * pageSize,
  56. currentPage.value * pageSize
  57. );
  58. };
  59. const pageChange = (page: number, pageSize: number) => {
  60. // console.log(page, pageSize);
  61. currentPage.value = page;
  62. // fetchData();
  63. showExams.items = examList.items.slice(
  64. (page - 1) * pageSize,
  65. page * pageSize
  66. );
  67. };
  68. const selectExam = (exam: Store["env"]["exam"]) => {
  69. store.env.exam = exam;
  70. store.env.examId = exam.id;
  71. router.push("/home");
  72. };
  73. const downloadImg = (exam: Store["env"]["exam"]) => {
  74. store.env.exam = exam;
  75. store.env.examId = exam.id;
  76. store.env.pageNumber = currentPage.value;
  77. router.push("/image-download");
  78. };
  79. </script>