index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. </template>
  56. </a-table-column>
  57. </a-table>
  58. <a-pagination
  59. v-show="total > 0"
  60. :total="total"
  61. :current="queryParam.pageIndex"
  62. :pageSize="queryParam.pageSize"
  63. @change="onPageChange"
  64. @showSizeChange="onPageSizeChange"
  65. :showSizeChanger="true"
  66. :pageSizeOptions="['10', '20', '50', '100']"
  67. style="margin-top: 16px; text-align: right"
  68. />
  69. <a-drawer
  70. :visible="drawerVisible"
  71. :title="drawerTitle"
  72. placement="right"
  73. width="900"
  74. @close="closeDrawer"
  75. destroyOnClose
  76. >
  77. <TaskEdit v-if="drawerVisible" :id="editId" @success="onEditSuccess" />
  78. </a-drawer>
  79. </div>
  80. </template>
  81. <script setup>
  82. import { ref, reactive, onMounted } from 'vue'
  83. import { message, Modal } from 'ant-design-vue'
  84. import examManagerApi from '@/api/exam/paper/examManager.js'
  85. import TaskEdit from './form.vue'
  86. import { useExamStore } from '@/store/exam.js'
  87. import { storeToRefs } from 'pinia'
  88. import { parseTime } from '@/utils/exam'
  89. const examStore = useExamStore()
  90. const { levelEnum, enumFormat } = storeToRefs(examStore)
  91. const drawerVisible = ref(false)
  92. const drawerTitle = ref('')
  93. const editId = ref(null)
  94. const queryParam = reactive({
  95. examName: null,
  96. examStatus: null,
  97. pageIndex: 1,
  98. pageSize: 10
  99. })
  100. const listLoading = ref(false)
  101. const tableData = ref([])
  102. const total = ref(0)
  103. const fetchList = async () => {
  104. listLoading.value = true
  105. try {
  106. const params = {
  107. ...queryParam,
  108. current: queryParam.pageIndex,
  109. size: queryParam.pageSize
  110. }
  111. delete params.pageIndex
  112. delete params.pageSize
  113. const data = await examManagerApi.pageList(params)
  114. tableData.value = data.records || []
  115. total.value = data.total || 0
  116. queryParam.pageIndex = data.current || 1
  117. } finally {
  118. listLoading.value = false
  119. }
  120. }
  121. onMounted(() => {
  122. fetchList()
  123. })
  124. const submitForm = () => {
  125. queryParam.pageIndex = 1
  126. fetchList()
  127. }
  128. const onPageChange = (page, pageSize) => {
  129. queryParam.pageIndex = page
  130. queryParam.pageSize = pageSize
  131. fetchList()
  132. }
  133. const onPageSizeChange = (current, size) => {
  134. queryParam.pageIndex = 1
  135. queryParam.pageSize = size
  136. fetchList()
  137. }
  138. const editTask = (record) => {
  139. drawerVisible.value = true
  140. drawerTitle.value = '编辑考试'
  141. editId.value = record.id
  142. }
  143. const deleteTask = (record) => {
  144. Modal.confirm({
  145. title: '确认删除该考试吗?',
  146. onOk: async () => {
  147. try {
  148. await examManagerApi.deleteExam([{ id: record.id }])
  149. message.success('删除成功')
  150. fetchList()
  151. } catch (e) {
  152. message.error(e.msg || '删除失败')
  153. }
  154. }
  155. })
  156. }
  157. const levelFormatter = ({ text }) => {
  158. return enumFormat.value(levelEnum.value, text)
  159. }
  160. const createTask = () => {
  161. drawerVisible.value = true
  162. drawerTitle.value = '创建考试'
  163. editId.value = null
  164. }
  165. const onEditSuccess = () => {
  166. editId.value = null
  167. drawerVisible.value = false
  168. fetchList()
  169. }
  170. const closeDrawer = () => {
  171. drawerVisible.value = false
  172. }
  173. const formatDateTime = (val) => {
  174. if (!val) return ''
  175. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  176. }
  177. </script>
  178. <style lang="less" scoped>
  179. .task-container {
  180. background: #fff;
  181. padding: 24px;
  182. border-radius: 8px;
  183. }
  184. </style>