feat: 修改部分导入文本的逻辑,添加部署脚本和样式文件,更新数据库迁移逻辑
- 新增部署脚本 `build-deploy-bundle.mjs`,用于构建和部署 web 和 server 目录。 - 新增样式文件 `index-acd65452.css`,包含基础样式和响应式设计。 - 新增脚本 `repro-import-text.mjs`,用于测试文本导入 API。 - 新增测试文件 `db-migration-score-zero.test.ts`,验证历史数据库中 questions.score 约束的迁移逻辑。 - 更新数据库初始化逻辑,允许插入 score=0 的问题。
This commit is contained in:
@@ -313,7 +313,7 @@ const QuizPage = () => {
|
||||
};
|
||||
|
||||
const handleJumpToFirstUnanswered = () => {
|
||||
const firstUnansweredIndex = questions.findIndex(q => !answers[q.id]);
|
||||
const firstUnansweredIndex = questions.findIndex(q => Number(q.score) > 0 && !answers[q.id]);
|
||||
if (firstUnansweredIndex !== -1) {
|
||||
handleJumpTo(firstUnansweredIndex);
|
||||
}
|
||||
@@ -325,7 +325,7 @@ const QuizPage = () => {
|
||||
setSubmitting(true);
|
||||
|
||||
if (!forceSubmit) {
|
||||
const unansweredQuestions = questions.filter(q => !answers[q.id]);
|
||||
const unansweredQuestions = questions.filter(q => Number(q.score) > 0 && !answers[q.id]);
|
||||
if (unansweredQuestions.length > 0) {
|
||||
message.warning(`还有 ${unansweredQuestions.length} 道题未作答`);
|
||||
return;
|
||||
@@ -333,10 +333,11 @@ const QuizPage = () => {
|
||||
}
|
||||
|
||||
const answersData = questions.map(question => {
|
||||
const isCorrect = checkAnswer(question, answers[question.id]);
|
||||
const userAnswer = (answers[question.id] ?? '') as any;
|
||||
const isCorrect = checkAnswer(question, userAnswer);
|
||||
return {
|
||||
questionId: question.id,
|
||||
userAnswer: answers[question.id],
|
||||
userAnswer,
|
||||
score: isCorrect ? question.score : 0,
|
||||
isCorrect
|
||||
};
|
||||
@@ -382,6 +383,7 @@ const QuizPage = () => {
|
||||
};
|
||||
|
||||
const checkAnswer = (question: Question, userAnswer: string | string[]): boolean => {
|
||||
if (Number(question.score) === 0) return true;
|
||||
if (!userAnswer) return false;
|
||||
|
||||
if (question.type === 'multiple') {
|
||||
@@ -395,7 +397,7 @@ const QuizPage = () => {
|
||||
};
|
||||
|
||||
const answeredCount = useMemo(() => {
|
||||
return questions.reduce((count, q) => (answers[q.id] ? count + 1 : count), 0);
|
||||
return questions.reduce((count, q) => (answers[q.id] || Number(q.score) === 0 ? count + 1 : count), 0);
|
||||
}, [questions, answers]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user