diff --git a/web/src/pages/QuestionManagement.tsx b/web/src/pages/QuestionManagement.tsx index 81c2439..9254a99 100644 --- a/web/src/pages/QuestionManagement.tsx +++ b/web/src/pages/QuestionManagement.tsx @@ -161,14 +161,16 @@ const QuestionManagement: React.FC = () => { // 解析选项(仅选择题和多选题需要) let options: Record | undefined - if (values.options && (values.type === 'multiple-choice' || values.type === 'multiple-selection')) { - // 将数组格式转换为对象格式 { "A": "选项A", "B": "选项B" } - options = values.options.reduce((acc: Record, opt: any) => { - if (opt && opt.key && opt.value) { - acc[opt.key] = opt.value - } - return acc - }, {}) + if (values.type === 'multiple-choice' || values.type === 'multiple-selection') { + if (values.options && values.options.length > 0) { + // 将数组格式转换为对象格式 { "A": "选项A", "B": "选项B" } + options = values.options.reduce((acc: Record, opt: any) => { + if (opt && opt.key && opt.value) { + acc[opt.key] = opt.value + } + return acc + }, {}) + } } // 构建请求数据 @@ -284,8 +286,8 @@ const QuestionManagement: React.FC = () => { rules={[{ required: true, message: '请选择答案' }]} > - 正确 - 错误 + 正确 + 错误 ) @@ -339,12 +341,28 @@ const QuestionManagement: React.FC = () => { )} - - + prevValues.options !== currentValues.options}> + {({ getFieldValue }) => { + const options = getFieldValue('options') || [] + const optionsList = options + .filter((opt: any) => opt && opt.key) + .map((opt: any) => ({ + label: `${opt.key}. ${opt.value || '(请先填写选项内容)'}`, + value: opt.key, + })) + return ( + + + prevValues.options !== currentValues.options}> + {({ getFieldValue }) => { + const options = getFieldValue('options') || [] + const optionsList = options + .filter((opt: any) => opt && opt.key) + .map((opt: any) => ({ + label: `${opt.key}. ${opt.value || '(请先填写选项内容)'}`, + value: opt.key, + })) + return ( + +