| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <template>
- <div class="task-container">
- <a-form layout="inline" :model="queryParam">
- <a-form-item label="问卷名称:">
- <a-input v-model:value="queryParam.examName" placeholder="请输入考试标题" style="min-width: 200px" allowClear />
- </a-form-item>
- <a-form-item label="问卷状态:">
- <a-select style="min-width: 150px" v-model:value="queryParam.examStatus" allowClear placeholder="考试状态">
- <a-select-option :value="0">未开始</a-select-option>
- <a-select-option :value="1">已开始</a-select-option>
- <a-select-option :value="2">已结束</a-select-option>
- </a-select>
- </a-form-item>
- <a-form-item>
- <a-button type="primary" @click="submitForm">查询</a-button>
- <a-button style="margin-left: 20px" type="primary" @click="createTask">创建问卷</a-button>
- </a-form-item>
- </a-form>
- <a-table
- :loading="listLoading"
- :data-source="tableData"
- :pagination="false"
- row-key="id"
- bordered
- style="margin-top: 16px"
- >
- <!-- <a-table-column title="Id" dataIndex="id" key="id" width="100" /> -->
- <a-table-column title="问卷名称" dataIndex="examName" key="examName" />
- <a-table-column title="问卷状态" dataIndex="examStatus" key="examStatus">
- <template #default="{ record }">
- <a-tag :color="record.examStatus === 0 ? 'default' : record.examStatus === 1 ? 'processing' : 'success'">
- {{ record.examStatus === 0 ? '未开始' : record.examStatus === 1 ? '已开始' : '已结束' }}
- </a-tag>
- </template>
- </a-table-column>
- <a-table-column title="开始时间" dataIndex="startTime" key="startTime">
- <template #default="{ record }">
- {{ formatDateTime(record.startTime) }}
- </template>
- </a-table-column>
- <a-table-column title="结束时间" dataIndex="endTime" key="endTime">
- <template #default="{ record }">
- {{ formatDateTime(record.endTime) }}
- </template>
- </a-table-column>
- <a-table-column title="创建时间" dataIndex="createTime" key="createTime">
- <template #default="{ record }">
- {{ formatDateTime(record.createTime) }}
- </template>
- </a-table-column>
- <a-table-column title="操作" key="action" align="center" :width="220">
- <template #default="{ record }">
- <a-button size="small" @click="editTask(record)">编辑</a-button>
- <a-button size="small" danger style="margin-left: 8px" @click="deleteTask(record)">删除</a-button>
- <a-button size="small" style="margin-left: 8px" @click="statistic(record)">答案统计</a-button>
- </template>
- </a-table-column>
- </a-table>
- <a-pagination
- v-show="total > 0"
- :total="total"
- :current="queryParam.pageIndex"
- :pageSize="queryParam.pageSize"
- @change="onPageChange"
- @showSizeChange="onPageSizeChange"
- :showSizeChanger="true"
- :pageSizeOptions="['10', '20', '50', '100']"
- style="margin-top: 16px; text-align: right"
- />
- <a-drawer
- :visible="drawerVisible"
- :title="drawerTitle"
- placement="right"
- width="900"
- @close="closeDrawer"
- destroyOnClose
- >
- <TaskEdit v-if="drawerVisible" :id="editId" @success="onEditSuccess" />
- </a-drawer>
- <a-modal
- :visible="statisticVisible"
- :title="statisticTitle"
- :footer="null"
- width="80%"
- @cancel="closeStatisticDrawer"
- >
- <StatisticAnalysis :paperId="statisticPaperId" :paperName="statisticExamName" examType="questionnaire" />
- </a-modal>
- </div>
- </template>
- <script setup>
- import { ref, reactive, onMounted } from 'vue'
- import { message, Modal } from 'ant-design-vue'
- import examManagerApi from '@/api/exam/paper/examManager.js'
- import StatisticAnalysis from '../examinationManagement/StatisticAnalysis.vue'
- import TaskEdit from './form.vue'
- import { useExamStore } from '@/store/exam.js'
- import { storeToRefs } from 'pinia'
- import { parseTime } from '@/utils/exam'
- const examStore = useExamStore()
- const { levelEnum, enumFormat } = storeToRefs(examStore)
- const drawerVisible = ref(false)
- const drawerTitle = ref('')
- const editId = ref(null)
- // 统计分析
- const statisticVisible = ref(false)
- const statisticTitle = ref('')
- const statisticPaperId = ref(null)
- const statisticExamName = ref(null)
- const queryParam = reactive({
- examName: null,
- examStatus: null,
- pageIndex: 1,
- pageSize: 10,
- examType: 3
- })
- const listLoading = ref(false)
- const tableData = ref([])
- const total = ref(0)
- const fetchList = async () => {
- listLoading.value = true
- try {
- const params = {
- ...queryParam,
- current: queryParam.pageIndex,
- size: queryParam.pageSize
- }
- delete params.pageIndex
- delete params.pageSize
- const data = await examManagerApi.pageList(params)
- tableData.value = data.records || []
- total.value = data.total || 0
- queryParam.pageIndex = data.current || 1
- } finally {
- listLoading.value = false
- }
- }
- onMounted(() => {
- fetchList()
- })
- const submitForm = () => {
- queryParam.pageIndex = 1
- fetchList()
- }
- const onPageChange = (page, pageSize) => {
- queryParam.pageIndex = page
- queryParam.pageSize = pageSize
- fetchList()
- }
- const onPageSizeChange = (current, size) => {
- queryParam.pageIndex = 1
- queryParam.pageSize = size
- fetchList()
- }
- const editTask = (record) => {
- drawerVisible.value = true
- drawerTitle.value = '编辑问卷'
- editId.value = record.id
- }
- const deleteTask = (record) => {
- Modal.confirm({
- title: '确认删除该考试吗?',
- onOk: async () => {
- try {
- await examManagerApi.deleteExam([{ id: record.id }])
- fetchList()
- } catch (e) {
- message.error(e.msg || '删除失败')
- }
- }
- })
- }
- const levelFormatter = ({ text }) => {
- return enumFormat.value(levelEnum.value, text)
- }
- const createTask = () => {
- drawerVisible.value = true
- drawerTitle.value = '创建问卷'
- editId.value = null
- }
- const onEditSuccess = () => {
- editId.value = null
- drawerVisible.value = false
- fetchList()
- }
- const closeDrawer = () => {
- drawerVisible.value = false
- }
- const formatDateTime = (val) => {
- if (!val) return ''
- return parseTime(val, '{y}-{m}-{d} {h}:{i}:{s}')
- }
- const statistic = async (record) => {
- statisticVisible.value = true
- statisticTitle.value = '答案统计'
- console.log('paperName=', record)
- statisticExamName.value = record.examName
- statisticPaperId.value = record.paperId
- }
- const closeStatisticDrawer = () => {
- statisticVisible.value = false
- }
- </script>
- <style lang="less" scoped>
- .task-container {
- background: #fff;
- padding: 24px;
- border-radius: 8px;
- }
- </style>
|