index.vue 6.4 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">
  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">
  37. <template #default="{ record }">
  38. {{ formatDateTime(record.startTime) }}
  39. </template>
  40. </a-table-column>
  41. <a-table-column title="结束时间" dataIndex="endTime" key="endTime">
  42. <template #default="{ record }">
  43. {{ formatDateTime(record.endTime) }}
  44. </template>
  45. </a-table-column>
  46. <a-table-column title="创建时间" dataIndex="createTime" key="createTime">
  47. <template #default="{ record }">
  48. {{ formatDateTime(record.createTime) }}
  49. </template>
  50. </a-table-column>
  51. <a-table-column title="操作" key="action" align="center" :width="220">
  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" 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="questionnaire" />
  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 '../examinationManagement/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 editId = ref(null)
  105. // 统计分析
  106. const statisticVisible = ref(false)
  107. const statisticTitle = ref('')
  108. const statisticPaperId = ref(null)
  109. const statisticExamName = ref(null)
  110. const queryParam = reactive({
  111. examName: null,
  112. examStatus: null,
  113. pageIndex: 1,
  114. pageSize: 10,
  115. examType: 3
  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. onMounted(() => {
  139. fetchList()
  140. })
  141. const submitForm = () => {
  142. queryParam.pageIndex = 1
  143. fetchList()
  144. }
  145. const onPageChange = (page, pageSize) => {
  146. queryParam.pageIndex = page
  147. queryParam.pageSize = pageSize
  148. fetchList()
  149. }
  150. const onPageSizeChange = (current, size) => {
  151. queryParam.pageIndex = 1
  152. queryParam.pageSize = size
  153. fetchList()
  154. }
  155. const editTask = (record) => {
  156. drawerVisible.value = true
  157. drawerTitle.value = '编辑问卷'
  158. editId.value = record.id
  159. }
  160. const deleteTask = (record) => {
  161. Modal.confirm({
  162. title: '确认删除该考试吗?',
  163. onOk: async () => {
  164. try {
  165. await examManagerApi.deleteExam([{ id: record.id }])
  166. fetchList()
  167. } catch (e) {
  168. message.error(e.msg || '删除失败')
  169. }
  170. }
  171. })
  172. }
  173. const levelFormatter = ({ text }) => {
  174. return enumFormat.value(levelEnum.value, text)
  175. }
  176. const createTask = () => {
  177. drawerVisible.value = true
  178. drawerTitle.value = '创建问卷'
  179. editId.value = null
  180. }
  181. const onEditSuccess = () => {
  182. editId.value = null
  183. drawerVisible.value = false
  184. fetchList()
  185. }
  186. const closeDrawer = () => {
  187. drawerVisible.value = false
  188. }
  189. const formatDateTime = (val) => {
  190. if (!val) return ''
  191. return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
  192. }
  193. const statistic = async (record) => {
  194. statisticVisible.value = true
  195. statisticTitle.value = '答案统计'
  196. console.log('paperName=', record)
  197. statisticExamName.value = record.examName
  198. statisticPaperId.value = record.paperId
  199. }
  200. const closeStatisticDrawer = () => {
  201. statisticVisible.value = false
  202. }
  203. </script>
  204. <style lang="less" scoped>
  205. .task-container {
  206. background: #fff;
  207. padding: 24px;
  208. border-radius: 8px;
  209. }
  210. </style>