123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <template>
- <el-dialog
- v-model="visible"
- title="问题卷分类管理"
- width="800px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- top="10vh"
- append-to-body
- @close="handleClose"
- @open="modalBeforeOpen"
- >
- <div class="issue-type-content">
- <!-- 操作按钮 -->
- <div class="action-bar">
- <el-button type="primary" @click="onAdd">新增</el-button>
- </div>
- <!-- 表格 -->
- <el-table :data="typeList" :loading="loading" class="type-table">
- <el-table-column property="id" label="编号" width="80" />
- <el-table-column property="name" label="分类名称" />
- <el-table-column property="type" label="类型" />
- <el-table-column label="操作" width="120">
- <template #default="scope">
- <el-button size="small" link @click="onEdit(scope.row)">
- 编辑
- </el-button>
- <el-button
- size="small"
- link
- type="danger"
- @click="onDelete(scope.row)"
- >
- 删除
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </div>
- <template #footer> </template>
- </el-dialog>
- <!-- 新增/编辑问题卷分类弹窗 -->
- <ModifyIssuePaperType
- ref="modifyTypeRef"
- :row-data="curRow"
- :exam-id="examId"
- @modified="getTypeList"
- />
- </template>
- <script setup lang="ts">
- import { ref } from 'vue';
- import { ElMessage, ElMessageBox } from 'element-plus';
- import type { IssuePaperTypeItem } from '@/api/types/issue-paper';
- import {
- getIssuePaperTypeList,
- deleteIssuePaperType,
- } from '@/api/issue-paper';
- import useModal from '@/hooks/modal';
- import useLoading from '@/hooks/loading';
- import { modalConfirm } from '@/utils/ui';
- import ModifyIssuePaperType from './ModifyIssuePaperType.vue';
- defineOptions({
- name: 'IssuePaperTypeDialog',
- });
- interface Props {
- examId: number;
- }
- const props = withDefaults(defineProps<Props>(), {
- examId: 0,
- });
- /* modal */
- const { visible, open, close } = useModal();
- defineExpose({ open, close });
- const { loading, setLoading } = useLoading();
- // 问题卷分类列表
- const typeList = ref<IssuePaperTypeItem[]>([]);
- // 获取问题卷分类列表
- async function getTypeList() {
- if (!props.examId) return;
- setLoading(true);
- try {
- const result = await getIssuePaperTypeList(props.examId);
- typeList.value = result;
- } catch (error) {
- console.error('获取问题卷分类列表失败:', error);
- ElMessage.error('获取问题卷分类列表失败');
- } finally {
- setLoading(false);
- }
- }
- // 新增/编辑相关
- const curRow = ref({} as IssuePaperTypeItem);
- const modifyTypeRef = ref();
- function onAdd() {
- curRow.value = {} as IssuePaperTypeItem;
- modifyTypeRef.value?.open();
- }
- function onEdit(row: IssuePaperTypeItem) {
- curRow.value = row;
- modifyTypeRef.value?.open();
- }
- // 删除
- async function onDelete(row: IssuePaperTypeItem) {
- const confirm = await modalConfirm(
- `确定要删除分类"${row.name}"吗?`,
- '删除确认'
- ).catch(() => false);
- if (!confirm) return;
- try {
- setLoading(true);
- await deleteIssuePaperType(row.id);
- ElMessage.success('删除成功');
- getTypeList();
- } catch (error) {
- console.log('删除失败', error);
- } finally {
- setLoading(false);
- }
- }
- const handleClose = () => {
- // 清理数据
- };
- /* init modal */
- function modalBeforeOpen() {
- getTypeList();
- }
- </script>
- <style scoped>
- .issue-type-content {
- min-height: 400px;
- }
- .action-bar {
- margin-bottom: 16px;
- display: flex;
- justify-content: flex-start;
- }
- .type-table {
- width: 100%;
- }
- .dialog-footer {
- display: flex;
- justify-content: flex-end;
- }
- </style>
|