|
@@ -83,7 +83,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
|
|
|
|
|
|
// 删除选项
|
|
|
const delImgListFu = useCallback(
|
|
|
- (label: string, ind: number) => {
|
|
|
+ (ind: number, value: string | string[]) => {
|
|
|
const arr = answerArr.map((v, i) => {
|
|
|
return {
|
|
|
label: i > ind ? answerArr[i - 1].label : v.label,
|
|
@@ -92,6 +92,13 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
|
|
|
});
|
|
|
const newData = arr.filter((v, i) => i !== ind);
|
|
|
setAnswerArr(newData);
|
|
|
+
|
|
|
+ // 如果删除的是已经选择的正确答案的值,把表单的正确答案的值清空
|
|
|
+ if (value === FormBoxRef.current.getFieldValue("correct")) {
|
|
|
+ FormBoxRef.current.setFieldValue("correct", "");
|
|
|
+ // 手动校验正确答案
|
|
|
+ FormBoxRef.current.validateFields(["correct"]);
|
|
|
+ }
|
|
|
},
|
|
|
[answerArr]
|
|
|
);
|
|
@@ -232,16 +239,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
|
|
|
<Form.Item
|
|
|
label="正确答案"
|
|
|
name="correct"
|
|
|
- rules={[
|
|
|
- { required: true, message: "请选择正确答案!" },
|
|
|
- {
|
|
|
- validator: async (rule, value) => {
|
|
|
- if (value && answerArr.every((v) => v.value !== value)) {
|
|
|
- return Promise.reject("请选择正确答案!");
|
|
|
- } else return Promise.resolve();
|
|
|
- },
|
|
|
- },
|
|
|
- ]}
|
|
|
+ rules={[{ required: true, message: "请选择正确答案!" }]}
|
|
|
>
|
|
|
<Radio.Group>
|
|
|
{answerArr.map((v) => (
|
|
@@ -273,7 +271,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
|
|
|
title="删除后无法恢复,是否删除?"
|
|
|
okText="删除"
|
|
|
cancelText="取消"
|
|
|
- onConfirm={() => delImgListFu(v.label, i)}
|
|
|
+ onConfirm={() => delImgListFu(i, v.value)}
|
|
|
>
|
|
|
<div className="clearCover">
|
|
|
<CloseCircleOutlined />
|