瀏覽代碼

fix(sent): mode 参数传给前端并修复逐词解析保存覆盖选择

- TemplateRender::render_sent 将 mode 加入 props,使 {{sent|mode=wbw}} 前端按 wbw 模式渲染(整体含义等字段正确显示)
- WbwSentCtl onChange 使用更新后的 newData 保存,避免闭包旧 wordData 覆盖用户下拉选择
visuddhinanda 3 天之前
父節點
當前提交
5837ad682c
共有 2 個文件被更改,包括 47 次插入50 次删除
  1. 1 0
      api-v13/app/Http/Api/TemplateRender.php
  2. 46 50
      dashboard-v6/src/components/wbw/WbwSentCtl.tsx

+ 1 - 0
api-v13/app/Http/Api/TemplateRender.php

@@ -1099,6 +1099,7 @@ class TemplateRender
         }
         }
         if (is_array($props)) {
         if (is_array($props)) {
             $props['show'] = $show;
             $props['show'] = $show;
+            $props['mode'] = $currMode;
         }
         }
 
 
         // 输出引用
         // 输出引用

+ 46 - 50
dashboard-v6/src/components/wbw/WbwSentCtl.tsx

@@ -752,64 +752,60 @@ const WbwSentCtl = memo(
             studio={studio}
             studio={studio}
             readonly={readonly}
             readonly={readonly}
             onChange={(e: IWbw, isPublish?: boolean, isPublic?: boolean) => {
             onChange={(e: IWbw, isPublish?: boolean, isPublic?: boolean) => {
-              setWordData((origin) => {
-                const newData = [...origin];
-                const snKey = createSnKey(e.sn);
+              const snKey = createSnKey(e.sn);
+              const newData = [...wordData];
 
 
-                // 更新当前单词
-                const index = newData.findIndex(
-                  (v) => createSnKey(v.sn) === snKey
-                );
-                if (index !== -1) {
-                  newData[index] = e;
-                }
+              // 更新当前单词
+              const index = newData.findIndex(
+                (v) => createSnKey(v.sn) === snKey
+              );
+              if (index !== -1) {
+                newData[index] = e;
+              }
 
 
-                // 如果是拆分后的单词,更新父单词的 factorMeaning
-                if (e.sn.length > 1) {
-                  const parentSn = e.sn.slice(0, e.sn.length - 1);
-                  const parentSnKey = createSnKey(parentSn);
-
-                  const factorMeaning = newData
-                    .filter(
-                      (value) =>
-                        value.sn.length === e.sn.length &&
-                        createSnKey(value.sn.slice(0, e.sn.length - 1)) ===
-                          parentSnKey &&
-                        value.real.value &&
-                        value.real.value.length > 0
-                    )
-                    .map((item) => item.meaning?.value)
-                    .join("+");
-
-                  const parentIndex = newData.findIndex(
-                    (v) => createSnKey(v.sn) === parentSnKey
-                  );
-                  if (parentIndex !== -1) {
-                    newData[parentIndex] = {
-                      ...newData[parentIndex],
-                      factorMeaning: {
-                        value: factorMeaning,
-                        status: 5,
-                      },
+              // 如果是拆分后的单词,更新父单词的 factorMeaning
+              if (e.sn.length > 1) {
+                const parentSn = e.sn.slice(0, e.sn.length - 1);
+                const parentSnKey = createSnKey(parentSn);
+
+                const factorMeaning = newData
+                  .filter(
+                    (value) =>
+                      value.sn.length === e.sn.length &&
+                      createSnKey(value.sn.slice(0, e.sn.length - 1)) ===
+                        parentSnKey &&
+                      value.real.value &&
+                      value.real.value.length > 0
+                  )
+                  .map((item) => item.meaning?.value)
+                  .join("+");
+
+                const parentIndex = newData.findIndex(
+                  (v) => createSnKey(v.sn) === parentSnKey
+                );
+                if (parentIndex !== -1) {
+                  newData[parentIndex] = {
+                    ...newData[parentIndex],
+                    factorMeaning: {
+                      value: factorMeaning,
+                      status: 5,
+                    },
+                  };
+
+                  if (newData[parentIndex].meaning?.status !== WbwStatus.manual) {
+                    newData[parentIndex].meaning = {
+                      value: factorMeaning.replaceAll("+", " "),
+                      status: 5,
                     };
                     };
-
-                    if (
-                      newData[parentIndex].meaning?.status !== WbwStatus.manual
-                    ) {
-                      newData[parentIndex].meaning = {
-                        value: factorMeaning.replaceAll("+", " "),
-                        status: 5,
-                      };
-                    }
                   }
                   }
                 }
                 }
+              }
 
 
-                return newData;
-              });
+              setWordData(newData);
 
 
-              // 延迟保存以批量处理
+              // 延迟保存以批量处理(使用更新后的 newData,避免闭包里的旧 wordData 覆盖用户选择)
               setTimeout(() => {
               setTimeout(() => {
-                saveWord(wordData, e.sn[0]);
+                saveWord(newData, e.sn[0]);
               }, 100);
               }, 100);
 
 
               if (isPublish === true) {
               if (isPublish === true) {