update code

main
haha 2024-07-16 22:40:50 +08:00
parent 04a44952e7
commit 23167ecc5d
4 changed files with 62 additions and 6 deletions

View File

@ -25,13 +25,63 @@ class RedNodeModel extends RectNodeModel {
this.text.x = this.x + 10; this.text.x = this.x + 10;
this.defaultFill = data.fill || "rgb(253, 208, 162)"; this.defaultFill = data.fill || "rgb(253, 208, 162)";
const startOnlyAsTarget = { const rule0 = {
message: "开始结点只能连接结束节点", message: "开始结点只能连接结束节点!",
validate: (sourceNode, targetNode, sourceAnchor, targetAnchor) => { validate: (sourceNode, targetNode, sourceAnchor, targetAnchor) => {
return sourceAnchor.type !== targetAnchor.type; let res= sourceAnchor.type !== targetAnchor.type;
return res;
}, },
}; };
this.sourceRules.push(startOnlyAsTarget); const rule1 = {
message: "同一算子不能互联!",
validate: (sourceNode, targetNode, sourceAnchor, targetAnchor) => {
return sourceNode.id !== targetNode.id;
},
};
const rule2 = {
message: "输入类型与输出类型不符!",
validate: (sourceNode, targetNode, sourceAnchor, targetAnchor) => {
let sp= sourceNode.properties.data.parameters;
let tp= targetNode.properties.data.parameters;
let inStr="";
let outStr="";
if(sourceAnchor.type=="start"){
inStr=sp.inputs.length>=sourceAnchor.idx?sp.inputs[sourceAnchor.idx-1].oper_inout_data_type:"";
}
if(sourceAnchor.type=="end"){
outStr=sp.outputs.length>=sourceAnchor.idx?sp.outputs[sourceAnchor.idx-1].oper_inout_data_type:"";
if(outStr=="same_as_input"){
outStr=sp.inputs[0].oper_inout_data_type;
}
}
if(targetAnchor.type=="start"){
inStr=tp.inputs.length>=targetAnchor.idx?tp.inputs[targetAnchor.idx-1].oper_inout_data_type:"";
}
if(targetAnchor.type=="end"){
outStr=tp.outputs.length>=targetAnchor.idx?tp.outputs[targetAnchor.idx-1].oper_inout_data_type:"";
if(outStr=="same_as_input"){
outStr=tp.inputs[0].oper_inout_data_type;
}
}
if(inStr.length>0 && outStr.length>0 ){
let tmpS=inStr.split(",").filter(d=>d).map(d=>d.toLowerCase());
let tmpE=outStr.split(",").filter(d=>d).map(d=>d.toLowerCase());
if(tmpS.sort().join(",")==tmpE.sort().join(",")){
return true;
}
if(tmpS.length>tmpE.length){
if((","+tmpS.sort().join(",")).indexOf(","+tmpE.sort().join(","))>=0){
return true;
}
}
}
return false;
},
};
this.sourceRules.push(rule1);
this.sourceRules.push(rule0);
this.sourceRules.push(rule2);
} }
getData() { getData() {
const data = super.getData(); const data = super.getData();

View File

@ -257,6 +257,7 @@ const doOutputSelected=idx=>{
.sp-text { .sp-text {
flex-grow: 1; flex-grow: 1;
display: block; display: block;
margin-left:4px;
} }
.div-param { .div-param {

View File

@ -461,6 +461,7 @@ onMounted(() => {
.sp-text { .sp-text {
flex-grow: 1; flex-grow: 1;
display: block; display: block;
margin-left:4px;
} }
.div-param{ .div-param{
.div-navs{ .div-navs{

View File

@ -72,7 +72,11 @@ const initEvent=(lf)=>{
doUpdateState() doUpdateState()
}); });
lf.on("connection:not-allowed",(a,b,c)=>{ lf.on("connection:not-allowed",(a,b,c)=>{
ElMessage.error("开始节点只能连接结束节点!"); if(a.msg=="不允许添加连线"){
ElMessage.error("开始结点只能连接结束节点!");
}else{
ElMessage.error(a.msg);
}
}); });
lf.on("node:delete",data=>{ lf.on("node:delete",data=>{
if(data.data.text.value=="目标绘图"){ if(data.data.text.value=="目标绘图"){