tangjunhao 4 ヶ月 前
コミット
c80189299c
3 ファイル変更53 行追加55 行削除
  1. 18 21
      src/components/PythonEditor/index.vue
  2. 1 1
      src/views/home.vue
  3. 34 33
      src/views/vuetree/index.vue

+ 18 - 21
src/components/PythonEditor/index.vue

@@ -8,33 +8,28 @@ import * as monaco from 'monaco-editor';
 
 const props = defineProps({
   modelValue: String, // v-model 绑定
-  value: String,      // 传统 value 绑定(兼容旧代码)
+  value: String,      // 兼容传统 value 绑定
   language: String,
 });
 
-const emit = defineEmits([
-  'update:modelValue', // v-model 更新事件
-  'change',           // 传统 change 事件
-]);
+const emit = defineEmits(['update:modelValue', 'change']);
 
 const editor = ref(null);
+let isUpdatingFromParent = false; // 添加防止死循环的锁
 
-// 获取当前绑定的值(优先使用 modelValue)
-const getCurrentValue = () => {
-  return props.modelValue ?? props.value;
-};
+// 获取当前值
+const getCurrentValue = () => props.modelValue ?? props.value;
+const getEditorValue = () => toRaw(editor.value)?.getValue() || '';
 
-// 获取编辑器内容
-const getEditorValue = () => {
-  return toRaw(editor.value)?.getValue() || '';
-};
-
-// 监听外部值变化(如果父组件修改了 value,同步到编辑器)
+// 监听父组件传来的值变化(用于外部更新编辑器)
 watch(
   () => getCurrentValue(),
   (newValue) => {
-    if (editor.value && newValue !== getEditorValue()) {
-      editor.value.setValue(newValue);
+    const editorVal = getEditorValue();
+    if (editor.value && newValue !== editorVal) {
+      isUpdatingFromParent = true; // 开锁,标记是外部更新
+      editor.value.setValue(newValue || '');
+      isUpdatingFromParent = false;
     }
   }
 );
@@ -59,17 +54,19 @@ onMounted(() => {
     automaticLayout: true,
   });
 
-  // 监听编辑器内容变化
+  // 编辑器内容变化时触发
   editor.value.onDidChangeModelContent(() => {
+    if (isUpdatingFromParent) return; // 阻止外部设置引起的触发
+
     const newValue = getEditorValue();
-    emit('update:modelValue', newValue); // 触发 v-model 更新
-    emit('change', newValue);            // 触发传统 change 事件
+    emit('update:modelValue', newValue); // 通知父组件更新
+    emit('change', newValue);
   });
 });
 </script>
 
 <style>
-#editorContainer{
+#editorContainer {
   height: 400px !important;
 }
 </style>

+ 1 - 1
src/views/home.vue

@@ -2275,7 +2275,7 @@ const handleClick = (tab, event) => {
   if (tabactive.value == 'User') {
     vuefval.value.logToObject1().then(() => {
       router.replace({ path: '/' });
-      // console.log('跳转到首页');
+      console.log('跳转到首页');
     });
   } else {
 

+ 34 - 33
src/views/vuetree/index.vue

@@ -1311,8 +1311,8 @@ async  function logToObject1() {
         // 创建一个图片元素并设置src属性为转换后的图片数据
        vueflowimg.value=img
        if(vueflowimg.value!=''){
-        console.log("进入了")
-        addflow();
+        console.log("保存图片成功!")
+        await addflow();
        }
         // 添加到DOM中或者做其他操作
       } catch (error) {
@@ -1320,46 +1320,47 @@ async  function logToObject1() {
       }
 }
 //添加接口
-const addflow = () => {
+const addflow = async () => {
     const savedObj = JSON.parse(sessionStorage.getItem("objlist"));
     const stypeValue = savedObj ? savedObj.stype : '';
 
-    // 用于首页主界面切换数据一致
     const updateobjlist = {
-      pid: pid.value,
-      name: newobj.value.name,
-      remark: newobj.value.description,
-      image: vueflowimg.value,
-      isshare: '1',
-      flow: mergedObj.value,
-      stype: stypeValue,
-    }
-    sessionStorage.setItem("objlist",JSON.stringify(updateobjlist));
-    
-    console.log("打印stypeValue:",stypeValue);
+        pid: pid.value,
+        name: newobj.value.name,
+        remark: newobj.value.description,
+        image: vueflowimg.value,
+        isshare: '1',
+        flow: mergedObj.value,
+        stype: stypeValue,
+    };
+    sessionStorage.setItem("objlist", JSON.stringify(updateobjlist));
+
+    console.log("打印stypeValue:", stypeValue);
+
     const params = {
         transCode: 'MDO0002',
         pid: pid.value,
         name: newobj.value.name,
-        remark:newobj.value.description,
-        image:vueflowimg.value,
-        isshare:'1',
-        flow:mergedObj.value ,
-        stype:stypeValue,
-    }
+        remark: newobj.value.description,
+        image: vueflowimg.value,
+        isshare: '1',
+        flow: mergedObj.value,
+        stype: stypeValue,
+    };
+
     console.log(params);
-    request(params)
-        .then((res) => {
-            console.log(res);
-            ElMessage({
-                  message: '工程保存成功',
-                  type: 'success',
-              })
-        })
-        .catch((err) => {
-            ElMessage.error(err.returnMsg)
-        })
-}
+
+    try {
+        const res = await request(params);
+        console.log(res);
+        ElMessage({
+            message: '工程保存成功',
+            type: 'success',
+        });
+    } catch (err) {
+        ElMessage.error(err.returnMsg);
+    }
+};
 /**
  * Resets the current viewport transformation (zoom & pan)
  */