Browse Source

🐛新增选项问题

shaogen1995 1 năm trước cách đây
mục cha
commit
ea6a872747
1 tập tin đã thay đổi với 22 bổ sung10 xóa
  1. 22 10
      src/pages/A6_1ques/A6Qtopic/QTadd.tsx

+ 22 - 10
src/pages/A6_1ques/A6Qtopic/QTadd.tsx

@@ -92,9 +92,13 @@ function QTadd({ moInfo, closeFu, tableLen, upTableFu, fatherId }: Props) {
   // 题目的数组
   const [list, setList] = useState<A6QListType[]>([]);
 
+  useEffect(() => {
+    console.log("------", list);
+  }, [list]);
+
   // 点击新增题目
   const addListFu = useCallback(
-    (rank: 1 | 2, length?: number) => {
+    (rank: 1 | 2, length?: number, id?: number) => {
       if (rank === 1 && list.length + tableLen >= 50)
         return MessageFu.warning("最多支持50题!");
       if (length && length >= 6) return MessageFu.warning("最多6个选项!");
@@ -102,26 +106,34 @@ function QTadd({ moInfo, closeFu, tableLen, upTableFu, fatherId }: Props) {
         setList([
           ...list,
           {
-            id: Date.now(),
+            id: Date.now() - 1000,
             name: "",
             type: "单选",
             skip: "不需要",
             custom: false,
             num: 1,
             sList: [
-              { id: Date.now(), txt: "", skip2: false, num2: 1 },
-              { id: Date.now() + 1, txt: "", skip2: false, num2: 1 },
+              { id: Date.now() - 900, txt: "", skip2: false, num2: 1 },
+              { id: Date.now() - 800, txt: "", skip2: false, num2: 1 },
             ],
           },
         ]);
       } else {
         setList(
-          list.map((v) => ({
+          list.map((v, i) => ({
             ...v,
-            sList: [
-              ...v.sList,
-              { id: Date.now(), txt: "", skip2: false, num2: 1 },
-            ],
+            sList:
+              v.id === id
+                ? [
+                    ...v.sList,
+                    {
+                      id: Date.now() - 700 - i * 10,
+                      txt: "",
+                      skip2: false,
+                      num2: 1,
+                    },
+                  ]
+                : v.sList,
           }))
         );
       }
@@ -537,7 +549,7 @@ function QTadd({ moInfo, closeFu, tableLen, upTableFu, fatherId }: Props) {
                   {/* 子选项的新增 */}
                   <div className="A6Q2_22" hidden={v.type === "填空"}>
                     <Button
-                      onClick={() => addListFu(2, v.sList.length)}
+                      onClick={() => addListFu(2, v.sList.length, v.id)}
                       disabled={v.sList.length >= 6}
                     >
                       新增选项