index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <div class="task-container">
  3. <a-form layout="inline" :model="queryParam">
  4. <a-form-item label="考试标题:">
  5. <a-input v-model:value="queryParam.examName" placeholder="请输入考试标题" style="min-width: 200px" allowClear />
  6. </a-form-item>
  7. <a-form-item label="考试状态:">
  8. <a-select style="min-width: 150px" v-model:value="queryParam.examStatus" allowClear placeholder="考试状态">
  9. <a-select-option :value="0">未开始</a-select-option>
  10. <a-select-option :value="1">已开始</a-select-option>
  11. <a-select-option :value="2">已结束</a-select-option>
  12. </a-select>
  13. </a-form-item>
  14. <a-form-item>
  15. <a-button type="primary" @click="submitForm">查询</a-button>
  16. <a-button style="margin-left: 20px" type="primary" @click="createTask">创建考试</a-button>
  17. </a-form-item>
  18. </a-form>
  19. <a-table
  20. :loading="listLoading"
  21. :data-source="tableData"
  22. :pagination="false"
  23. row-key="id"
  24. bordered
  25. style="margin-top: 16px"
  26. >
  27. <a-table-column title="Id" dataIndex="id" key="id" width="100" />
  28. <a-table-column title="考试标题" dataIndex="examName" key="examName" />
  29. <a-table-column title="考试状态" dataIndex="examStatus" key="examStatus" width="120">
  30. <template #default="{ record }">
  31. <a-tag :color="record.examStatus === 0 ? 'default' : record.examStatus === 1 ? 'processing' : 'success'">
  32. {{ record.examStatus === 0 ? '未开始' : record.examStatus === 1 ? '已开始' : '已结束' }}
  33. </a-tag>
  34. </template>
  35. </a-table-column>
  36. <a-table-column title="开始时间" dataIndex="startTime" key="startTime" width="160">
  37. <template #default="{ record }">
  38. {{ formatDateTime(record.startTime) }}
  39. </template>
  40. </a-table-column>
  41. <a-table-column title="结束时间" dataIndex="endTime" key="endTime" width="160">
  42. <template #default="{ record }">
  43. {{ formatDateTime(record.endTime) }}
  44. </template>
  45. </a-table-column>
  46. <a-table-column title="创建时间" dataIndex="createTime" key="createTime" width="160">
  47. <template #default="{ record }">
  48. {{ formatDateTime(record.createTime) }}
  49. </template>
  50. </a-table-column>
  51. <a-table-column title="操作" key="action" align="center" width="160">
  52. <template #default="{ record }">
  53. <a-button size="small" @click="editTask(record)">编辑</a-button>
  54. <a-button size="small" danger style="margin-left: 8px" @click="deleteTask(record)">删除</a-button>
  55. <a-button size="small" type="primary" style="margin-left: 8px" @click="statistic(record)">统计分析</a-button>
  56. </template>
  57. </a-table-column>
  58. </a-table>
  59. <a-pagination
  60. v-show="total > 0"
  61. :total="total"
  62. :current="queryParam.pageIndex"
  63. :pageSize="queryParam.pageSize"
  64. @change="onPageChange"
  65. @showSizeChange="onPageSizeChange"
  66. :showSizeChanger="true"
  67. :pageSizeOptions="['10', '20', '50', '100']"
  68. style="margin-top: 16px; text-align: right"
  69. />
  70. <a-drawer
  71. :visible="drawerVisible"
  72. :title="drawerTitle"
  73. placement="right"
  74. width="900"
  75. @close="closeDrawer"
  76. destroyOnClose
  77. >
  78. <TaskEdit v-if="drawerVisible" :id="editId" @success="onEditSuccess" />
  79. </a-drawer>
  80. <a-modal
  81. :visible="statisticVisible"
  82. :title="statisticTitle"
  83. :footer="null"
  84. width="80%"
  85. @cancel="closeStatisticDrawer"
  86. >
  87. <StatisticAnalysis :paperId="statisticPaperId" :paperName="statisticExamName" examType="exam" />
  88. </a-modal>
  89. </div>
  90. </template>
  91. <script setup>
  92. import { ref, reactive, onMounted } from 'vue'
  93. import { message, Modal } from 'ant-design-vue'
  94. import examManagerApi from '@/api/exam/paper/examManager.js'
  95. import StatisticAnalysis from './StatisticAnalysis.vue'
  96. import TaskEdit from './form.vue'
  97. import { useExamStore } from '@/store/exam.js'
  98. import { storeToRefs } from 'pinia'
  99. import { parseTime } from '@/utils/exam'
  100. const examStore = useExamStore()
  101. const { levelEnum, enumFormat } = storeToRefs(examStore)
  102. const drawerVisible = ref(false)
  103. const drawerTitle = ref('')
  104. const statisticExamName = ref(null)
  105. const editId = ref(null)
  106. // 统计分析
  107. const statisticVisible = ref(false)
  108. const statisticTitle = ref('')
  109. const statisticPaperId = ref(null)
  110. const queryParam = reactive({
  111. examName: null,
  112. examStatus: null,
  113. pageIndex: 1,
  114. pageSize: 10,
  115. examType: 1
  116. })
  117. const listLoading = ref(false)
  118. const tableData = ref([])
  119. const total = ref(0)
  120. const fetchList = async () => {
  121. listLoading.value = true
  122. try {
  123. const params = {
  124. ...queryParam,
  125. current: queryParam.pageIndex,
  126. size: queryParam.pageSize
  127. }
  128. delete params.pageIndex
  129. delete params.pageSize
  130. const data = await examManagerApi.pageList(params)
  131. tableData.value = data.records || []
  132. total.value = data.total || 0
  133. queryParam.pageIndex = data.current || 1
  134. } finally {
  135. listLoading.value = false
  136. }
  137. }
  138. const statistic = async (record) => {
  139. statisticVisible.value = true
  140. statisticTitle.value = '统计分析'
  141. statisticExamName.value = record.examName
  142. statisticPaperId.value = record.paperId
  143. }
  144. const closeStatisticDrawer = () => {
  145. statisticVisible.value = false
  146. }
  147. onMounted(() => {
  148. fetchList()
  149. })
  150. const submitForm = () => {
  151. queryParam.pageIndex = 1
  152. fetchList()
  153. }
  154. const onPageChange = (page, pageSize) => {
  155. queryParam.pageIndex = page
  156. queryParam.pageSize = pageSize
  157. fetchList()
  158. }
  159. const onPageSizeChange = (current, size) => {
  160. queryParam.pageIndex = 1
  161. queryParam.pageSize = size
  162. fetchList()
  163. }
  164. const editTask = (record) => {
  165. drawerVisible.value = true
  166. drawerTitle.value = '编辑考试'
  167. editId.value = record.id
  168. }
  169. const deleteTask = (record) => {
  170. Modal.confirm({
  171. title: '确认删除该考试吗?',
  172. onOk: async () => {
  173. try {
  174. await examManagerApi.deleteExam([{ id: record.id }])
  175. fetchList()
  176. } catch (e) {
  177. message.error(e.msg || '删除失败')
  178. }
  179. }
  180. })
  181. }
  182. const levelFormatter = ({ text }) => {
  183. return enumFormat.value(levelEnum.value, text)
  184. }
  185. const createTask = () => {
  186. drawerVisible.value = true
  187. drawerTitle.value = '创建考试'
  188. editId.value = null
  189. }
  190. const onEditSuccess = () => {
  191. editId.value = null
  192. drawerVisible.value = false
  193. fetchList()
  194. }
  195. const closeDrawer = () => {
  196. drawerVisible.value = false
  197. }
  198. const formatDateTime = (val) => {
  199. if (!val) return ''
  200. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  201. }
  202. </script>
  203. <style lang="less" scoped>
  204. .task-container {
  205. background: #fff;
  206. padding: 24px;
  207. border-radius: 8px;
  208. }
  209. </style>