liuyu
21 小时以前 93c133349a5ccd7a328371fa113dce69d5611f21
apps/jnpf-web-apps-main/src/views/x/tms/question/index.vue
@@ -11,14 +11,16 @@
import { Modal } from 'ant-design-vue';
import { deleteQuestion, getQuestionBanks, getQuestionList } from '#/api/x/tms/question';
import { getQuestionBanks, getQuestionList, invalidateQuestion } from '#/api/x/tms/question';
import {
  QUESTION_TYPE_OPTIONS,
  STATUS_OPTIONS,
  labelOfStatus,
  labelOfType,
  loadQuestionDics,
} from './constants';
import { TMS_DIC_FIELD_NAMES } from '#/views/x/tms/shared/dic';
defineOptions({ name: 'TmsQuestionList' });
@@ -53,17 +55,18 @@
  },
];
const [registerTable, { reload, getForm }] = useVxeTable({
const [registerTable, { reload, getForm, getSelectRows }] = useVxeTable({
  api: fetchList,
  columns,
  immediate: true,
  immediate: false,
  rowKey: 'id',
  useSearchForm: true,
  formConfig: {
    baseColProps: { span: 6 },
    compact: true,
    showAdvancedButton: true,
    autoAdvancedLine: 1,
    alwaysShowLines: 1,
    autoAdvancedLine: 4,
    schemas: [
      {
        field: 'bankId',
@@ -84,7 +87,8 @@
          allowClear: true,
          showSearch: true,
          placeholder: '请选择题型',
          options: QUESTION_TYPE_OPTIONS,
          options: QUESTION_TYPE_OPTIONS.value,
          fieldNames: TMS_DIC_FIELD_NAMES,
        },
      },
      {
@@ -95,7 +99,8 @@
          allowClear: true,
          showSearch: true,
          placeholder: '请选择状态',
          options: STATUS_OPTIONS.filter((x) => x.id !== 'invalid'),
          options: STATUS_OPTIONS.value,
          fieldNames: TMS_DIC_FIELD_NAMES,
        },
      },
      {
@@ -114,8 +119,9 @@
      },
    ],
  },
  rowSelection: { type: 'checkbox' },
  actionColumn: {
    width: 100,
    width: 180,
    title: '操作',
    dataIndex: 'action',
    fixed: 'right',
@@ -123,20 +129,55 @@
});
onMounted(async () => {
  banks.value = (await getQuestionBanks()) || [];
  getForm()?.updateSchema?.({
    field: 'bankId',
    componentProps: {
      allowClear: true,
      showSearch: true,
      placeholder: '请选择题库',
      options: banks.value,
  await loadQuestionDics();
  try {
    const list = await getQuestionBanks();
    banks.value = Array.isArray(list) ? list : [];
  } catch {
    banks.value = [];
  }
  getForm()?.updateSchema?.([
    {
      field: 'bankId',
      componentProps: {
        allowClear: true,
        showSearch: true,
        placeholder: '请选择题库',
        options: banks.value,
      },
    },
  });
    {
      field: 'questionType',
      componentProps: {
        allowClear: true,
        showSearch: true,
        placeholder: '请选择题型',
        options: QUESTION_TYPE_OPTIONS.value,
        fieldNames: TMS_DIC_FIELD_NAMES,
      },
    },
    {
      field: 'bizStatus',
      componentProps: {
        allowClear: true,
        showSearch: true,
        placeholder: '请选择状态',
        options: STATUS_OPTIONS.value,
        fieldNames: TMS_DIC_FIELD_NAMES,
      },
    },
  ]);
  reload();
});
async function fetchList(params: Record<string, any>) {
  return { data: await getQuestionList(params) };
  const page = await getQuestionList(params);
  return {
    data: {
      list: Array.isArray(page?.list) ? page.list : [],
      pagination: page?.pagination || { total: 0 },
    },
  };
}
function stripHtml(html?: string) {
@@ -155,31 +196,55 @@
  router.push('/tms/question/create');
}
function handleEdit(record: QuestionEntity) {
  router.push(`/tms/question/edit/${record.id}`);
}
function handleDelete(record: QuestionEntity) {
function handleManage() {
  const rows = (getSelectRows?.() || []) as QuestionEntity[];
  if (!rows.length) {
    createMessage.warning('请先勾选要管理的试题');
    return;
  }
  if (rows.length === 1) {
    handleEdit(rows[0]!);
    return;
  }
  Modal.confirm({
    title: '确认删除',
    content: `确定删除试题「${stripHtml(record.stem) || record.questionNo}」吗?`,
    title: '批量废弃',
    content: `已勾选 ${rows.length} 道试题,确定全部废弃吗?`,
    onOk: async () => {
      await deleteQuestion(record.id!);
      createMessage.success('删除成功');
      for (const row of rows) {
        if (row.id) await invalidateQuestion(row.id);
      }
      createMessage.success('废弃成功');
      reload();
    },
  });
}
function handleDetail(record: QuestionEntity) {
  router.push(`/tms/question/detail/${record.id}`);
}
function handleEdit(record: QuestionEntity) {
  router.push(`/tms/question/edit/${record.id}`);
}
async function handleInvalidate(record: QuestionEntity) {
  await invalidateQuestion(record.id!);
  createMessage.success('废弃成功');
  reload();
}
function getTableActions(record: QuestionEntity): ActionItem[] {
  return [
    { icon: 'icon-ym icon-ym-btn-edit', tooltip: '编辑', onClick: handleEdit.bind(null, record) },
    { label: '编辑', onClick: handleEdit.bind(null, record) },
    {
      icon: 'icon-ym icon-ym-btn-clearn',
      tooltip: '删除',
      label: '废弃',
      color: 'error',
      onClick: handleDelete.bind(null, record),
      modelConfirm: {
        content: `确定废弃试题「${stripHtml(record.stem) || record.questionNo}」吗?废弃后将从列表移除。`,
        onOk: handleInvalidate.bind(null, record),
      },
    },
    { label: '详情', onClick: handleDetail.bind(null, record) },
  ];
}
</script>
@@ -192,7 +257,7 @@
          <template #tableTitle>
            <a-space>
              <a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="handleCreate">创建试题</a-button>
              <a-button disabled>管理试题</a-button>
              <a-button @click="handleManage">管理试题</a-button>
            </a-space>
          </template>
          <template #bizStatus="{ record }">