Browse Source

完善手动连线功能

liling 1 year ago
parent
commit
32dd656c3d
1 changed files with 63 additions and 42 deletions
  1. 63 42
      src/pages/components/drawModal/LineDouble.vue

+ 63 - 42
src/pages/components/drawModal/LineDouble.vue

@@ -175,8 +175,7 @@ export default {
                     if (res.data == null || res.data=="") {
                     if (res.data == null || res.data=="") {
                         curList.value = [];
                         curList.value = [];
                         return;
                         return;
-                    }
-                    
+                    }                    
                     let tmpList = [];
                     let tmpList = [];
                     //对结果进行重排排序:将已关联到输出装置的端子排在前面
                     //对结果进行重排排序:将已关联到输出装置的端子排在前面
                     res.data.forEach((item, index) => {
                     res.data.forEach((item, index) => {
@@ -186,8 +185,7 @@ export default {
                             //未关联的端子按原结果顺序排列
                             //未关联的端子按原结果顺序排列
                             tmpList.push(item)
                             tmpList.push(item)
                         }
                         }
-                    })
-                    
+                    })                    
                     curList.value = tmpList
                     curList.value = tmpList
                     //pastLoading.value = false
                     //pastLoading.value = false
                 } else {
                 } else {
@@ -220,41 +218,41 @@ export default {
                             //未关联的端子按原结果顺序排列
                             //未关联的端子按原结果顺序排列
                             tmpList.push(item)
                             tmpList.push(item)
                         }
                         }
-                    })
-                    
+                    })                    
                     outList.value = tmpList;
                     outList.value = tmpList;
                     setIndex()
                     setIndex()
                     // 将 setTimeout 移动到 then 方法中
                     // 将 setTimeout 移动到 then 方法中
                     setTimeout(() => {
                     setTimeout(() => {
                         res.data.forEach((item, index) => {
                         res.data.forEach((item, index) => {
-
-                            let line = {
-                                start: item.from_fcda_id,
-                                end: item.id
-                            };
-                            let starts = document.getElementById(line.start);
-                            let ends = document.getElementById(line.end).parentNode;
-                            // console.log(starts, ends, '??????');
-                            // 检查 starts 和 ends 是否存在
-                            if (starts && ends) {
-                                /*
-                                leaderLineList.value.push();
-                                */
-                               const key=line.start+','+line.end
-                               leaderLineList.value[key] = new LeaderLine(starts, ends, {
-                                    color: "#ccc",
-                                    size: 2,
-                                    path: "straight",
-                                    startSocket: "right",
-                                    endSocket: "left",
-                                    endPlug: 'arrow3',
-                                    endPlugSize: 2
-                                })
-                                hiddenLine();
-                                pastLoading.value = false
-                            } else {
-                                //console.error(`Element with ID ${line.start} or ${line.end} not found.`);
+                            if(item.from_fcda_id=='' || item.from_fcda_id=='0'){
+                                return
                             }
                             }
+                            let fromfcdaids = item.from_fcda_id.split(',') //有可能会有多个id
+                            fromfcdaids.forEach((v)=>{
+                                let line = {
+                                    start: v,
+                                    end: item.id
+                                };
+                                let starts = document.getElementById(line.start);
+                                let ends = document.getElementById(line.end).parentNode;
+                                // 检查 starts 和 ends 是否存在
+                                if (starts && ends) {
+                                const key=line.start+','+line.end
+                                leaderLineList.value[key] = new LeaderLine(starts, ends, {
+                                        color: "#ccc",
+                                        size: 2,
+                                        path: "straight",
+                                        startSocket: "right",
+                                        endSocket: "left",
+                                        endPlug: 'arrow3',
+                                        endPlugSize: 2
+                                    })
+                                    hiddenLine();
+                                    pastLoading.value = false
+                                } else {
+                                    //console.error(`Element with ID ${line.start} or ${line.end} not found.`);
+                                }
+                            })
                         });
                         });
                     }, 100);
                     }, 100);
                 } else {
                 } else {
@@ -311,15 +309,15 @@ export default {
         function setIndex(row, num) {
         function setIndex(row, num) {
             if (row && num) {
             if (row && num) {
                 leftFcda.value = row.id
                 leftFcda.value = row.id
-                // checkList.value = [row.to_fcda_id]
                 fcdaIds.value = row.to_fcda_id
                 fcdaIds.value = row.to_fcda_id
                 leftIndex.value = num
                 leftIndex.value = num
             } else {      
             } else {      
                 if (curList.value.length > 0) {
                 if (curList.value.length > 0) {
                     curList.value.map(item => {
                     curList.value.map(item => {
                         if (item.to_fcda_id != '0' && item.to_fcda_id != '') {
                         if (item.to_fcda_id != '0' && item.to_fcda_id != '') {
-                            console.log(item)
-                            checkList.value.push(item.to_fcda_id)
+                            if(!checkList.value.includes(item.to_fcda_id)){
+                                checkList.value.push(item.to_fcda_id)
+                            }
                         }
                         }
                     })
                     })
                     oldCheckList.value = checkList.value
                     oldCheckList.value = checkList.value
@@ -338,10 +336,10 @@ export default {
         }
         }
         function checkChange(e) {
         function checkChange(e) {
             checkObj.value = e
             checkObj.value = e
-            //const subItem = oldCheckList.value.filter(item => !checkList.value.includes(item)); //是否取消选择,取差集
+            const subItem = oldCheckList.value.filter(item => !checkList.value.includes(item)); //是否取消选择,取差集
             const addItem = checkList.value.filter(item => !oldCheckList.value.includes(item)); //是否新选择的,取差集
             const addItem = checkList.value.filter(item => !oldCheckList.value.includes(item)); //是否新选择的,取差集
             let no = false
             let no = false
-            let hintTxt = ''
+            let hintTxt = '不允许的操作'
             if(addItem.length>0){
             if(addItem.length>0){
                 //判断是否选择源端子以及是否未关联任何其他端子,否则不允许关联                
                 //判断是否选择源端子以及是否未关联任何其他端子,否则不允许关联                
                 if(leftFcda.value==''){
                 if(leftFcda.value==''){
@@ -352,8 +350,28 @@ export default {
                     //源端子已有关联
                     //源端子已有关联
                     hintTxt = "选择源(左侧)端子已有关联,请先取消关联或选择其它端子!"
                     hintTxt = "选择源(左侧)端子已有关联,请先取消关联或选择其它端子!"
                     no=true
                     no=true
-                }              
+                }
                 fcdaRelationDlgTitle.value = "确定在当前2个端子间建立关联关系?"
                 fcdaRelationDlgTitle.value = "确定在当前2个端子间建立关联关系?"
+            }else if(subItem.length>0){
+                if(fcdaIds.value=='' || fcdaIds.value=='0'){
+                    //当前选择的源端子还未关联任何端子时,可以尝试让用户选择继续建立关联
+                    fcdaRelationDlgTitle.value = "当前端子已有关联,是否继续建立关联关系?"
+                }else if(e.from_fcda_id.indexOf(leftFcda.value)==-1){
+                    //当用户取消关联操作,但左侧选中的端子不是当前端子已关联之一
+                    ElMessage({
+                        type: "info",
+                        message: "请先选择已关联的对应源(左侧)端子!"
+                    })
+                    //恢复选择框状态
+                    checkList.value.push(e.id)
+                    oldCheckList.value=checkList.value
+                    return
+                }else if(e.from_fcda_id.indexOf(leftFcda.value)>-1){
+                    //当用户取消关联操作,并且左侧选中的端子为当前端子已关联之一,可进行后续操作
+                    fcdaRelationDlgTitle.value = "是否取消当前2个端子关联关系?"
+                }
+            }else{
+                return
             }
             }
             if(no){
             if(no){
                     ElMessage({
                     ElMessage({
@@ -365,6 +383,7 @@ export default {
                     checkList.value.splice(ind,1)
                     checkList.value.splice(ind,1)
                     return
                     return
             }
             }
+            //用户操作确认框
             sureModal.value = true
             sureModal.value = true
         }
         }
         //弹窗打开后使得线条在指定区域中
         //弹窗打开后使得线条在指定区域中
@@ -409,10 +428,11 @@ export default {
                 return
                 return
             }
             }
             fcdaIds.value = checkObj.value.id
             fcdaIds.value = checkObj.value.id
-            if(subItem.length>0){
+            //单关联删除或删除多端子关联关系之一
+            if(subItem.length>0 && checkObj.value.from_fcda_id.indexOf(leftFcda.value)>-1){
                 flow.delModelFcdaOn({
                 flow.delModelFcdaOn({
                     model_id: modelIds.value - 0,
                     model_id: modelIds.value - 0,
-                    from_fcda_id :checkObj.value.from_fcda_id - 0,
+                    from_fcda_id :leftFcda.value - 0,
                     to_fcda_id :fcdaIds.value
                     to_fcda_id :fcdaIds.value
                 }).then(res=>{
                 }).then(res=>{
                     if (res.code == 0) {
                     if (res.code == 0) {
@@ -436,7 +456,8 @@ export default {
                     })
                     })
                 })
                 })
             }
             }
-            if(addItem.length>0){
+            //单端子关联或者多端子关联
+            if(addItem.length>0 || (subItem.length>0 && checkObj.value.from_fcda_id.indexOf(leftFcda.value)==-1)){
                 flow.saveModelOn({
                 flow.saveModelOn({
                     model_id: modelIds.value - 0,
                     model_id: modelIds.value - 0,
                     from_ied_type: starts.value.ied_type,
                     from_ied_type: starts.value.ied_type,