tangjunhao il y a 3 mois
Parent
commit
f9fb52d188
4 fichiers modifiés avec 36 ajouts et 39 suppressions
  1. 1 0
      package.json
  2. 20 37
      src/components/PythonEditor/index.vue
  3. 2 2
      src/views/titlecomponent/TACS.vue
  4. 13 0
      vite.config.ts

+ 1 - 0
package.json

@@ -59,6 +59,7 @@
     "eslint-plugin-vue": "^9.17.0",
     "prettier": "^3.0.3",
     "scss": "^0.2.4",
+    "sirv": "^3.0.1",
     "typescript": "^5.2.2",
     "unplugin-auto-import": "^0.16.6",
     "unplugin-vue-components": "^0.25.2",

+ 20 - 37
src/components/PythonEditor/index.vue

@@ -2,6 +2,13 @@
 import { ref, onMounted, onBeforeUnmount, watch, nextTick } from "vue";
 import loader from "@monaco-editor/loader";
 
+// 添加 config 配置,必须在 loader.init() 之前
+loader.config({
+  paths: {
+    vs: "/monaco-editor/vs", // 对应 node_modules/monaco-editor/min/vs 被映射的URL路径
+  },
+});
+
 const props = defineProps({
   value: String,
   language: {
@@ -15,35 +22,18 @@ const props = defineProps({
 });
 
 const emit = defineEmits(["update:value"]);
-
 const editorContainer = ref(null);
 let editorInstance = null;
 
-// 调试:打印容器尺寸
-const logContainerSize = () => {
-  if (!editorContainer.value) {
-    // console.log('Editor container not yet mounted');
-    return;
-  }
-  const rect = editorContainer.value.getBoundingClientRect();
-  // console.log('Container size:', rect.width, 'x', rect.height);
-};
-
 // 初始化 Monaco 编辑器
 const initEditor = async () => {
   const monaco = await loader.init();
-  
-  // 等待容器渲染完成
+
   await nextTick();
-  
-  // 添加额外延迟确保布局完成(仅开发时需要)
-  if (process.env.NODE_ENV === 'development') {
-    await new Promise(resolve => setTimeout(resolve, 50));
-  }
 
-  // 再次检查尺寸
-  const rect = editorContainer.value.getBoundingClientRect();
-  // console.log('Final container size:', rect.width, 'x', rect.height);
+  if (process.env.NODE_ENV === "development") {
+    await new Promise((resolve) => setTimeout(resolve, 50));
+  }
 
   editorInstance = monaco.editor.create(editorContainer.value, {
     value: props.value || "",
@@ -53,38 +43,32 @@ const initEditor = async () => {
 
   editorInstance.onDidChangeModelContent(() => {
     const value = editorInstance.getValue();
-    emit("update:value", value);  // 触发v-model更新
+    emit("update:value", value);
   });
 
-  // 强制立即布局
   editorInstance.layout();
 };
 
-// 处理窗口大小变化
-const handleResize = () => {
-  if (editorInstance) {
-    // console.log('Window resized, updating editor layout');
-    editorInstance.layout();
-  }
-};
-
 onMounted(() => {
-  // console.log('Component mounted, initializing editor...');
   initEditor();
 });
 
 onBeforeUnmount(() => {
-  // console.log('Component unmounting, disposing editor...');
-  window.removeEventListener('resize', handleResize);
+  window.removeEventListener("resize", handleResize);
   editorInstance?.dispose();
 });
 
+const handleResize = () => {
+  if (editorInstance) {
+    editorInstance.layout();
+  }
+};
+
 // 监听语言变化
 watch(
   () => props.language,
   (newLanguage) => {
     if (editorInstance) {
-      console.log('Language changed to:', newLanguage);
       loader.init().then((monaco) => {
         monaco.editor.setModelLanguage(editorInstance.getModel(), newLanguage);
       });
@@ -92,12 +76,11 @@ watch(
   }
 );
 
-// 监听变化
+// 监听 value 变化
 watch(
   () => props.value,
   (newValue) => {
     if (editorInstance && editorInstance.getValue() !== newValue) {
-      console.log('Value updated programmatically');
       editorInstance.setValue(newValue);
     }
   }

+ 2 - 2
src/views/titlecomponent/TACS.vue

@@ -268,8 +268,8 @@ let tacsvalue = ref({
   nu:'0.33',
   ys:'262.0e6',
   useffd: 1,
-  l2convergence:'1e3',
-  l2convergencerel:'1e3'
+  l2convergence:'1e-10',
+  l2convergencerel:'1e-6'
 })
 
 let writesolution = ref(1);

+ 13 - 0
vite.config.ts

@@ -3,6 +3,8 @@ import vue from '@vitejs/plugin-vue'
 import monacoEditorPlugin from 'vite-plugin-monaco-editor';
 import removeConsole from 'vite-plugin-remove-console';
 import compression from 'vite-plugin-compression';
+import sirv from 'sirv';
+import path from 'path';
 
 //1、 导入 path 模块,帮助我们解析路径
 import { resolve } from 'path'
@@ -38,6 +40,17 @@ export default defineConfig(({ mode }) => {
                 dts: "src/components.d.ts",
             }),
             VueSetupExtend(),
+            {
+              name: 'monaco-editor-local',
+              configureServer(server) {
+              server.middlewares.use(
+                '/monaco-editor',
+                sirv(path.resolve(__dirname, 'node_modules/monaco-editor/min'), {
+                    dev: true,
+                 })
+              );
+            },
+    },
         ],
 
         //1、 ↓解析配置