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:
@@ -263,7 +263,9 @@ export class AdminUserController {
|
||||
continue;
|
||||
}
|
||||
|
||||
await UserModel.create({ name, phone, password });
|
||||
const user = await UserModel.create({ name, phone, password });
|
||||
// 统一规则:新用户默认加入“全体用户”系统组
|
||||
await UserGroupModel.updateUserGroups(user.id, []);
|
||||
imported++;
|
||||
} catch (error: any) {
|
||||
if (error.message === '手机号已存在') {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Request, Response } from 'express';
|
||||
import * as XLSX from 'xlsx';
|
||||
import { UserModel, QuestionModel, QuizModel } from '../models';
|
||||
import { UserModel, QuestionModel, QuizModel, UserGroupModel } from '../models';
|
||||
|
||||
export class BackupController {
|
||||
// 导出用户数据
|
||||
@@ -129,10 +129,12 @@ export class BackupController {
|
||||
if (users && users.length > 0) {
|
||||
for (const user of users) {
|
||||
try {
|
||||
await UserModel.create({
|
||||
const createdUser = await UserModel.create({
|
||||
name: user.姓名 || user.name,
|
||||
phone: user.手机号 || user.phone
|
||||
});
|
||||
// 统一规则:恢复数据创建的用户也必须加入“全体用户”系统组
|
||||
await UserGroupModel.updateUserGroups(createdUser.id, []);
|
||||
restoredCount.users++;
|
||||
} catch (error) {
|
||||
console.log('用户已存在,跳过:', user.手机号 || user.phone);
|
||||
|
||||
@@ -155,7 +155,19 @@ export class QuizController {
|
||||
answer.isCorrect = false;
|
||||
}
|
||||
} else if (question.type === 'single' || question.type === 'judgment') {
|
||||
const isCorrect = answer.userAnswer === question.answer;
|
||||
const normalizeJudgment = (raw: unknown) => {
|
||||
const v = String(raw ?? '').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;
|
||||
};
|
||||
|
||||
const isCorrect =
|
||||
question.type === 'judgment'
|
||||
? normalizeJudgment(answer.userAnswer) === normalizeJudgment(question.answer)
|
||||
: answer.userAnswer === question.answer;
|
||||
answer.score = isCorrect ? question.score : 0;
|
||||
answer.isCorrect = isCorrect;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ export class UserController {
|
||||
|
||||
const existingUser = await UserModel.findByPhone(phone);
|
||||
|
||||
if (existingUser) {
|
||||
if (existingUser) {
|
||||
if (existingUser.password && existingUser.password !== password) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
@@ -118,6 +118,11 @@ export class UserController {
|
||||
});
|
||||
} else {
|
||||
const newUser = await UserModel.create({ name, phone, password });
|
||||
// 自动加入"全体用户"组
|
||||
const allUsersGroup = await UserGroupModel.getSystemGroup();
|
||||
if (allUsersGroup) {
|
||||
await UserGroupModel.addMember(allUsersGroup.id, newUser.id);
|
||||
}
|
||||
res.json({
|
||||
success: true,
|
||||
data: newUser
|
||||
|
||||
Reference in New Issue
Block a user