index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <a-card>
  3. <div class="paper-list">
  4. <!-- 任务中心开始 -->
  5. <div class="task-center" style="margin-bottom: 24px">
  6. <h3 style="border-left: solid 4px #3651d4; padding-left: 8px; margin-bottom: 12px; font-size: 18px">
  7. <div>{{ examName }}</div>
  8. </h3>
  9. <a-spin :spinning="taskLoading">
  10. <a-table
  11. ref="paperTableRef"
  12. :columns="taskColumns"
  13. :data-source="taskList"
  14. :expand-row-by-click="true"
  15. :pagination="pagination"
  16. >
  17. <template #bodyCell="{ column, record }">
  18. <template v-if="record.examType && column.key === 'examType'">
  19. {{ examTypeName(record.examType) || '--' }}
  20. </template>
  21. <template v-if="record.startTime && column.key === 'startTime'">
  22. {{ formatDateTime(record.startTime) || '--' }}
  23. </template>
  24. <template v-if="record.endTime && column.key === 'endTime'">
  25. {{ formatDateTime(record.endTime) || '--' }}
  26. </template>
  27. <template v-if="record.paperType && column.key === 'paperType'">
  28. {{ paperTypeEnum(record.paperType) }}
  29. </template>
  30. <template v-if="column.key === 'status'">
  31. <a-tag :color="statusTagFormatter(record.status)" size="small">
  32. {{ statusTextFormatter(record.status) }}
  33. </a-tag>
  34. </template>
  35. <template v-if="column.key === 'action'">
  36. <router-link
  37. v-if="record.status == 0"
  38. :to="{ path: '/student/do', query: { id: record.paperId ? record.paperId : record.id } }"
  39. target="_blank"
  40. >
  41. <a-button type="link" size="small">{{ examType == 4 ? `开始答题` : `填写${examName}` }}</a-button>
  42. </router-link>
  43. <router-link
  44. v-if="record.status == 2"
  45. :to="{ path: '/student/read', query: { id: record.answerId } }"
  46. target="_blank"
  47. >
  48. <a-button type="link" size="small">查看结果</a-button>
  49. </router-link>
  50. </template>
  51. </template>
  52. </a-table>
  53. </a-spin>
  54. </div>
  55. </div>
  56. </a-card>
  57. </template>
  58. <script setup>
  59. import { useExamStore } from '@/store/exam'
  60. import examPaperApi from '@/api/student/examPaper'
  61. import { useRoute } from 'vue-router'
  62. import tool from '@/utils/tool'
  63. import { parseTime } from '@/utils/exam'
  64. import Broadcast from '@/utils/Broadcast.js'
  65. const route = useRoute()
  66. const formatDateTime = (val) => {
  67. if (!val) return ''
  68. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  69. }
  70. // store
  71. const examStore = useExamStore()
  72. const paperTypeEnum = computed(() => {
  73. return (key) => {
  74. return examStore.paperTypeEnum.filter((item) => item.key == key)[0]?.value
  75. }
  76. })
  77. const examNameOption = tool.dictList('EXAM_TYPE')
  78. const examTypeName = computed(() => {
  79. return (id) => {
  80. return examNameOption.filter((r) => r.value == id)[0].label
  81. }
  82. })
  83. const examName = computed(() => {
  84. switch (examType.value) {
  85. case '1':
  86. return '考试'
  87. break
  88. case '2':
  89. return '章节测验'
  90. break
  91. case '3':
  92. return '调查问卷'
  93. break
  94. case '4':
  95. return '我的作业'
  96. break
  97. }
  98. })
  99. // 任务中心相关
  100. const taskList = ref([])
  101. const taskLoading = ref(false)
  102. // 选中表格的表格common
  103. const selectedCommons = [
  104. {
  105. title: '操作',
  106. dataIndex: 'action',
  107. align: 'center',
  108. width: 80
  109. },
  110. {
  111. title: '机构名',
  112. dataIndex: 'name',
  113. ellipsis: true
  114. }
  115. ]
  116. const taskColumns = ref([
  117. { title: '问卷名称', dataIndex: 'examName', key: 'examName' },
  118. { title: '问卷类型', dataIndex: 'examType', key: 'examType', width: 120 },
  119. { title: '开始时间', dataIndex: 'startTime', key: 'startTime', width: 180 },
  120. { title: '结束时间', dataIndex: 'endTime', key: 'endTime', width: 180 },
  121. { title: '状态', dataIndex: 'status', key: 'status', width: 90},
  122. { title: '操作', key: 'action', align: 'right', width: 120}
  123. ])
  124. const statusTextFormatter = (status) => {
  125. if (status === 0) return '未答题'
  126. if (status === 1) return '待判分'
  127. if (status === 2) return '已完成'
  128. return ''
  129. }
  130. const statusTagFormatter = (status) => {
  131. if (status === 2) return 'blue'
  132. if (status === 1) return 'green'
  133. if (status === 0) return 'gray'
  134. return 'default'
  135. }
  136. const getTaskList = async () => {
  137. taskLoading.value = true
  138. try {
  139. let res = []
  140. const params = {
  141. current: pagination.value.current,
  142. size: pagination.value.pageSize,
  143. subjectId: pagination.value.subjectId,
  144. courseId: route.query.id,
  145. paperType: paperType.value,
  146. examType: examType.value
  147. }
  148. res = await examPaperApi.pageExamList(params)
  149. taskList.value = res?.records || []
  150. pagination.value.total = res.total
  151. } catch (e) {
  152. taskList.value = []
  153. }
  154. taskLoading.value = false
  155. }
  156. // 学科分类
  157. const pagination = ref({
  158. current: 1,
  159. pageSize: 10,
  160. onChange: (current) => {
  161. pagination.value.current = current
  162. getTaskList()
  163. }
  164. })
  165. const handleChange = (value) => {
  166. pagination.value.subjectId = value
  167. getTaskList()
  168. }
  169. // lifecycle
  170. const examType = ref()
  171. const paperType = ref(2)
  172. // 监听消息
  173. const stopListening = Broadcast.on('getTaskList', (event) => {
  174. if (event.type == 1) {
  175. getTaskList()
  176. }
  177. })
  178. onMounted(() => {
  179. examType.value = route.params && route.params.examType
  180. getTaskList()
  181. })
  182. onBeforeUnmount(() => {
  183. stopListening()
  184. })
  185. </script>
  186. <style lang="less" scoped>
  187. .paper-list {
  188. margin-top: 10px;
  189. .task-center {
  190. margin-bottom: 24px;
  191. }
  192. }
  193. </style>