Kaynağa Gözat

fix: 修改调整翻译等功能

liaojiaxing 1 ay önce
ebeveyn
işleme
0b2cb1c1c2

+ 2 - 2
apps/designer/src/components/flowchart/process.tsx

@@ -31,8 +31,8 @@ const component = ({ node }: { node: Node }) => {
           <rect
             x={strokeWidth}
             y={strokeWidth}
-            width={size?.width - 4}
-            height={size?.height - 4}
+            width={size?.width-2*strokeWidth}
+            height={size?.height-2*strokeWidth}
             fill={fillContent}
             stroke={strokeColor}
             strokeDasharray={strokeDasharray}

+ 9 - 1
apps/designer/src/events/mindMapEvent.ts

@@ -198,7 +198,6 @@ export const bindMindMapEvents = (
    */
   graph.on("node:change:data", (args) => {
     const { current, previous } = args;
-    console.log("数据变更:", current, previous);
     // 收折子项 setMindProjectInfo更新会重新渲染
     if (current.collapsed !== previous.collapsed) {
       setMindProjectInfo &&
@@ -219,6 +218,15 @@ export const bindMindMapEvents = (
           graph
         );
     }
+    if (current?.width !== previous?.width || current?.height !== previous?.height) {
+      setMindProjectInfo &&
+        updateTopic(
+          args.cell.id,
+          { width: current.width, height: current.height },
+          setMindProjectInfo,
+          graph
+        );
+    }
     if (current?.border !== previous?.border) {
       setMindProjectInfo &&
         updateTopic(

+ 6 - 5
apps/designer/src/models/mindMapModel.ts

@@ -45,6 +45,12 @@ export default function mindMapModel() {
     setProjectInfo(cloneDeep(info));
     projectInfoRef.current = info;
     sessionStorage.setItem("mindMapProjectInfo", JSON.stringify(info));
+    // 初始化加载数据 清空画布
+    if(init) {
+      graph?.clearCells();
+      graph?.centerContent();
+      historyRef.current = [];
+    }
 
     if (!init && !isSetting) {
       const graphId = sessionStorage.getItem("projectId");
@@ -94,11 +100,6 @@ export default function mindMapModel() {
       });
     }
 
-    if(init) {
-      graph?.centerContent();
-      historyRef.current = [];
-    }
-
     // 添加记录
     if(!ignoreHistory && !ignoreRender) {
       historyRef.current?.push(info);

+ 11 - 11
apps/designer/src/pages/flow/components/Config/AiCreator.tsx

@@ -222,13 +222,19 @@ export default function AICreator(props: {
 
   // 替换节点文本内容
   const handleReplace = (labelMap: LabelMap, data: Record<string, string>) => {
-    Object.keys(data).forEach((key) => {
+    const keyMap: Record<string, string> = data;
+    if(Array.isArray(data)) {
+      data.forEach(item => {
+        keyMap[item.original] = item.value
+      })
+    }
+    Object.keys(keyMap).forEach((key) => {
       if (labelMap[key]) {
         labelMap[key].forEach((item) => {
           const cell = graph?.getCellById(item.cell);
           if (cell && cell.shape !== "edge") {
             cell.setData({
-              [item.key]: data[key],
+              [item.key]: keyMap[key],
             });
             graph?.select(cell);
           } else if (cell?.isEdge()) {
@@ -239,7 +245,7 @@ export default function AICreator(props: {
                 ...item,
                 attrs: {
                   label: {
-                    text: data?.[(item.attrs?.label?.text as string)?.trim()] || item.attrs?.label?.text
+                    text: keyMap?.[(item.attrs?.label?.text as string)?.trim()] || item.attrs?.label?.text
                   }
                 }
               }
@@ -290,10 +296,7 @@ export default function AICreator(props: {
     const data = JSON.stringify(Object.keys(labelMap));
     let result = "";
     onRequest(
-      `修复语法错误,并返回修复后的键对值,要求:
-1、仅返回修复后的JSON数据,不展示其他内容
-2、以键值对展示 如: {'大有做为': '大有作为'}
-需要修复的数据:${data}`,
+      `修复语法错误,需要修复的数据:${data}`,
       {
         onUpdate: (data) => {
           result += data.answer;
@@ -361,10 +364,7 @@ export default function AICreator(props: {
     const data = JSON.stringify(Object.keys(labelMap));
     let result = "";
     onRequest(
-      `翻译成${lang === 'en' ? '英文' : '中文'},并返回翻译后的键对值,要求:
-        1、仅返回修复后的JSON数据,不展示其他内容
-        2、以键值对展示 如: {'中文': 'Chinese'}
-      需要翻译的数据:${data}`,
+      `翻译成${lang === 'en' ? '英文' : '中文'},需要翻译的数据:${data}`,
       {
         onUpdate: (data) => {
           result += data.answer;

+ 10 - 10
apps/designer/src/pages/mindmap/components/Config/AiCreator.tsx

@@ -163,13 +163,19 @@ export default function AICreator(props: {
 
   // 替换节点文本内容
   const handleReplace = (labelMap: LabelMap, data: Record<string, string>) => {
+    const keyMap: Record<string, string> = data;
+    if(Array.isArray(data)) {
+      data.forEach(item => {
+        keyMap[item.original] = item.value
+      })
+    }
     mindProjectInfo && setMindProjectInfo({
       ...mindProjectInfo,
       topics: traverseNode(mindProjectInfo?.topics || [], (topic) => {
         // 判断当前节点是否需要替换
         const ids = labelMap[topic.label?.trim()]?.map(item => item.cell);
-        if (data[topic.label?.trim()] && ids?.includes(topic.id)) {
-          topic.label = data[topic.label?.trim()];
+        if (keyMap[topic.label?.trim()] && ids?.includes(topic.id)) {
+          topic.label = keyMap[topic.label?.trim()];
         }
         return topic
       })
@@ -216,10 +222,7 @@ export default function AICreator(props: {
     const data = JSON.stringify(Object.keys(labelMap));
     let result = "";
     onRequest(
-      `修复语法错误,并返回修复后的键对值,要求:
-1、仅返回修复后的JSON数据,不展示其他内容
-2、以键值对展示 如: {'大有做为': '大有作为'}
- 需要修复的数据:${data}`,
+      `修复语法错误,需要修复的数据:${data}`,
       {
         onUpdate: (data) => {
           result += data.answer;
@@ -287,10 +290,7 @@ export default function AICreator(props: {
     const data = JSON.stringify(Object.keys(labelMap));
     let result = "";
     onRequest(
-      `翻译成${lang === "en" ? "英文" : "中文"},并返回翻译后的键对值,要求:
-          1、仅返回修复后的JSON数据,不展示其他内容
-          2、以键值对展示 如: {'中文': 'Chinese'}
-        需要翻译的数据:${data}`,
+      `翻译成${lang === "en" ? "英文" : "中文"},需要翻译的数据:${data}`,
       {
         onUpdate: (data) => {
           result += data.answer;

+ 11 - 10
apps/designer/src/pages/mindmap/mindMap.tsx

@@ -15,6 +15,16 @@ import {
   getBorderPositionAndSize,
 } from "@/utils/mindmapHander";
 
+type RenderParams = {
+  topics: TopicItem[];
+  pageSetting: MindMapProjectInfo["pageSetting"];
+  structure: StructureType;
+  theme: string;
+  graph: Graph;
+  setMindProjectInfo: (info: MindMapProjectInfo) => void;
+  returnCells?: boolean;
+}
+
 /**
  * 渲染思维导图项目
  * @param graph
@@ -27,15 +37,7 @@ export const renderMindMap = ({
   graph,
   setMindProjectInfo,
   returnCells = false
-}: {
-  topics: TopicItem[];
-  pageSetting: MindMapProjectInfo["pageSetting"];
-  structure: StructureType;
-  theme: string;
-  graph: Graph;
-  setMindProjectInfo: (info: MindMapProjectInfo) => void;
-  returnCells?: boolean;
-}) => {
+}: RenderParams) => {
   const cells: Cell[] = [];
   topics.forEach((topic) => {
     // 遍历出层次结构
@@ -53,7 +55,6 @@ export const renderMindMap = ({
     }
     const offsetX = originPosition.x - result.x;
     const offsetY = originPosition.y - result.y;
-
     const traverse = (hierarchyItem: HierarchyResult, parent?: Node) => {
       if (hierarchyItem) {
         const { data, children, x, y } = hierarchyItem;