liuyu
22 小时以前 93c133349a5ccd7a328371fa113dce69d5611f21
apps/jnpf-web-apps-main/src/views/x/tms/onlineExam/mock.ts
@@ -6,11 +6,50 @@
  OnlineExamQuestionItem,
} from './types';
import { mockGetQuestion, mockQueryQuestions } from '#/views/x/tms/question/mock';
function delay<T>(data: T, ms = 220): Promise<T> {
  return new Promise((resolve) => setTimeout(() => resolve(data), ms));
}
/** 在线考试 mock 自带样题(不再依赖试题管理 mock) */
const DEMO_QUESTIONS: OnlineExamQuestionItem[] = [
  {
    id: 'demo_q1',
    questionNo: '260001',
    questionType: 'judge',
    stem: '特种作业人员必须取得有效资格证书后方可上岗作业。',
    score: 20,
    options: [
      { optionLabel: 'T', optionContent: '正确', isCorrect: '1' },
      { optionLabel: 'F', optionContent: '错误', isCorrect: '0' },
    ],
  },
  {
    id: 'demo_q2',
    questionNo: '260002',
    questionType: 'multi',
    stem: '下列哪些属于特种设备?',
    score: 20,
    options: [
      { optionLabel: 'A', optionContent: '电梯', isCorrect: '1' },
      { optionLabel: 'B', optionContent: '压力容器', isCorrect: '1' },
      { optionLabel: 'C', optionContent: '普通办公桌', isCorrect: '0' },
      { optionLabel: 'D', optionContent: '锅炉', isCorrect: '1' },
    ],
  },
  {
    id: 'demo_q3',
    questionNo: '260003',
    questionType: 'single',
    stem: 'GMP 的全称是?',
    score: 20,
    options: [
      { optionLabel: 'A', optionContent: '药品生产质量管理规范', isCorrect: '1' },
      { optionLabel: 'B', optionContent: '药品经营质量管理规范', isCorrect: '0' },
      { optionLabel: 'C', optionContent: '实验室管理规范', isCorrect: '0' },
      { optionLabel: 'D', optionContent: '文件管理规范', isCorrect: '0' },
    ],
  },
];
const store: MyPaperListItem[] = [
  {
@@ -89,48 +128,11 @@
  });
}
async function buildQuestions(): Promise<OnlineExamQuestionItem[]> {
  const all = await mockQueryQuestions({ pageSize: 50, currentPage: 1 });
  const list = (all.list || []).filter((q) => ['single', 'multi', 'judge'].includes(q.questionType));
  const picked = list.slice(0, 5);
  const detailed: OnlineExamQuestionItem[] = [];
  for (const q of picked) {
    const full = await mockGetQuestion(q.id!);
    detailed.push({
      id: full.id!,
      questionNo: full.questionNo,
      questionType: full.questionType as 'single' | 'multi' | 'judge',
      stem: full.stem,
      score: 20,
      options: (full.options || []).map((o) => ({
        optionLabel: o.optionLabel,
        optionContent: o.optionContent,
        isCorrect: o.isCorrect,
      })),
    });
  }
  // mock 题不够时补空题避免无法开考
  if (!detailed.length) {
    detailed.push({
      id: 'demo_q1',
      questionType: 'judge',
      stem: '特种作业人员必须取得有效资格证书后方可上岗作业。',
      score: 100,
      options: [
        { optionLabel: 'T', optionContent: '正确', isCorrect: '1' },
        { optionLabel: 'F', optionContent: '错误', isCorrect: '0' },
      ],
    });
  }
  return detailed;
}
export async function mockStartExam(myPaperId: string): Promise<OnlineExamPaper> {
  const row = store.find((x) => x.id === myPaperId);
  if (!row) return Promise.reject(new Error('试卷不存在'));
  if (row.status === 'submitted') return Promise.reject(new Error('该试卷已交卷,无法再次考试'));
  const questions = await buildQuestions();
  const examId = row.examId || `exam_${Date.now()}`;
  row.status = 'doing';
  row.examId = examId;
@@ -142,7 +144,7 @@
    totalScore: row.totalScore,
    passScore: row.passScore,
    durationMin: row.durationMin,
    questions,
    questions: DEMO_QUESTIONS.map((q) => ({ ...q, options: q.options.map((o) => ({ ...o })) })),
  });
}