feat: 更新构建流程,添加 API 构建脚本和 SQL 文件复制脚本

- 修改 package.json,更新构建命令,添加 postbuild 脚本以复制 init.sql 文件。
- 新增 scripts/build-api.mjs,使用 esbuild 构建 API 代码。
- 新增 scripts/copy-init-sql.mjs,复制数据库初始化 SQL 文件到构建输出目录。
- 在 SubjectSelectionPage 组件中添加 totalScore 属性,增加历史最高分状态显示功能。
- 在 ExamSubjectPage 和 QuestionManagePage 中优化判断题答案处理逻辑。
- 在 OptionList 组件中将判断题选项文本从 'T' 和 'F' 改为 '对' 和 '错'。
- 在 QuizFooter 组件中调整样式,增加按钮和文本的可读性。
- 新增用户默认组测试用例,验证新用户创建后自动加入“全体用户”系统组。
- 新增 tsconfig.api.json,配置 API 相关 TypeScript 编译选项。
- 移除 vite.config.ts 中的 global 定义。
This commit is contained in:
2025-12-30 20:33:14 +08:00
parent 1822d8b4da
commit eb4504960e
31 changed files with 10221 additions and 150 deletions

View File

@@ -34,11 +34,28 @@ export interface ExcelQuestionData {
}
export class QuestionModel {
private static normalizeJudgmentAnswer(raw: unknown): string {
const v = String(raw ?? '').trim();
if (!v) return v;
// 兼容历史存储与导入A/B、T/F、true/false、1/0 等
const yes = new Set(['A', 'T', 'TRUE', 'True', 'true', '1', '正确', '对', '是', 'Y', 'y', 'YES', 'yes']);
const no = new Set(['B', 'F', 'FALSE', 'False', 'false', '0', '错误', '错', '否', '不是', 'N', 'n', 'NO', 'no']);
if (yes.has(v)) return '正确';
if (no.has(v)) return '错误';
return v;
}
// 创建题目
static async create(data: CreateQuestionData): Promise<Question> {
const id = uuidv4();
const optionsStr = data.options ? JSON.stringify(data.options) : null;
const answerStr = Array.isArray(data.answer) ? JSON.stringify(data.answer) : data.answer;
const normalizedAnswer =
data.type === 'judgment' && !Array.isArray(data.answer)
? this.normalizeJudgmentAnswer(data.answer)
: data.answer;
const answerStr = Array.isArray(normalizedAnswer) ? JSON.stringify(normalizedAnswer) : normalizedAnswer;
const category = data.category && data.category.trim() ? data.category.trim() : '通用';
const analysis = String(data.analysis ?? '').trim().slice(0, 255);
@@ -71,7 +88,11 @@ export class QuestionModel {
const question = questions[i];
const id = uuidv4();
const optionsStr = question.options ? JSON.stringify(question.options) : null;
const answerStr = Array.isArray(question.answer) ? JSON.stringify(question.answer) : question.answer;
const normalizedAnswer =
question.type === 'judgment' && !Array.isArray(question.answer)
? this.normalizeJudgmentAnswer(question.answer)
: question.answer;
const answerStr = Array.isArray(normalizedAnswer) ? JSON.stringify(normalizedAnswer) : normalizedAnswer;
const category = question.category && question.category.trim() ? question.category.trim() : '通用';
const analysis = String(question.analysis ?? '').trim().slice(0, 255);
@@ -132,7 +153,11 @@ export class QuestionModel {
const question = questions[i];
try {
const optionsStr = question.options ? JSON.stringify(question.options) : null;
const answerStr = Array.isArray(question.answer) ? JSON.stringify(question.answer) : question.answer;
const normalizedAnswer =
question.type === 'judgment' && !Array.isArray(question.answer)
? this.normalizeJudgmentAnswer(question.answer)
: question.answer;
const answerStr = Array.isArray(normalizedAnswer) ? JSON.stringify(normalizedAnswer) : normalizedAnswer;
const category = question.category && question.category.trim() ? question.category.trim() : '通用';
const analysis = String(question.analysis ?? '').trim().slice(0, 255);
@@ -291,7 +316,11 @@ export class QuestionModel {
}
if (data.answer !== undefined) {
const answerStr = Array.isArray(data.answer) ? JSON.stringify(data.answer) : data.answer;
const normalizedAnswer =
data.type === 'judgment' && !Array.isArray(data.answer)
? this.normalizeJudgmentAnswer(data.answer)
: data.answer;
const answerStr = Array.isArray(normalizedAnswer) ? JSON.stringify(normalizedAnswer) : normalizedAnswer;
fields.push('answer = ?');
values.push(answerStr);
}
@@ -353,6 +382,9 @@ export class QuestionModel {
return answerStr;
}
}
if (type === 'judgment') {
return this.normalizeJudgmentAnswer(answerStr);
}
return answerStr;
}

View File

@@ -329,6 +329,14 @@ export class QuizModel {
return answer;
}
}
if (type === 'judgment') {
const v = String(answer ?? '').trim();
const yes = new Set(['A', 'T', 'TRUE', 'True', 'true', '1', '正确', '对', '是', 'Y', 'y', 'YES', 'yes']);
const no = new Set(['B', 'F', 'FALSE', 'False', 'false', '0', '错误', '错', '否', '不是', 'N', 'n', 'NO', 'no']);
if (yes.has(v)) return '正确';
if (no.has(v)) return '错误';
return v;
}
return answer;
}