index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div style="margin-top: 10px" class="app-contain">
  3. <a-row :gutter="50">
  4. <a-col :span="14">
  5. <a-table
  6. :loading="listLoading"
  7. :data-source="tableData"
  8. :columns="columns"
  9. row-key="id"
  10. :custom-row="customRow"
  11. :pagination="false"
  12. >
  13. </a-table>
  14. <a-pagination
  15. v-if="total > 0"
  16. :total="total"
  17. :current="queryParam.pageIndex"
  18. :page-size="queryParam.pageSize"
  19. @change="onPageChange"
  20. @showSizeChange="onPageSizeChange"
  21. :show-size-changer="true"
  22. :page-size-options="['10', '20', '50', '100']"
  23. style="margin-top: 20px"
  24. />
  25. </a-col>
  26. <a-col :span="10">
  27. <a-card class="record-answer-info">
  28. <a-form layout="vertical">
  29. <a-form-item>
  30. <QuestionAnswerShow
  31. :qType="selectItem.questionType"
  32. :qLoading="qAnswerLoading"
  33. :question="selectItem.questionItem"
  34. :answer="selectItem.answerItem"
  35. />
  36. </a-form-item>
  37. </a-form>
  38. </a-card>
  39. </a-col>
  40. </a-row>
  41. </div>
  42. </template>
  43. <script setup>
  44. import { ref, reactive, onMounted } from 'vue'
  45. import { useExamStore } from '@/store/exam'
  46. import examPaperAnswerApi from '@/api/student/questionAnswer'
  47. import QuestionAnswerShow from '../exam/components/QuestionAnswerShow.vue'
  48. import { parseTime } from '@/utils/exam'
  49. const examStore = useExamStore()
  50. const queryParam = reactive({
  51. pageIndex: 1,
  52. pageSize: 10
  53. })
  54. const listLoading = ref(false)
  55. const tableData = ref([])
  56. const total = ref(0)
  57. const qAnswerLoading = ref(false)
  58. const selectItem = reactive({
  59. questionType: 0,
  60. questionItem: null,
  61. answerItem: null
  62. })
  63. const columns = [
  64. { title: '题干', dataIndex: 'shortTitle', key: 'shortTitle', ellipsis: true },
  65. {
  66. title: '题型',
  67. dataIndex: 'questionType',
  68. key: 'questionType',
  69. width: 90,
  70. customRender: ({ text }) => questionTypeFormatter(text)
  71. },
  72. { title: '学科', dataIndex: 'subjectName', key: 'subjectName', width: 90 },
  73. {
  74. title: '做题时间',
  75. dataIndex: 'createTime',
  76. key: 'createTime',
  77. width: 200,
  78. customRender: ({ text }) => formatDateTime(text)
  79. }
  80. ]
  81. function search() {
  82. listLoading.value = true
  83. const params = { ...queryParam, current: queryParam.pageIndex, size: queryParam.pageSize }
  84. delete params.pageIndex
  85. delete params.pageSize
  86. examPaperAnswerApi
  87. .pageList(params)
  88. .then((data) => {
  89. const re = data
  90. tableData.value = re.records
  91. total.value = re.total
  92. queryParam.pageIndex = re.current
  93. listLoading.value = false
  94. if (re.records && re.records.length !== 0) {
  95. qAnswerShow(re.records[0].id)
  96. }
  97. })
  98. .catch(() => {
  99. listLoading.value = false
  100. })
  101. }
  102. function formatDateTime(val) {
  103. if (!val) return ''
  104. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  105. }
  106. function customRow(record) {
  107. return {
  108. onClick: () => itemSelect(record)
  109. }
  110. }
  111. function itemSelect(record) {
  112. qAnswerShow(record.id)
  113. }
  114. function qAnswerShow(id) {
  115. qAnswerLoading.value = true
  116. examPaperAnswerApi.select(id).then((re) => {
  117. let response = re
  118. selectItem.questionType = response.questionVM.questionType
  119. selectItem.questionItem = response.questionVM
  120. selectItem.answerItem = response.questionAnswerVM
  121. qAnswerLoading.value = false
  122. })
  123. }
  124. function questionTypeFormatter(type) {
  125. return examStore.enumFormat(examStore.exam.question.typeEnum, type)
  126. }
  127. function onPageChange(page, pageSize) {
  128. queryParam.pageIndex = page
  129. queryParam.pageSize = pageSize
  130. search()
  131. }
  132. function onPageSizeChange(current, size) {
  133. queryParam.pageIndex = 1
  134. queryParam.pageSize = size
  135. search()
  136. }
  137. onMounted(() => {
  138. search()
  139. })
  140. </script>
  141. <style lang="less" scoped>
  142. .app-contain {
  143. // 可根据需要自定义样式
  144. }
  145. .record-answer-info {
  146. margin-top: 20px;
  147. }
  148. </style>