123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644 |
- <template>
- <VueFlow ref="vueFlowRef" v-model:nodes="nodes" v-model:edges="edges" :class="{ dark }"
- class="basic-flow"
- :style="backgroundStyle"
- :default-viewport="{ zoom: 1.5 }" :min-zoom="0.2" :max-zoom="2.5" @drop="onDrop1"
- @node-contextmenu="onNodeContextMenu"
- @dragover="onDragOver" @dragleave="onDragLeave" @edge-click="onEdgeClick" @node-double-click="onNodeDoubleClick"
- @node-click="onNodeClick" @edge-double-click="onEdgeDoubleClick">
- <!-- 自定义节点类型为default的节点 -->
- <template #node-default="props">
- <eltree :node="props" />
- </template>
- <!-- 自定义节点类型为group的节点 -->
- <template #node-group="props">
- <eltreeGroup :node="props" />
- </template>
-
- <Background pattern-color="#aaa" :gap="16"
- />
- <!-- <MiniMap /> @input="handleUpdate"-->
- <Panel :position="'right'" style="display: none;">
- <div class="field">
- <div>
- <label for="label">Label:</label>
- <input id="label" v-model.lazy="labelname" /></div>
- <button @click="handleUpdate" class="lableaniu">确定</button>
- </div>
- <!-- <div> -->
- <!-- <button class="remove" @click="removeNode(event)">N</button>
- <button class="remove" @click="removeEdge(event)">E</button>
- <button class="remove" @click="removeall(event)">all</button>
-
- </div> -->
- <!-- <button @click="onSelection()" class="lableaniu">获取</button> -->
- </Panel>
- <Controls position="top-left">
- <ControlButton title="重置" @click="resetTransform">
- <Icon name="reset" />
- </ControlButton>
- <ControlButton title="背景切换" @click="toggleDarkMode">
- <Icon v-if="dark" name="sun" />
- <Icon v-else name="moon" />
- </ControlButton>
- <ControlButton title="保存" @click="logToObject1">
- <!-- <Icon name="log" /> -->
- <el-icon :color="iconcolor"><UploadFilled /></el-icon>
- </ControlButton>
- <ControlButton title="删除节点" @click="removeNode()">
- <el-icon :color="iconcolor"><DocumentDelete /></el-icon>
- </ControlButton>
- <ControlButton title="删除线" @click="removeEdge()">
- <el-icon :color="iconcolor"><Crop /></el-icon>
- </ControlButton>
- <ControlButton title="清空全部" @click="confirmDelete()">
- <el-icon :color="iconcolor"><DeleteFilled /></el-icon>
- </ControlButton>
-
-
- </Controls>
- <el-dialog v-model="changeNameshow" align-center :modal="false" :close-on-click-modal="false"
- :append-to-body="true" draggable :fullscreen="false" :modal-append-to-body="false" modal-class="summary-dlg"
- width="400" class="dialog_class bgcolor colortext tianjia sel">
- <template #header="{ titleId, titleClass }">
- <div class="my-header ">
- <h4 :id="titleId" :class="titleClass">修改名称</h4>
- </div>
- </template>
- <div style="margin-top: 20px;padding: 20px;">
- <el-form :model="changeName" label-width="100px" class="demo-ruleForm">
- <el-form-item label="新名称:" prop="name">
- <el-input v-model="changeName.name" placeholder="请输入名称" maxlength="20"></el-input>
- </el-form-item>
-
- </el-form>
- </div>
-
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="changeNameshow = false">取 消</el-button>
- <el-button type="primary" @click="handleUpdate">确 定</el-button>
- </div>
- </template>
- </el-dialog>
- <!-- 双击线段 -->
- <el-dialog v-model="dataflowshow" align-center :modal="false" :close-on-click-modal="false"
- :append-to-body="true" draggable :fullscreen="false" :modal-append-to-body="false" modal-class="summary-dlg"
- width="500" class="dialog_class bgcolor colortext tianjia sel">
- <template #header="{ titleId, titleClass }">
- <div class="my-header ">
- <h4 :id="titleId" :class="titleClass">数据流</h4>
- </div>
- </template>
- <div style="margin-top: 5px;padding: 10px 35px;">
- <linetablecard v-if="datacontent === '1'"
- v-model:check-all="checkAll"
- v-model:table-data="youhuaFFDtable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '2'"
- v-model:check-all="checkAll"
- v-model:table-data="youhuaCSTtable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '3'"
- v-model:check-all="checkAll"
- v-model:table-data="ADflowyouhuatable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '4'"
- v-model:check-all="checkAll"
- v-model:table-data="Xfoilyouhuatable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '5'"
- v-model:check-all="checkAll"
- v-model:table-data="ADflowMathfunctable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '6'"
- v-model:check-all="checkAll"
- v-model:table-data="TacsMathFunctable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '7'"
- v-model:check-all="checkAll"
- v-model:table-data="youhuaTACStable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '8'"
- v-model:check-all="checkAll"
- v-model:table-data="MathFuncyouhuatable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '9'"
- v-model:check-all="checkAll"
- v-model:table-data="Tacsyouhuatable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- @check-flag-change="handlecheckFlagchange"
- />
- <linetablecard v-if="datacontent === '10'"
- v-model:check-all="checkAll"
- v-model:table-data="youhuaMathFunctable"
- :steamtype-options="steamtypeoptions"
- :is-indeterminate="isIndeterminate"
- :is-youhua="false"
- @check-flag-change="handlecheckFlagchange"
- />
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="dataflowshow = false">取 消</el-button>
- <el-button type="primary" @click="confirmselection();dataflowshow = false ">确 定</el-button>
- </div>
- </template>
- </el-dialog>
- </VueFlow>
- <div class="dnd-flow">
- <!-- <div id="contextMenu" @click="deleteItemConfirm">删除</div> -->
- </div>
- </template>
- <script setup>
- import { ref, markRaw,inject } from 'vue'
- import { VueFlow,Panel, useVueFlow, MarkerType} from '@vue-flow/core'
- import { ElMessage, ElButton, ElDialog, ElSelect, ElMessageBox} from 'element-plus'
- import {
- DocumentDelete,
- Delete,
- UploadFilled,
- Histogram,
- DeleteFilled,
- Crop,
- } from '@element-plus/icons-vue'
- import { useRoute } from 'vue-router';
- import { request, uploadFile } from "@/utils/request";
- import { Background } from '@vue-flow/background'
- import { ControlButton, Controls } from '@vue-flow/controls'
- import { initialEdges, initialNodes } from './modeljs.js'
- import { MiniMap } from '@vue-flow/minimap'
- import "./main.css";//重置样式
- import DropzoneBackground from './DropzoneBackground.vue'
- import eltree from './eltree.vue'
- import eltreeGroup from './eltreeGroup.vue'
- import CustomEdge from './CustomEdge.vue';
- import useDragAndDrop from './useDnD';
- import f11 from '@/assets/img/f11.png'
- import r2 from '@/assets/img/r2.png'
- import html2canvas from 'html2canvas';
- import Icon from './Icon.vue'
- import { formatTime } from '@/js/lindex.js';
- import emitter from "@/utils/emitter";
- import linetablecard from '@/views/vuetree/linetablecard.vue'
- // import func from 'vue-temp/vue-editor-bridge.js';
- import backgroundImg from '@/assets/flowimg/surromdao.png'
- const backgroundStyle = {
- backgroundImage: `url(${backgroundImg})`,
- backgroundPosition: 'center',
- backgroundRepeat: 'no-repeat'
- }
- const dark = ref(false)
- let datatree=ref();
- const route = useRoute();
- const { onInit, onNodeDragStop, onNodeContextMenu, onConnect, addEdges, setViewport, toObject,addNodes,updateEdgeData,onConnectStart} = useVueFlow()
- let vueFlowRef = ref();
- let emit = defineEmits(['optimizerfalse']);
- let mergedObj=ref();
- let labelname=ref();
- let iconcolor=ref('#000')
- const props = defineProps({
- optimizer: {
- type: Boolean,
- },
- jboptimizer: {
- type: Boolean,
- },
- Xfoil: {
- type: Boolean,
- },
- // color1: {
- // type: String,
- // },
- })
- let newobj=ref({
- name:'',
- description:'',
- })
- let nodesitem=ref([]);
- let linenum=ref(1);
- let bgcolor=ref();
- let linecolor=ref('#2267B1')
- let pid=ref('');
- let newroter=ref();
- let vueflowimg=ref('');
- const shopShow = ref(false);
- // 选中节点
- let noid = ref([]);
- let Edgeid = ref();
- let seledge=ref(null);
- let djshow=ref(false);
- let node = ref();
- let contextMenu = ref({
- position: { x: 0, y: 0 },
- target: 'kong',
- })
- let Nested=ref([]);
- let Nested2=ref([]);
- let nnum=ref(0);
- const { onDragOver, onDrop, onDragLeave, isDragOver } = useDragAndDrop();
- const edges = ref([]);
- const nodes = ref([]);
- const changeNameshow = ref(false);
- const changeName = ref({
- name: '',
-
- })
- // 旧数据存储
- let prevNodes = [...nodes.value];
- let prevEdges = [...edges.value];
- // 监听节点变化
- watch(nodes, (newNodes) => {
- const deletedNodes = prevNodes.filter((node) => !newNodes.some((n) => n.id === node.id));
- if (deletedNodes.length > 0) {
- console.log("Deleted Nodes:", deletedNodes);
- // 处理节点删除逻辑
- }
- prevNodes = [...newNodes];
- }, { deep: true });
- // 监听连线变化
- watch(edges, (newEdges) => {
- const deletedEdges = prevEdges.filter((edge) => !newEdges.some((e) => e.id === edge.id));
- if (deletedEdges.length > 0) {
- console.log("Deleted Edges:", deletedEdges);
- // 处理连线删除逻辑
- }
- prevEdges = [...newEdges];
- }, { deep: true });
- onNodeContextMenu((e) => {
- noid.value = e.node;
- changeName.value.name = e.node.data.label;
- changeNameshow.value = true;
- })
- // 监听连接开始,提前取消选中的线段
- onConnectStart(() => {
- cleanEdgeselect();
- });
- // 线的类型 process-逻辑线 data-数据线
- let lineType = ref('process');
- // 线序号
- let linecount = ref(0);
- onConnect((connection) => {
- console.log('线连接',connection);
- // 创建唯一的边ID(由源节点和目标节点组成)
- const edgeId = `${lineType.value}-${connection.source}-${connection.sourceHandle}-${connection.target}-${connection.targetHandle}`;
- connection.id = edgeId; // 自定义 ID
- connection.type = 'smoothstep';// smoothstep straight
- connection.zIndex = lineType.value === 'process' ? 10 : 5; // 逻辑流在上,数据流在下
- connection.interactionWidth = lineType.value === 'process' ? 5 : 20; // 降低逻辑流窄线判定范围,避免二者重叠无法判定
- if(lineType.value === 'process'){
- connection.markerEnd = MarkerType.ArrowClosed;
- }else if(lineType.value === 'data'){
- connection.markerEnd = {
- type: MarkerType.ArrowClosed,
- width: 6, // 设置宽度(箭头大小)
- height: 6, // 设置高度(箭头大小)实测长宽一样才生效
- color: linecolor.value, // 设置颜色
- };
- }
- // connection.markerEnd = lineType.value === "data" ? "" : MarkerType.ArrowClosed;
- connection.color=linecolor.value;
- // connection.label = '这是一条注释';
- connection.style = { strokeWidth:linenum.value ,stroke:linecolor.value};
- // 连接数据流线前应先连接逻辑流
- // if(lineType.value === 'data'){
- // const processEdgeId = `process-${connection.source}-${connection.sourceHandle}-${connection.target}-${connection.targetHandle}`;
- // const hasProcessEdge = edges.value.some(edge => edge.id === processEdgeId);
- // if(!hasProcessEdge){
- // ElMessage({
- // message:'请先连接逻辑流连线!',
- // type:'error'
- // })
- // return;
- // }
- // }
- // 相同线删除上一条线的流
- const sameEdge = edges.value.find(edge => edge.id === edgeId);
- if(sameEdge){
- deleteflow(sameEdge.data.wid);
- }
- 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 = () => {
- if (noid.value && noid.value.data) {
- noid.value.data.label = changeName.value.name; // 更新名称
- console.log(noid.value.data.label); // 打印更新后的值
- } else {
- console.error("noid.value 或 noid.value.data 未定义"); // 错误日志
- }
- changeNameshow.value = false; // 更新后关闭对话框
- // noid.value.data.label = labelname;
- };
- emitter.on('child2Data', data => {
- datatree.value = data;
- console.log("datatree的值:",datatree.value);
- })
- function onNodeClick(e) {
- noid.value = e.node;
- changeName.value.name=e.node.data.label;
- console.log("shuju:",e.node.data);
- console.log("noid.value:",noid.value);
- console.log("changeName.value:",changeName.value.name);
- djshow.value = !djshow.value;
- // if(djshow.value){
- // console.log('选中');
- // }else{
- // console.log('取消选中');
- // }
- }
- //模块化
- const bgcolorfunc= (color)=>{
- bgcolor.value=color;
- if(noid.value.style!=undefined){
- console.log(noid.value.style);
- noid.value.style.backgroundColor=color;
- }
- }
- function onSelection(){
- let positionX=[];
- let positiony=[];
- for(let i=0;i<Nested.value.length;i++){
- // Nested2.value.push(Nested.value[i]);
- positionX.push(Nested.value[i].position.x)
- positiony.push(Nested.value[i].position.y)
- }
- let xmin=Math.min(...positionX);
- let ymax=Math.max(...positiony);
- console.log(positionX);
- // console.log( positionX)
- // console.log(44444)
- // console.log( positiony)
- nnum.value++;
- // let x=Math.floor(Math.random() * 91) + 10;
- // let y=Math.floor(Math.random() * 91) + 10;
- let name='模块'+nnum.value
- let item= {
- id:nnum.value.toString(),
- data: { label:name },
- position: { x:xmin , y:ymax},
- style: { backgroundColor: bgcolor.value, width: '200px',height: '200px' },
- //children: [],
- }
-
- if(Nested.value.length!=0){
- Nested2.value=[];
- for(let i=0;i<Nested.value.length;i++){
- Nested2.value.push(Nested.value[i]);
- }
- console.log(Nested2.value);
- nodesitem.value= Nested2.value.map(node => {
- if(node.parentNode==undefined){
-
- node.isParent=false;
- node.parentNode=item.id;
- console.log( node.parentNode)
- node.position.x= node.position.x /2;
- node.position.y= node.position.y/2;
- node.expandParent=true;
- //positionxy=node.position;
- // node.extent='parent';
- // return node;
- }
- return node;
- })
-
- }
- nodes.value.push(item)
- for(let i=0;i<nodesitem.value.length;i++){
- console.log(nodesitem.value[i]);
- nodes.value.push(nodesitem.value[i])
- }
- console.log( nodes.value);
- }
- function onNodeDoubleClick(e) {
- noid.value = e.node;
- const nowid = e.node.data.wid;
- console.log( e.node.data.name);
- if (e.node.data.name == 'optimizer') {
- emit('optimizerfalse',{name:'优化器',wid:nowid});
- }else if(e.node.data.name=="optimizer1"){
- emit('optimizerfalse',{name:'进化优化器',wid:nowid});
- }else if(e.node.data.name=="optimizer3"){
- emit('optimizerfalse',{name:'代理优化器',wid:nowid});
- }else if(e.node.data.name=="Xfoil"){
- emit('optimizerfalse',{name:'Xfoil',wid:nowid});
- }else if(e.node.data.name=="optimizer2"){
- emit('optimizerfalse',{name:'梯度优化器',wid:nowid});
- }else if(e.node.data.name=="CST"){
- emit('optimizerfalse',{name:'CST',wid:nowid});
- }else if(e.node.data.name=="ADflow"|| e.node.data.name=="RAE2822"){
- emit('optimizerfalse',{name:'ADflow',wid:nowid});
- }else if(e.node.data.name=="FFD"){
- emit('optimizerfalse',{name:'FFD',wid:nowid});
- }else if(e.node.data.name=="TACS"){
- emit('optimizerfalse',{name:'TACS',wid:nowid});
- }else if(e.node.data.name=="参数化"){
- emit('optimizerfalse',{name:'参数化',wid:nowid});
- }else if(e.node.data.name=="气动分析"){
- emit('optimizerfalse',{name:'气动分析',wid:nowid});
- }else if(onPythonlist.value.some(item => e.node.data.name.includes(item))){
- emit('optimizerfalse',{name:e.node.data.name,wid:nowid});
- }else if(e.node.data.name=="CATIA"){
- emit('optimizerfalse',{name:'CATIA',wid:nowid});
- }else if(e.node.data.name=="FSI"){
- emit('optimizerfalse',{name:'FSI',wid:nowid});
- }else if(e.node.data.name=="Flight"){
- emit('optimizerfalse',{name:'Flight',wid:nowid});
- }else if(e.node.data.name=="MathFunc"){
- emit('optimizerfalse',{name:'MathFunc',wid:nowid});
- }
- }
- let onPythonlist=ref(['Python','Branin','Rosenbrock','Rastrigin','G9','Forrester']);
- let previousEdge = null; // 用于保存上一个选中的边缘
- // 监听线
- function onEdgeClick(e) {
- console.log('Edge Click', e.edge);
- console.log('所有线段:',edges.value);
- // 如果已经有选中的边缘
- if (seledge.value) {
- // 恢复上一个选中边缘的样式
- if (previousEdge) {
- previousEdge.style = {
- ...previousEdge.style,
- stroke: previousEdge.originalColor, // 恢复原始颜色
- strokeWidth: previousEdge.originalWidth,// 恢复原始宽度
- };
- }
- }
- // 保存当前点击的边缘为选中边缘
- Edgeid.value = e.edge.id;
- seledge.value = e.edge;
- // 暂时更改当前选中边缘的样式
- seledge.value.originalColor = seledge.value.style.stroke; // 保存当前边缘的原始颜色
- seledge.value.originalWidth = seledge.value.style.strokeWidth; // 保存当前边缘的原始宽度
- const isProcess = e.edge.data.type === 'process';
- seledge.value.style = {
- ...seledge.value.style,
- stroke: isProcess ? '#2267B1' : 'rgba(255, 255, 0, 0.3)',// 设置选中边缘的颜色
- strokeWidth: isProcess ? 2 : 6,// 设置选中边缘的宽度
- };
- // 保存当前选中的边缘作为上一个选中边缘
- previousEdge = seledge.value;
- }
- let dataflowshow=ref(false);
- let youhuaFFDtable = ref([
- { code:'FFD参数(sample)', name:'FFD参数(sample)', steamflag:1 }
- ])
- let youhuaCSTtable = ref([
- { code:'上表面CST参数(upper)', name:"上表面CST参数(upper)", steamflag:1 },
- { code:'下表面CST参数(lower)', name:'下表面CST参数(lower)', steamflag:1 }
- ])
- let youhuaTACStable = ref([
- { code:'TACS参数', name:'TACS参数', steamflag:1 }
- ])
- let steamtypeoptions = ref([
- { label:'约束条件', value:1 },
- { label:'优化目标', value:2 }
- ])
- let ADflowyouhuatable = ref([
- { code: "cl", name:'升力系数Cl', comtype:2 , steamflag:1, steamtype:1 },
- { code: "cd", name:'阻力系数Cd', comtype:2 , steamflag:1, steamtype:1 },
- { code: "cm", name:'力矩系数Cm', comtype:2 , steamflag:1, steamtype:1 },
-
- ])
- let ADflowMathfunctable = ref([])
- let TacsMathFunctable = ref([])
- let MathFuncyouhuatable = ref([])
- let Xfoilyouhuatable = ref([
- // { code:'', name:'升力系数Cl', comtype:2 , steamflag:1, steamtype:1 },
- // { code:'', name:'阻力系数Cd', comtype:2 , steamflag:1, steamtype:1 },
- // { code:'', name:'压阻力系数Cdp', comtype:2 , steamflag:1, steamtype:1 },
- // { code:'', name:'力矩系数Cm', comtype:2 , steamflag:1, steamtype:1 },
- // { code:'', name:'上表面转换点位置xtr-upper', comtype:2 , steamflag:1, steamtype:1 },
- // { code:'', name:'下表面转换点位置xtr-lower', comtype:2 , steamflag:1, steamtype:1 },
- ])
- let Tacsyouhuatable = ref([])
- let youhuaMathFunctable = ref([])
- let checkAll = ref(false);
- let isIndeterminate = ref(false);
- const dataTables = {
- '1': youhuaFFDtable,
- '2': youhuaCSTtable,
- '3': ADflowyouhuatable,
- '4': Xfoilyouhuatable,
- '5': ADflowMathfunctable,
- '6': TacsMathFunctable,
- '7': youhuaTACStable,
- '8': MathFuncyouhuatable,
- '9': Tacsyouhuatable,
- '10': youhuaMathFunctable,
- };
- const handlecheckFlagchange = () => {
- const table = dataTables[datacontent.value];
- if (!table) return;
- let checkedCount = table.value.filter(item => Boolean(item.steamflag)).length;
- checkAll.value = checkedCount === table.value.length;
- isIndeterminate.value = checkedCount > 0 && checkedCount < table.value.length;
- };
- const handlecheckAllchange = (val) => {
- const table = dataTables[datacontent.value];
- if (!table) return;
- table.value.forEach(item => item.steamflag = val ? 1 : 0);
- isIndeterminate.value = false;
- };
- // 双击线段弹窗确认
- const confirmselection=()=>{
- const table = dataTables[datacontent.value];
- let checkedData = table.value.filter((item) => item.steamflag).map((item) => item.name);
- console.log('xuanzhongshuju:',checkedData);
- console.log('seledge:',seledge.value);
- seledge.value.label=checkedData.join('\n');
- // 保存数据流
- if(datacontent.value === '1'){
- dataFlowsave1(ffdid.value,'2');
- }else if(datacontent.value === '2'){
- dataFlowsave1(cstid.value,'0');
- }else if(datacontent.value === '7'){
- dataFlowsave1(tacsid.value,'5');
- }else if(datacontent.value === '5'){
- dataFlowsave2(adid.value,'3',mfcid.value,'4');
- }else if(datacontent.value === '6'){
- dataFlowsave2(tacsid.value,'5',mfcid.value,'4');
- }else{
- dataFlowsave();
- }
-
-
- dataflowshow.value = false;
- }
- const xfid = ref('')
- const adid = ref('')
- const mfcid = ref('')
- const tacsid = ref('')
- const ffdid = ref('')
- const cstid = ref('')
- // 监听组件xfoil返回的xfid
- const handleXfid = (xfidFromB) => {
- xfid.value = xfidFromB.value;
- noid.value.data.xfid = xfid.value;
- };
- const handleAdid = (adidFromB) => {
- adid.value = adidFromB.value;
- noid.value.data.adid = adid.value;
- }
- const handleMfcid = (mfcidFromB) => {
- mfcid.value = mfcidFromB.value;
- noid.value.data.mfcid = mfcid.value;
- };
- const handleTacsid = (tacsidFromB) => {
- tacsid.value = tacsidFromB.value;
- noid.value.data.tacsid = tacsid.value;
- };
- const handleFfdid = (ffdidFromB) => {
- // console.log('ffdidFromB:',ffdidFromB.value);
- ffdid.value = ffdidFromB.value;
- noid.value.data.ffdid = ffdid.value;
- // console.log('noid.value.data.ffdid:',noid.value.data.ffdid);
- };
- const handleCstid = (cstidFromB) => {
- cstid.value = cstidFromB.value;
- noid.value.data.cstid = cstid.value;
- };
- // 用于自动mathfunc的mfcid
- const handlegetMfcid = ({id,nowid}) => {
- getMfcid(id,nowid);
- }
- let equation = 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]`);
- const getMfcid = (id,nowid) => {
- const params = {
- transCode: "MDO0064",
- pid: id,
- wid: nowid,
- equation: equation.value
- };
- request(params).then((res) => {
- // console.log("获取mfcid成功", res.mfcid);
- mfcid.value = res.mfcid;
- })
- .catch((err) => {
- console.log("获取mfcid失败", err);
- })
- }
- let datacontent = ref('')
- // 判定是哪种线段
- function onEdgeDoubleClick(e) {
-
- console.log('Edge Double Click', e)
- if(e.edge.data.type==='process'){
- console.log('逻辑流不打开弹窗');
- return ;
- }
- seledge.value = e.edge;
- // dataflowshow.value = true
- console.log('qidian:',e.edge.sourceNode.data.name);
- console.log('zhongdian:',e.edge.targetNode.data.name);
- let qidian = e.edge.sourceNode.data.name;
- let zhongdian = e.edge.targetNode.data.name;
- let youhualist = ['optimizer','optimizer3','optimizer1','optimizer2'];
- if( youhualist.includes(qidian) && zhongdian ==='FFD' ){
- datacontent.value = '1';
- ffdid.value = e.edge.targetNode.data.ffdid;
- if(ffdid.value) {
- dataflowshow.value = true;
- }else{
- ElMessage.error('FFD未初始化!')
- }
- }else if( youhualist.includes(qidian) && zhongdian ==='CST') {
- datacontent.value = '2';
- cstid.value = e.edge.targetNode.data.cstid;
- if(cstid.value) {
- dataflowshow.value = true;
- }else{
- ElMessage.error('CST未初始化!')
- }
- // dataflowshow.value = true;
- }else if( qidian === 'ADflow' && youhualist.includes(zhongdian) ) {
- datacontent.value = '3';
- // emitter.emit('requestGetadid',pid.value);
- adid.value = e.edge.sourceNode.data.adid;
- // console.log('adid:',adid.value)
- if(adid.value) {
- querydataFlow(adid,2);
- dataflowshow.value = true;
- }else{
- ElMessage.error('ADflow未初始化!')
- }
- }else if ( qidian === 'Xfoil' && youhualist.includes(zhongdian) ) {
- datacontent.value = '4';
- // emitter.emit('requestGetxfid',pid.value);
- xfid.value = e.edge.sourceNode.data.xfid;
- // console.log('xfid:',xfid.value)
- if(xfid.value) {
- querydataFlow(xfid,2);
- dataflowshow.value = true;
- }else{
- ElMessage.error('Xfoil未初始化!')
- }
- }else if ( qidian === 'ADflow' && zhongdian ==='MathFunc' ) {
- datacontent.value = '5';
- adid.value = e.edge.sourceNode.data.adid;
- mfcid.value = e.edge.targetNode.data.mfcid || mfcid.value;
- if(adid.value&&mfcid.value) {
- querydataFlow(adid,3);
- dataflowshow.value = true;
- }else{
- ElMessage.error('ADflow未初始化!')
- }
- }else if ( qidian === 'TACS' && zhongdian ==='MathFunc' ) {
- datacontent.value = '6';
- tacsid.value = e.edge.sourceNode.data.tacsid;
- mfcid.value = e.edge.targetNode.data.mfcid || mfcid.value;
- if(tacsid.value&&mfcid.value) {
- querydataFlow(tacsid,3);
- dataflowshow.value = true;
- }else{
- ElMessage.error('TACS未初始化!')
- }
- }else if( youhualist.includes(qidian) && zhongdian ==='TACS') {
- datacontent.value = '7';
- tacsid.value = e.edge.targetNode.data.tacsid;
- if(tacsid.value) {
- dataflowshow.value = true;
- }else{
- ElMessage.error('TACS未初始化!')
- }
- // dataflowshow.value = true;
- }else if( qidian ==='MathFunc' && youhualist.includes(zhongdian)) {
- datacontent.value = '8';
- mfcid.value = e.edge.sourceNode.data.mfcid || mfcid.value;
- if(mfcid.value) {
- querydataFlow(mfcid,2);
- dataflowshow.value = true;
- }else{
- ElMessage.error('MathFunc未初始化!')
- }
- }else if( qidian ==='TACS' && youhualist.includes(zhongdian)) {
- datacontent.value = '9';
- tacsid.value = e.edge.sourceNode.data.tacsid;
- if(tacsid.value) {
- querydataFlow(tacsid,2);
- dataflowshow.value = true;
- }else{
- ElMessage.error('TACS未初始化!')
- }
- }else if( youhualist.includes(qidian) && zhongdian ==='MathFunc') {
- datacontent.value = '10';
- mfcid.value = e.edge.sourceNode.data.mfcid || mfcid.value;
- if(mfcid.value) {
- querydataFlow(mfcid,4);
- dataflowshow.value = true;
- }else{
- ElMessage.error('MathFunc未初始化!')
- }
- }
- console.log('leixing:',datacontent.value);
- nextTick(() => {
- handlecheckFlagchange();
- });
- }
- const querydataFlow = (comid,type) => {
- const params = {
- transCode: "MDO0052",
- pid: pid.value,
- comid: comid.value,
- type: type,
- }
- request(params).then((res) => {
- if(datacontent.value === '3'){
- ADflowyouhuatable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '4'){
- Xfoilyouhuatable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '5'){
- ADflowMathfunctable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '6'){
- TacsMathFunctable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '8'){
- MathFuncyouhuatable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '9'){
- Tacsyouhuatable.value = res.params;
- handlecheckFlagchange();
- }
- if(datacontent.value === '10'){
- // 修改 steamtype 为 4
- const modifiedParams = res.params.map(param => {
- return {
- ...param,
- steamtype: 4
- };
- });
- youhuaMathFunctable.value = modifiedParams;
- handlecheckFlagchange();
- }
- })
- .catch((err) => {
- ElMessage.error(err.returnMsg)
- })
- }
- // 求解器到优化器的数据流保存
- const dataFlowsave = () => {
- let stringArray = '';
- if(datacontent.value === '3'){
- stringArray = convertToStringArray([],ADflowyouhuatable.value);
- }else if(datacontent.value === '4'){
- stringArray = convertToStringArray([],Xfoilyouhuatable.value);
- }else if(datacontent.value === '8'){
- stringArray = convertToStringArray([],MathFuncyouhuatable.value);
- }else if(datacontent.value === '9'){
- stringArray = convertToStringArray([],Tacsyouhuatable.value);
- }else if(datacontent.value === '10'){
- stringArray = convertToStringArray([],youhuaMathFunctable.value);
- }else{
- return;
- }
- const params = {
- transCode: "MDO0053",
- paramstr: stringArray,
- };
- request(params).then((res) => {
- ElMessage({
- message: '数据流保存成功',
- type: 'success',
- })
- })
- .catch((err) => {
- ElMessage.error('数据流保存失败')
- })
- }
- const convertToStringArray = (result, Data) => {
- // console.log('Data:', Data);
- // 安全检查 Data,确保它是一个数组
- if (!Array.isArray(Data)) {
- console.error('Data should be an array');
- return result; // 返回原 result 或者根据需要返回其他默认值
- }
- result = Data.map(row => {
- // 获取每一行的 `paramid`, `steamflag`, `steamtype`
- const paramid = row.paramid ?? ' ';
- const steamflag = row.steamflag ?? '';
- const steamtype = row.steamtype ?? ' ';
- // 将字段连接为一个以逗号分隔的字符串
- return `${paramid},${steamflag},${steamtype}`;
- }).join(';'); // 每行之间用分号分隔
- return result;
- }
- // ffd、cst、tacs 等优化器到求解器的数据流保存
- const dataFlowsave1 = (comid,comtype) => {
- const params = {
- transCode: "MDO0073",
- comid: comid,
- comtype: comtype,
- };
- request(params).then((res) => {
- ElMessage({
- message: '数据流保存成功',
- type: 'success',
- })
- })
- .catch((err) => {
- ElMessage.error('数据流保存失败')
- })
- }
- // 求解器之间数据流保存
- const dataFlowsave2 = (fcomid,fcomtype,tcomid,tcomtype) => {
- let stringArray = '';
- if(datacontent.value === '5'){
- stringArray = convertToStringArray2([],ADflowMathfunctable.value);
- }else if(datacontent.value === '6'){
- stringArray = convertToStringArray2([],TacsMathFunctable.value);
- }else{
- return;
- }
- const params = {
- transCode: "MDO0074",
- fcomid: fcomid,
- fcomtype: fcomtype,
- paramstr: stringArray,
- tcomid: tcomid,
- tcomtype: tcomtype,
- };
- request(params).then((res) => {
- ElMessage({
- message: '数据流保存成功',
- type: 'success',
- })
- })
- .catch((err) => {
- ElMessage.error('数据流保存失败')
- })
- }
- const convertToStringArray2 = (result, Data) => {
- // console.log('Data:', Data);
- // 安全检查 Data,确保它是一个数组
- if (!Array.isArray(Data)) {
- console.error('Data should be an array');
- return result; // 返回原 result 或者根据需要返回其他默认值
- }
- result = Data.map(row => {
- // 获取每一行的 `paramid`, `steamflag`
- const paramid = row.paramid ?? ' ';
- const steamflag = row.steamflag ?? '';
- // 将字段连接为一个以逗号分隔的字符串
- return `${paramid},${steamflag}`;
- }).join(';'); // 每行之间用分号分隔
- return result;
- }
- // 右键更改名字
- // const onContextMenu = (e) => {
- // e.preventDefault(); // 阻止浏览器默认的右键菜单
- // const node = e.target.closest(".vue-flow__node");
- // console.log("nodes:",nodes);
- // console.log("node:",node);
- // if (node) {
- // // 获取当前右键点击的节点
- // const nodeId = node.getAttribute("data-id");
- // const clickedNode = nodes.value.find((n) => n.id === nodeId);
- // console.log("clickedNode:",clickedNode);
-
- // if (clickedNode) {
- // noid.value = clickedNode;
- // changeName.value.name = clickedNode.label; // 将当前节点的label放入弹窗中
- // changeNameshow.value = true; // 显示弹窗
- // }
- // }
- // };
- onInit((vueFlowInstance) => {
- vueFlowInstance.fitView()
- })
- onNodeDragStop(({ event, nodes, node }) => {
- console.log(nodes)
- Nested.value=nodes;
- console.log('Node Drag Stop', { event, nodes, node })
- })
- // onConnect((connection) => {
- // addEdges(connection)
- // console.log('Connection', connection)
- // })
- function updatePos() {
- nodes.value = nodes.value.map((node) => {
- return {
- ...node,
- position: {
- x: Math.random() * 400,
- y: Math.random() * 400,
- },
- }
- })
- }
- function removeEdge(id) {
- if(!seledge.value){
- return;
- }
- id = Edgeid.value;
- const wid = seledge.value.data.wid;
- vueFlowRef.value.removeEdges(id);
- deleteflow(wid);
- seledge.value=null;
- console.log('msg:',datatree.value);
- }
- // 触摸
- const onDrop1=(event)=>{
- // console.log('onDrop1:',event);
- onDrop(event);
- emitter.emit('doSomethingEvent');
- }
- function removeNode(id) {
- id = noid.value.id;
- const wid = noid.value.data.wid;
- console.log('removeNodewid:',wid);
- if(datatree.value==undefined){
- if(nodes.value.length>0){
- for (let i = 0; i <nodes.value.length; i++) {
- if(id==nodes.value[i].id){
- console.log(44444)
- console.log( nodes.value[i]);
- nodes.value.splice(i, 1)
- deleteflow(wid);
- }
- }
- console.log( nodes.value);
- }
- }else{
- if(nodes.value.length>0){
- for (let i = 0; i <nodes.value.length; i++) {
- if(id==nodes.value[i].id){
- console.log( nodes.value[i]);
- nodes.value.splice(i, 1)
- }
- }
- }
- for (let i = 0; i <datatree.value[0].children.length; i++) {
- if(id.includes(datatree.value[0].children[i].Text)){
- for (let j = 0; j <datatree.value[0].children[i].children.length; j++) {
- if(id==datatree.value[0].children[i].children[j].id){
- //datatree.value[0].children.splice(datatree.value[0].children[i].children[j], 1);
- datatree.value[0].children[i].children.splice(j, 1);
- deleteflow(wid);
- vueFlowRef.value.removeNodes(id);
- removeRelatedEdges(id);
- }
-
- }
- }
- }
- }
- }
- function removeRelatedEdges(nodeId) {
- //过滤出与该节点相关的连线
- const relatedEdges = edges.value.filter(
- (edge) => edge.source === nodeId || edge.target === nodeId
- );
-
- // 遍历删除关联的连线
- relatedEdges.forEach((edge) => {
- if (edge.data && edge.data.wid) {
- deleteflow(edge.data.wid);
- }
- });
- }
- // 删除提示
- const confirmDelete = () => {
- ElMessageBox.confirm(
- '确定要删除全部吗?删除后不可恢复!',
- '删除确认',
- {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning',
- }
- )
- .then(() => {
- removeall();
- })
- .catch(() => {
- ElMessage({
- type: 'info',
- message: '已取消删除',
- })
- })
- }
- function removeall() {
- try {
- const allnodes = nodes.value;
- const allEdges = edges.value;
- for (let i = 0; i < allnodes.length; i++) {
- if (allnodes[i].data.wid) {
- deleteflow(allnodes[i].data.wid);
- }
- }
- for (let i = 0; i < allEdges.length; i++) {
- if (allEdges[i].data.wid) {
- deleteflow(allEdges[i].data.wid);
- }
- }
- 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 = []
- }
- }
-
- } 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 = (nowid) => {
- const params = {
- transCode: 'MDO0059',
- wid: nowid,
- }
- request(params)
- .then((res) => {
- console.log(res);
- })
- .catch((err) => {
- ElMessage.error('删除流程失败')
- })
- }
- async function logToObject1() {
- const flowData = toObject();
- let obj = { nodes: flowData.nodes, edges: flowData.edges };
- mergedObj.value=JSON.stringify(obj);
- try {
- const container = vueFlowRef.value.$el;
- const canvas = await html2canvas(container);
- const img = canvas.toDataURL('image/png');
-
- // 创建一个图片元素并设置src属性为转换后的图片数据
- vueflowimg.value=img
- if(vueflowimg.value!=''){
- console.log("保存图片成功!")
- await addflow();
- }
- // 添加到DOM中或者做其他操作
- } catch (error) {
- console.error('转换出错:', error);
- }
- }
- //添加接口
- 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);
- 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,
- };
- console.log(params);
- 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)
- */
- function resetTransform() {
- setViewport({ x: 0, y: 0, zoom: 1 })
- }
- function toggleDarkMode() {
- dark.value = !dark.value;
- if(dark.value){
- iconcolor.value='#fff'
- }else{
- iconcolor.value='#000'
- }
- }
- // 禁用右键菜单的函数
- const onNodeContextMenu1 = (event) => {
- event.preventDefault();
- };
- onMounted(() => {
- setTimeout(function() {
- getroter();
- }, 1500);
- // childfun();
-
- // 点击其他区域取消线段选中
- if (vueFlowRef.value) {
- vueFlowRef.value.$el.addEventListener('click', (event) => {
- // 确保点击的不是边缘
- if (seledge.value && !event.target.closest('.vue-flow__edge')) {
- cleanEdgeselect();
- }
- });
- }
- document.addEventListener('contextmenu', onNodeContextMenu1);
- emitter.on("xfidFromxfoil", handleXfid);
- emitter.on("adidFromadflow", handleAdid);
- emitter.on("mfcidFromMathFunc", handleMfcid);
- emitter.on("tacsidFromTACS", handleTacsid);
- emitter.on("ffdidFromFfd", handleFfdid);
- emitter.on("cstidFromCst", handleCstid);
- emitter.on("getMfcid",handlegetMfcid);
- });
- const cleanEdgeselect = () => {
- if(seledge.value) {
- // 恢复选中边缘的原始样式
- seledge.value.style = {
- ...seledge.value.style,
- stroke: seledge.value.originalColor,
- strokeWidth: previousEdge?.originalWidth || 1, // 恢复原始宽度
- };
- // 清空选中的边缘
- seledge.value = null;
- Edgeid.value = null;
- previousEdge = null;
- }
-
- }
- // 在组件销毁前移除右键菜单禁用
- onBeforeUnmount(() => {
- document.removeEventListener('contextmenu', onNodeContextMenu1);
- });
- onUnmounted(() => {
- emitter.off('child2Data');
- emitter.off("xfidFromxfoil", handleXfid);
- emitter.off("adidFromadflow", handleAdid);
- emitter.off("mfcidFromMathFunc", handleMfcid);
- emitter.off("tacsidFromTACS", handleTacsid);
- emitter.off("ffdidFromFfd", handleFfdid);
- emitter.off("cstidFromCst", handleCstid);
- emitter.off("getMfcid",handlegetMfcid);
- });
- // 获取链接
- const getroter=()=>{
- //datatree.value[0].children=[];
- let objlist=JSON.parse(sessionStorage.getItem("objlist"));
- if(objlist.flow!=''){
- let nodesflow=JSON.parse(objlist.flow)
- nodes.value=nodesflow.nodes;
- edges.value=nodesflow.edges;
- }
- newobj.value.name=objlist.name;
- newobj.value.description=objlist.remark;
- pid.value=objlist.pid;
- // let item={
- // id:'1-0',
- // label: objlist.name,
- // img:r2,
- // }
- // console.log( datatree.value[0].children);
- // datatree.value[0].children.push(item);
- }
- //改变线的类型
- const linestrokeWidth=(type)=>{
- if(type=='process'){
- linenum.value=1;
- linecolor.value = '#2267B1';
- lineType.value = 'process';
- }else if(type=='data'){
- linenum.value=6;
- linecolor.value = "rgba(150, 150, 150, 0.2)";
- lineType.value = 'data';
- }
- }
- //改变线的颜色
- const changeAllEdgesColor = (color1) => {
- console.log('yanse:', color1);
- linecolor.value = color1;
- // 找到当前选中的边缘
- if (seledge.value) {
- // 更新该边缘的颜色
- let newColor = linecolor.value;
- // 如果选中的线 `linetype` 是 `data`,则增加透明度 0.2
- if (seledge.value.data.type === 'data') {
- newColor = convertToRGBA(linecolor.value, 0.2);
- }
- const updatedEdge = {
- ...seledge.value,
- style: {
- ...seledge.value.style,
- stroke: newColor, // 只修改颜色
- }
- };
- // 更新 edges 数组
- const updatedEdges = edges.value.map(edge =>
- edge.id === seledge.value.id ? updatedEdge : edge
- );
- edges.value = updatedEdges; // 持久化修改后的边缘
- }
- };
- // 颜色转换函数:将 Hex / RGB 转换为 RGBA
- const convertToRGBA = (color, alpha) => {
- if (color.startsWith('#')) {
- // 处理 Hex 颜色(例如 #ff0000 转换为 rgba(255, 0, 0, 0.3))
- const r = parseInt(color.substring(1, 3), 16);
- const g = parseInt(color.substring(3, 5), 16);
- const b = parseInt(color.substring(5, 7), 16);
- return `rgba(${r}, ${g}, ${b}, ${alpha})`;
- } else if (color.startsWith('rgb')) {
- // 处理 RGB 颜色,替换透明度
- return color.replace(/rgb(a?)\(([^)]+)\)/, `rgba($2, ${alpha})`);
- }
- return color; // 默认返回原始颜色(避免报错)
- };
- watch(() => seledge.value, (newItems, oldItems) => {
- if(seledge.value!=null){
- // seledge.value.style.stroke = linecolor.value;
- }
- });
- defineExpose({changeAllEdgesColor,linestrokeWidth,getroter,onSelection,bgcolorfunc,logToObject1});
- </script>
- <style>
- /* .vue-flow__edge.selected .vue-flow__edge-path, .vue-flow__edge:focus .vue-flow__edge-path, .vue-flow__edge:focus-visible .vue-flow__edge-path {
- stroke: #555 !important;
- } */
- .vue-flow__edge:focus .vue-flow__edge-path, .vue-flow__edge:focus-visible .vue-flow__edge-path {
- stroke: #555 !important;
- }
- .vue-flow__edge {
- text-align: left;
- /* 设置edges的左对齐 */
- }
- .vue-flow__edge-text {
- transform: translateY(-10px); /* 将 label 向上偏移 */
- background: transparent !important;
- font-size: 8px;
- font-family: 'Microsoft YaHei';
- color: #333333;
- }
- .vue-flow__edge-textbg {
- fill: transparent !important; /* 将背景设置为透明 */
- }
- #contextMenu {
- display: none;
- position: absolute;
- background-color: #fff;
- border-radius: 5px;
- padding: 10px;
- text-align: center;
- color: black;
- font-size: 14px;
- font-weight: 400;
- cursor: pointer;
- z-index: 99999;
- }
- .vue-flow__node-default.selectable:hover,
- .vue-flow__node-input.selectable:hover,
- .vue-flow__node-output.selectable:hover {
- box-shadow: none;
- }
- panel {
- cursor: pointer;
- position: absolute;
- z-index: 100000;
- }
- .remove {
- background: #fff;
- color: #666;
- margin: 0 10px;
- font-size: 12px;
- }
- .vue-flow__node-default, .vue-flow__node-input, .vue-flow__node-output{
- /* width: auto !important; */
- border: none;
- background-color: rgba(0,0,0,0);
- }
- .node-content {
- cursor: move; /* 更改鼠标光标表示可拖动 */
- }
- .vue-flow__node {
- cursor: move;
- }
- /* 禁用文本选中效果 */
- .left_main * {
- -webkit-user-select: none; /* Safari */
- -moz-user-select: none; /* Firefox */
- -ms-user-select: none; /* IE10+/Edge */
- user-select: none; /* Standard syntax */
- }
- .lableaniu{
- font-size: 12px;
- background-color: #ddd;
- padding: 4px 16px;
- /* margin-top: -17px; */
- margin-left: 5px;
- margin-top: 0px;
- border-radius: 1px;
- }
- .vue-flow__controls-button svg{
- max-width: 16px;
- max-height: 16px;
- }
- .field{
- display: flex;
- }
- </style>
|