aamin 1 год назад
Родитель
Сommit
6bfcce0b61
2 измененных файлов с 21 добавлено и 10 удалено
  1. 20 10
      houtai/src/pages/A1Rule/TopicSetting/index.tsx
  2. 1 0
      houtai/src/types/api/A1Rule.ts

+ 20 - 10
houtai/src/pages/A1Rule/TopicSetting/index.tsx

@@ -253,10 +253,20 @@ function TopicSetting({ closeFu }: Props) {
   const getList = useCallback(async () => {
     const res = await getTopicByZhuNongKeTangAPI();
     if (res.code === 0) {
+      const newData = res.data.map((item: any) => {
+        let newAnswer = {
+          ...JSON.parse(item.answer),
+          correct: encodeStr(Base64.encode(item.correct)),
+        };
+        let NewItem = { ...item, answer: JSON.stringify(newAnswer) };
+        return {
+          ...NewItem,
+        };
+      });
       // 保存编辑前的数据
-      setEditBeforeData(res.data);
+      setEditBeforeData(newData);
       // 保存编辑后的数据
-      disposeEditShowData(res.data);
+      disposeEditShowData(newData);
     }
   }, [disposeEditShowData]);
 
@@ -435,11 +445,7 @@ function TopicSetting({ closeFu }: Props) {
           return (
             <Select
               style={{ width: 120 }}
-              defaultValue={
-                item.answer.correct
-                  ? Base64.decode(decodeStr(item.answer.correct))
-                  : ""
-              }
+              defaultValue={item.correct ? item.correct : ""}
               onChange={(value: any) => {
                 handleCorrectChange(value, index);
               }}
@@ -539,21 +545,25 @@ function TopicSetting({ closeFu }: Props) {
       });
     }
 
-    console.log("查看题目编辑的数据是什么样", editShowData);
     // 执行数据提交   新增不用传id  编辑要传id
     // console.log(editShowData)
     let data = editShowData.map((item: any) => {
+      const newItem = { ...item.answer };
+      delete newItem.correct;
+
       return item.type && item.type === "add"
         ? {
-            answer: JSON.stringify(item.answer),
+            answer: JSON.stringify(newItem),
             description: item.description,
             question: item.question,
+            correct: Base64.decode(decodeStr(item.answer.correct)),
           }
         : {
-            answer: JSON.stringify(item.answer),
+            answer: JSON.stringify(newItem),
             description: item.description,
             id: item.id,
             question: item.question,
+            correct: Base64.decode(decodeStr(item.answer.correct)),
           };
     });
     const res = await saveQuestionAPI(data);

+ 1 - 0
houtai/src/types/api/A1Rule.ts

@@ -55,6 +55,7 @@ export type QuestionTableType = {
   answer: any;
   // answer: string;
   createTime: string;
+  correct:string;
   creatorId: number;
   creatorName: string;
   description: string;