Ver código fonte

325接口修改

tangjunhao 5 meses atrás
pai
commit
d7b77d328f

+ 6 - 6
src/views/home.vue

@@ -3399,13 +3399,13 @@ const devise = () => {
   request(params)
     .then((res) => {
       ElMessage({
-        message: res.returnMsg,
+        message: '设计变量保存成功',
         type: 'success',
       })
       getissue();
     })
     .catch((err) => {
-      ElMessage.error(err.returnMsg)
+      ElMessage.error('设计变量保存失败')
     })
 }
 //约束的添加restrain
@@ -3418,13 +3418,13 @@ const restrain = () => {
   request(params)
     .then((res) => {
       ElMessage({
-        message: res.returnMsg,
+        message: '约束条件保存成功',
         type: 'success',
       })
       getyueshu();
     })
     .catch((err) => {
-      ElMessage.error(err.returnMsg)
+      ElMessage.error('约束条件保存失败')
     })
 }
 //优化目标接口
@@ -3437,13 +3437,13 @@ const funlistaa = () => {
   request(params)
     .then((res) => {
       ElMessage({
-        message: res.returnMsg,
+        message: '优化目标保存成功',
         type: 'success',
       })
       getmub();
     })
     .catch((err) => {
-      ElMessage.error(err.returnMsg)
+      ElMessage.error('优化目标保存失败')
     })
 }
 //初始化

+ 1 - 1
src/views/home/newfile.vue

@@ -249,7 +249,7 @@ const modeladd=()=>{
     request(params)
         .then((res) => {
           ElMessage({
-                  message: res.returnMsg,
+                  message: "工程创建成功!",
                   type: 'success',
               })
               modelflow.value=res;

+ 1 - 1
src/views/home/querylist.vue

@@ -41,7 +41,7 @@
             </el-table-column>
             <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
                 <template #default="scope">
-                  <el-button size="small" type="text" icon="el-icon-delete" @click.stop="confirmDelete(scope.$index, scope.row)(scope.$index, scope.row)">删除</el-button>
+                  <el-button size="small" type="text" icon="el-icon-delete" @click.stop="confirmDelete(scope.$index, scope.row)">删除</el-button>
                 </template>
               </el-table-column>
         </el-table>

+ 9 - 9
src/views/titlecomponent/ADflow.vue

@@ -98,8 +98,8 @@
     <!-- 设置参数 -->
 
     <div
-      class="eldesign classtable dlheight"
-      style="margin-top: 10px"
+      class="eldesign classtable"
+      style="margin-top: 10px; height: 340px;overflow: auto;"
       v-show="currentTab1 == '2'"
     >
       <el-form-item label="分析对象:" :label-width="formLabelWidth1">
@@ -272,16 +272,16 @@
         <el-row>
         <el-col :span="12">
           <el-checkbox v-model="cl" :false-label="0"
-          :true-label="1" label="升力系数Cl" size="large" />
+          :true-label="1" label="升力系数Cl" style="height: 32px;" />
           <el-checkbox v-model="resrho" :false-label="0"
-          :true-label="1" label="密度残差Resrho" size="large" />
+          :true-label="1" label="密度残差Resrho" style="height: 32px;" />
       
         </el-col>
         <el-col :span="12">
           <el-checkbox v-model="cd" :false-label="0"
-          :true-label="1" label="阻力系数Cd" size="large" />
+          :true-label="1" label="阻力系数Cd" style="height: 32px;" />
           <el-checkbox v-model="cmz" :false-label="0"
-          :true-label="1" label="力矩系数Cm" size="large" />
+          :true-label="1" label="力矩系数Cm" style="height: 32px;" />
         </el-col>
       </el-row>
       </el-form-item>
@@ -361,7 +361,7 @@ let percentage = ref(0);
 let uploadStatus = ref('');
 let isUploadSuccess = ref(true);
 let formLabelWidth3 = ref(120)
-let formLabelWidth1 = ref(170)
+let formLabelWidth1 = ref(180)
 let formLabelWidth200 = ref(200)
 let currentTab1 = ref(0)
 let pid = ref()
@@ -682,12 +682,12 @@ const getadflowsave = () => {
   request(params)
     .then((res) => {
       ElMessage({
-        message: res.returnMsg,
+        message: '保存成功',
         type: "success"
       })
     })
     .catch((err) => {
-      ElMessage.error(err.returnMsg)
+      ElMessage.error('保存失败')
     })
 }
 // 更新文件名

+ 151 - 16
src/views/vuetree/index.vue

@@ -49,7 +49,7 @@
       <ControlButton title="删除线" @click="removeEdge()">
         <el-icon  :color="iconcolor"><Crop /></el-icon>
       </ControlButton>
-      <ControlButton title="清空全部" @click="removeall()">
+      <ControlButton title="清空全部" @click="confirmDelete()">
         <el-icon :color="iconcolor"><DeleteFilled /></el-icon>
       </ControlButton>
       
@@ -236,7 +236,7 @@
 <script setup>
 import { ref, markRaw,inject } from 'vue'
 import { VueFlow,Panel, useVueFlow, MarkerType} from '@vue-flow/core'
-import { ElMessage, ElButton, ElDialog, ElSelect } from 'element-plus'
+import { ElMessage, ElButton, ElDialog, ElSelect, ElMessageBox} from 'element-plus'
 import {
   DocumentDelete,
   Delete,
@@ -267,7 +267,7 @@ import emitter from "@/utils/emitter";
 const dark = ref(false)
 let datatree=ref();
 const route = useRoute();
-const { onInit, onNodeDragStop, onNodeContextMenu, onConnect, addEdges, setViewport, toObject,addNode } = useVueFlow()
+const { onInit, onNodeDragStop, onNodeContextMenu, onConnect, addEdges, setViewport, toObject,addNodes,updateEdgeData } = useVueFlow()
 let vueFlowRef = ref();
 let emit = defineEmits(['optimizerfalse']);
 let mergedObj=ref();
@@ -329,8 +329,16 @@ onNodeContextMenu((e) => {
   changeNameshow.value = true;
 })
 
+// 线的类型 process-逻辑线 data-数据线
+let lineType = ref('process');
+// 线序号
+let linecount = ref(0);
+
 onConnect((connection) => {
-  console.log(connection);
+  console.log('线连接',connection);
+  // 创建唯一的边ID(由源节点和目标节点组成)
+  const edgeId = `${connection.source}-${connection.target}`;
+  connection.id = edgeId;  // 自定义 ID
   connection.type = 'smoothstep';//  smoothstep straight
   connection.markerEnd = MarkerType.ArrowClosed;
   connection.color=linecolor.value;
@@ -338,6 +346,30 @@ onConnect((connection) => {
   connection.style = { strokeWidth:linenum.value ,stroke:linecolor.value};
   addEdges(connection)
   seledge.value=null;
+  
+  linecount.value++;
+  const newName = `Seg${linecount.value}`;
+
+  const sourceNode = vueFlowRef.value.getNode(connection.source);
+  const targetNode = vueFlowRef.value.getNode(connection.target);
+
+  // 调用 saveflow 保存数据并获取 wid
+  saveflow(pid.value, '', newName, lineType.value, sourceNode.data.uid, targetNode.data.uid)
+    .then((wid) => {
+      // 更新连接线的数据
+      const updatedData = {
+        wid: wid,
+        uid: newName,
+        type: lineType.value,
+        fromuid: sourceNode.data.uid,
+        touid: targetNode.data.uid,
+      };
+      updateEdgeData(connection.id, updatedData);
+
+    })
+    .catch((error) => {
+      console.error('保存流程失败:', error);
+    });
 })
 //修改名称
 const handleUpdate = () => {
@@ -352,7 +384,7 @@ const handleUpdate = () => {
 };
 emitter.on('child2Data', data => {
   datatree.value = data;
-  console.log(datatree.value);
+  console.log("datatree的值:",datatree.value);
 })
 
 function onNodeClick(e) {
@@ -487,6 +519,7 @@ let onPythonlist=ref(['Python','Branin','Rosenbrock','Rastrigin','G9','Forrester
 let previousEdge = null;  // 用于保存上一个选中的边缘
 // 监听线
 function onEdgeClick(e) {
+  console.log('Edge Click', e.edge);
   // 如果已经有选中的边缘
   if (seledge.value) {
     // 恢复上一个选中边缘的样式
@@ -740,9 +773,10 @@ onNodeDragStop(({ event, nodes, node }) => {
   console.log('Node Drag Stop', { event, nodes, node })
 })
 
-onConnect((connection) => {
-  addEdges(connection)
-})
+// onConnect((connection) => {
+//   addEdges(connection)
+//   console.log('Connection', connection)
+// })
 function updatePos() {
 
   nodes.value = nodes.value.map((node) => {
@@ -806,20 +840,121 @@ console.log( nodes.value);
 }
 }
 }
-function removeall(){
-  nodes.value=[];
-  edges.value=[];
-  Nested2.value=[];
-  Nested.value=[];
 
-  for (let i = 0; i <datatree.value[0].children.length; i++) {
-      for (let j = 0; j <datatree.value[0].children[i].children.length; j++) {
-        datatree.value[0].children[i].children=[];
+// 删除提示
+const confirmDelete = () => {
+  ElMessageBox.confirm(
+    '确定要删除全部吗?删除后不可恢复!',
+    '删除确认',
+    {
+      confirmButtonText: '确定',
+      cancelButtonText: '取消',
+      type: 'warning',
     }
+  )
+    .then(() => {
+      removeall();
+    })
+    .catch(() => {
+      ElMessage({
+        type: 'info',
+        message: '已取消删除',
+      })
+    })
+}
+
+function removeall() {
+  try {
+    nodes.value = []
+    edges.value = []
+    Nested2.value = []
+    Nested.value = []
+
+    // 判断 datatree 是否为空或未定义
+    if (!datatree.value || datatree.value.length === 0 || !datatree.value[0]?.children) {
+      console.warn('datatree 数据为空或未定义')
+      ElMessage({
+        type: 'warning',
+        message: '没有数据可以删除'
+      })
+      return
+    }
+
+    // 清空 datatree 的 children
+    for (let i = 0; i < datatree.value[0].children.length; i++) {
+      if (datatree.value[0]?.children[i]?.children) {
+        datatree.value[0].children[i].children = []
+      }
+    }
+
+    // 删除成功
+    ElMessage({
+      type: 'success',
+      message: '删除成功'
+    })
+  } catch (error) {
+    console.error('删除失败:', error)
+    ElMessage({
+      type: 'error',
+      message: '删除过程中出错'
+    })
+  }
+}
 
+// 流查询
+const queryflow = () => {
+  const params = {
+    transCode: 'MDO0057',
+    pid: pid.value,
+  }
+  request(params)
+  .then((res) => {
+    console.log(res);
+    
+  })
+  .catch((err) => {
+    ElMessage.error(err.returnMsg)
+  })
 }
 
+// 保存流
+const saveflow = async (pid,wid, uid, type, fromuid, touid) => {
+  const params = {
+    transCode: 'MDO0058',
+    pid: pid || '',
+    wid: wid || '', // 流ID
+    uid: uid || '',
+    type: type || '',
+    fromuid: fromuid || '',
+    touid: touid || '',
+  };
+
+  try {
+    // 直接使用 await 等待 request 返回
+    const res = await request(params);
+    return res.wid; // 返回 wid
+  } catch (err) {
+    // 处理错误
+    ElMessage.error(err.returnMsg || '保存流程失败');
+  }
+};
+
+// async function saveFlowExample() {
+//   try {
+//     const wid = await saveflow('flow123', 'user001', 'process', 'fromA', 'toB');
+//     console.log('返回的 wid:', wid);
+//   } catch (err) {
+//     console.error('保存流程失败:', err.message);
+//   }
+// }
+// saveFlowExample();
+
+// 删除流
+const deleteflow = () => {
+
 }
+
+
 async  function logToObject1() {
   let obj = { nodes: toObject().nodes,edges:toObject().edges };
   mergedObj.value=JSON.stringify(obj);

+ 80 - 5
src/views/vuetree/useDnD.js

@@ -1,6 +1,8 @@
 // import { useVueFlow,Position,MarkerType } from '@vue-flow/core';
 import { useVueFlow,Position,MarkerType} from '@vue-flow/core';
 import { ref, watch } from 'vue'
+import { ElMessage, ElButton, ElDialog, ElSelect } from "element-plus"
+import { request, uploadFile } from "@/utils/request"
 import gc1 from '@/assets/flowimg/gc1.png'
 import gc2 from '@/assets/flowimg/gc2.png'
 import gc3 from '@/assets/flowimg/gc3.png'
@@ -115,6 +117,29 @@ const state = {
   isDragging: ref(false),
 }
 
+// 保存流
+const saveflow = async (pid, wid, uid, type, fromuid, touid) => {
+  const params = {
+    transCode: 'MDO0058',
+    pid: pid || '',
+    wid: wid || '', // 流ID
+    uid: uid || '',
+    type: type || '',
+    fromuid: fromuid || '',
+    touid: touid || '',
+  };
+
+  try {
+    const res = await request(params);
+    return res.wid;
+  } catch (err) {
+    ElMessage.error(err.returnMsg);
+  }
+};
+
+// 用来存储每种组件名称出现次数的对象
+const nameCount = {}
+
 export default function useDragAndDrop() {
   const { draggedType, isDragOver, isDragging } = state
 
@@ -180,14 +205,29 @@ export default function useDragAndDrop() {
    *
    * @param {DragEvent} event
    */
-  function onDrop(event) {
+  async function onDrop(event) {
     const position = screenToFlowCoordinate({
       x: event.clientX,
       y: event.clientY,
     })
 
+    const savedObj = JSON.parse(sessionStorage.getItem("objlist"));
+    console.log('objlist',savedObj);
+    const pid = savedObj.pid;
+    const newwid = '';
+
     const nodeId = getId()
     const image1=imagefun();
+    // 获取当前组件的名称
+    const componentName = image1.name;
+
+    // 如果该组件的名称已存在,给名称添加序号
+    if (!nameCount[componentName]) {
+      nameCount[componentName] = 0;
+    }
+  
+    nameCount[componentName]++; // 增加计数
+    const newName = `${componentName}${nameCount[componentName]}`; // 新的名称加上序号
  
     let snodes=ref([]);
     let sedges=ref([]);
@@ -197,15 +237,50 @@ export default function useDragAndDrop() {
       // const edges = ref([])
 
     }else{
-      snodes.value=[];
-      sedges.value=[];
+      // 创建初始的节点数据,不包含 wid
       const newNode = {
         id: nodeId,
         type: draggedType.value,
         position,
-        data: image1,
-      }
+        data: { ...image1, uid: newName },
+      };
+
       snodes.value.push(newNode)
+
+      // 异步保存数据并更新 wid
+      saveflow(pid, newwid, newName, 'com', '', '').then((wid) => {
+      // 更新节点数据中的 wid
+      newNode.data.wid = wid;
+
+      // 使用 onNodesInitialized 来更新节点数据
+      onNodesInitialized(() => {
+        // 更新节点的其他数据
+        updateNode(nodeId, (node) => ({
+          ...node, 
+          data: {
+            ...node.data,
+            wid: newNode.data.wid,  // 更新节点中的 wid
+          },
+        }));
+      });
+    }).catch((err) => {
+      console.error('保存流程失败:', err.message);
+      ElMessage.error('保存流程失败');
+    });
+
+        // saveflow(pid , savewid, newName, 'com', '', '')
+        // console.log('返回的 wid:', widtemp.value)
+        // const wid = widtemp.value
+        // const uid = newName
+        // // 创建新节点,包含 wid 数据
+        // const newNode = {
+        //   id: nodeId,
+        //   type: draggedType.value,
+        //   position,
+        //   data: { ...image1, wid , uid}, // 将 wid 存入节点数据中
+        // }
+  
+        // snodes.value.push(newNode)
     
     }
     const { off } = onNodesInitialized(() => {