index.vue 4.0 KB

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