Selaa lähdekoodia

Merge branch 'master' of http://192.168.0.130:13000/CQ_ADI/airoptweb

huangxingxing 4 kuukautta sitten
vanhempi
säilyke
f78a5b3282

BIN
src/assets/img/jiegoucanshu.png


+ 64 - 62
src/components/PythonEditor/index.vue

@@ -1,86 +1,88 @@
 <template>
-  <div id="editorContainer"></div>
+  <div :id="editorId" class="editorContainer"></div>
 </template>
 
 <script setup>
-import { ref, onMounted, watch, toRaw } from 'vue';
-import * as monaco from 'monaco-editor';
+import { ref, onMounted, onUnmounted, watch, computed, toRaw } from 'vue'
+import * as monaco from 'monaco-editor'
 
 const props = defineProps({
-  modelValue: String, // v-model 绑定
-  value: String,      // 兼容传统 value 绑定
+  value: String,
   language: String,
-});
+})
 
-const emit = defineEmits(['update:modelValue', 'change']);
+const emit = defineEmits(['change'])
+const editor = ref(null)
+const editorId = computed(() => `editor_${Math.random().toString(36).slice(2, 11)}`)
 
-const editor = ref(null);
-let isUpdatingFromParent = false; // 添加防止死循环的锁
+const getEditorValue = () => toRaw(editor.value)?.getValue() || ''
 
-// 获取当前值
-const getCurrentValue = () => props.modelValue ?? props.value;
-const getEditorValue = () => toRaw(editor.value)?.getValue() || '';
+let resizeObserver = null
 
-// 监听父组件传来的值变化(用于外部更新编辑器)
-watch(
-  () => getCurrentValue(),
-  (newValue) => {
-    const editorVal = getEditorValue();
-    const normalize = (s) => (s || '').trim();
+onMounted(() => {
+  const el = document.getElementById(editorId.value)
+
+  if (!el) {
+    // console.warn('[MonacoEdit]找不到容器元素')
+    return
+  }
 
-    if (editor.value && normalize(newValue) !== normalize(editorVal)) {
-      console.log('外部更新编辑器内容', newValue);
-      console.log('当前编辑器内容', editorVal);
+  const initEditor = () => {
+    if (editor.value || el.clientWidth === 0 || el.clientHeight === 0) return
 
-      isUpdatingFromParent = true;
+    // console.log('[MonacoEdit]尺寸可用,初始化编辑器')
 
-      // 设置值
-      editor.value.setValue(newValue || '');
+    monaco.editor.defineTheme('custom-light', {
+      base: 'vs',
+      inherit: true,
+      rules: [],
+      colors: {
+        'editorGutter.background': '#EEEEEE',
+      },
+    })
 
-      // 等当前宏任务结束后再解除锁
-      queueMicrotask(() => {
-        isUpdatingFromParent = false;
-        console.log('编辑器内容已更新', editor.value.getValue());
-      });
-    } else {
-      console.log('内容相同,跳过更新');
+    editor.value = monaco.editor.create(el, {
+      value: props.value || '',
+      language: props.language || 'python',
+      minimap: { enabled: true },
+      colorDecorators: true,
+      readOnly: false,
+      theme: 'custom-light',
+      automaticLayout: true,
+    })
+
+    editor.value.onDidChangeModelContent(() => {
+      emit('change', getEditorValue())
+    })
+
+    console.log('[MonacoEdit]初始化完成')
+  }
+
+  // 使用 ResizeObserver 监听尺寸变化
+  resizeObserver = new ResizeObserver(() => {
+    if (el.clientWidth > 0 && el.clientHeight > 0 && !editor.value) {
+      initEditor()
     }
+  })
+
+  resizeObserver.observe(el)
+})
+
+onUnmounted(() => {
+  if (editor.value) {
+    editor.value.dispose()
+    editor.value = null
   }
-);
 
-onMounted(() => {
-  monaco.editor.defineTheme("custom-light", {
-    base: "vs",
-    inherit: true,
-    rules: [],
-    colors: {
-      "editorGutter.background": "#EEEEEE",
-    },
-  });
-
-  editor.value = monaco.editor.create(document.getElementById('editorContainer'), {
-    value: getCurrentValue() || '',
-    language: props.language || 'python',
-    minimap: { enabled: true },
-    colorDecorators: true,
-    readOnly: false,
-    theme: "custom-light",
-    automaticLayout: true,
-  });
-
-  // 编辑器内容变化时触发
-  editor.value.onDidChangeModelContent(() => {
-    if (isUpdatingFromParent) return; // 阻止外部设置引起的触发
-
-    const newValue = getEditorValue();
-    emit('update:modelValue', newValue); // 通知父组件更新
-    emit('change', newValue);
-  });
-});
+  if (resizeObserver) {
+    resizeObserver.disconnect()
+    resizeObserver = null
+  }
+})
 </script>
 
 <style>
-#editorContainer {
+.editorContainer {
   height: 400px !important;
 }
 </style>

+ 20 - 2
src/views/home.vue

@@ -1244,7 +1244,7 @@
           type="textarea"
           placeholder="Please input"
         /> -->
-              <PythonEdit v-model="textarea1" language="python" @change="handleEditorChange"/>
+              <PythonEdit v-show="pythoneditorshow" :value="textarea1" language="python" @change="handleEditorChange"/>
               </div>
               <div class="pythfoter">
                 <div class="span active" >
@@ -2620,9 +2620,11 @@ const intxfoiladflow = (nowid) => {
   });
 }
 
+ let pythoneditorshow = ref(false)
 // Python窗口初始化
 const initPython = (nowid) => {
   console.log('Pythonchushihua');
+  pythoneditorshow.value = true; // 显示编辑器
   pythonwid.value = nowid;
   const param = {
     transCode: 'MDO0036',
@@ -2635,7 +2637,9 @@ const initPython = (nowid) => {
     
     // 判断 res.ptython 是否为空,若不为空则赋值
     if (res.ptython) {
+      console.log('Python内容:', res.ptython);
       textarea1.value = res.ptython;
+      
     }
   }).catch((err) => {
     console.error('Python内容初始化失败');
@@ -2645,11 +2649,12 @@ const initPython = (nowid) => {
 // Python确认按钮提交
 const pythonSubmit = () => {
   console.log('Python确认按钮提交');
+  pythoneditorshow.value = false; // 隐藏编辑器
   const param = {
     transCode:'MDO0037',
     pid: pid.value,
     wid: pythonwid.value,
-    python: textarea1.value,
+    python: newtextarea1.value,
   }
   request(param).then((res) => {
     ElMessage({
@@ -2661,9 +2666,22 @@ const pythonSubmit = () => {
   });
 }
 
+let newtextarea1 = ref(`import os
+import numpy as np
+from surromdao.solver import BaseSolver
+
+class Branin(BaseSolver):
+    def __init__(self, filename=os.path):
+        super().__init__(filename)
+    
+    def compute(self, xdict):
+        x = np.zeros(2)
+        # x[0] = xdict['x1']
+        # x[1] = xdict['x2']`);
 // python处理编辑器内容变化的方法
 const handleEditorChange = (value) => {
   // console.log('Editor content changed in parent component:', value);
+  newtextarea1.value = value;
 };
 
 let MathFuncxinjian = ref('ture')

+ 19 - 3
src/views/titlecomponent/MathFunc.vue

@@ -38,8 +38,8 @@
         </el-table>
     </div>
 
-    <div v-if="currentTab1 == '1'" style="margin-top: 10px">
-        <PythonEdit  v-model="equation" language="python" />
+    <div v-show="currentTab1 == '1'" style="margin-top: 10px">
+        <PythonEdit  :value="equation" language="python" @change="updateEquation"/>
     </div> 
 
     <div v-show="currentTab1 == '2'" class="eldesign classtable" style="margin-top: 10px">
@@ -259,6 +259,22 @@ const getmathfuncAssign = (data) => {
   outParams.value = data.outParams;
 }
 
+let newequation = ref(`import os
+import numpy as np
+from surromdao.solver import BaseSolver
+
+class Branin(BaseSolver):
+    def __init__(self, filename=os.path):
+        super().__init__(filename)
+
+    def compute(self, xdict):
+        x = np.zeros(2)
+        # x[1] = x[2]`);
+let updateEquation = (value) => {
+  // console.log('updateEquation:', value);
+  newequation.value = value;
+}
+
 const getmathfuncsave = (id,nowid) => {
   if(nowid){
     wid.value = nowid
@@ -269,7 +285,7 @@ const getmathfuncsave = (id,nowid) => {
     transCode: "MDO0064",
     pid: pid.value,
     wid: wid.value,
-    equation: equation.value,
+    equation: newequation.value,
     inParams: convertToStringArray([],inParams.value),
     outParams: convertToStringArray([],outParams.value)
   };

+ 10 - 4
src/views/titlecomponent/TACS.vue

@@ -8,6 +8,7 @@
         :class="{ active: currentTab2 === index }"
         @click="selectTab2(index)"
       >
+         <img :src="tab.imgSrc" style="width: 22px;"/>
         {{ tab.name }}
       </li>
     </ul>
@@ -219,6 +220,11 @@ import cloudChart from "../threejsView/index.vue" // 云图
 import { request, uploadFile } from "@/utils/request"
 import emitter from "@/utils/emitter"
 
+import meshFile from "@/assets/img/meshFile.png";
+import jiegoucanshu from "@/assets/img/jiegoucanshu.png";
+import configParams from "@/assets/img/configParams.png";
+import analysisParams from "@/assets/img/analysisParams.png";
+
 let fid = ref()
 let formLabelWidth1 = ref(170)
 let formLabelWidth120 = ref(120)
@@ -230,10 +236,10 @@ let wid = ref();
 let tacsid = ref();
 
 let tabslist2= ref([
-  { id: '0', name: '网格文件' },
-  { id: '1', name: '结构参数' },
-  { id: '2', name: '设置参数' },
-  { id: '3', name: '分析参数' },
+  { id: '0', name: '网格文件' ,imgSrc:meshFile},
+  { id: '1', name: '结构参数' ,imgSrc:jiegoucanshu},
+  { id: '2', name: '设置参数' ,imgSrc:configParams},
+  { id: '3', name: '分析参数' ,imgSrc:analysisParams},
 
 ])