From 60c2cd1406e113d2070a8783668b8ca5371126ee Mon Sep 17 00:00:00 2001 From: yanlongqi Date: Sat, 8 Nov 2025 06:38:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=96=B0=E5=BB=BA=E9=A2=98=E7=9B=AE=E6=97=B6?= =?UTF-8?q?answer=E5=AD=97=E6=AE=B5=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将编辑题目时的表单初始化逻辑应用到新建题目 - 新建时正确设置默认的type、content、answer和options字段 - 题型切换时根据不同题型设置相应的默认answer值 - 确保所有题型都有正确的初始状态 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- web/src/pages/QuestionManagement.tsx | 36 +++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/web/src/pages/QuestionManagement.tsx b/web/src/pages/QuestionManagement.tsx index 8c20156..81c2439 100644 --- a/web/src/pages/QuestionManagement.tsx +++ b/web/src/pages/QuestionManagement.tsx @@ -106,10 +106,24 @@ const QuestionManagement: React.FC = () => { } else { setEditingQuestion(null) form.resetFields() - // 新建时设置默认值 + + // 新建时设置默认值 - 参照编辑逻辑 + const defaultType = 'multiple-choice' + + // 设置默认答案值 + let defaultAnswer: any = '' + let defaultOptions: Array<{ key: string; value: string }> = [] + + // 为单选和多选题设置默认选项 + if (defaultType === 'multiple-choice' || defaultType === 'multiple-selection') { + defaultOptions = [{ key: 'A', value: '' }, { key: 'B', value: '' }] + } + form.setFieldsValue({ - type: 'multiple-choice', - options: [{ key: 'A', value: '' }, { key: 'B', value: '' }], + type: defaultType, + content: '', + answer: defaultAnswer, + options: defaultOptions, }) } setModalVisible(true) @@ -548,7 +562,8 @@ const QuestionManagement: React.FC = () => { layout="vertical" initialValues={{ type: 'multiple-choice', - options: [{ key: 'A', value: '' }, { key: 'B', value: '' }] + options: [{ key: 'A', value: '' }, { key: 'B', value: '' }], + answer: '', // 添加默认answer字段 }} > { // 为单选和多选题设置默认选项 if (value === 'multiple-choice' || value === 'multiple-selection') { form.setFieldsValue({ - options: [{ key: 'A', value: '' }, { key: 'B', value: '' }] + options: [{ key: 'A', value: '' }, { key: 'B', value: '' }], + answer: value === 'multiple-choice' ? '' : [], // 单选空字符串,多选空数组 }) } + // 为判断题设置默认答案 + else if (value === 'true-false') { + form.setFieldsValue({ answer: true }) + } // 为填空题设置默认答案数组 - if (value === 'fill-in-blank') { + else if (value === 'fill-in-blank') { form.setFieldsValue({ answer: [''] }) } + // 为简答题和论述题设置默认空字符串 + else if (value === 'short-answer' || value === 'ordinary-essay' || value === 'management-essay') { + form.setFieldsValue({ answer: '' }) + } }} > {questionTypes.map(type => (