|
|
|
@ -35,7 +35,7 @@ |
|
|
|
|
|
|
|
|
|
<script setup> |
|
|
|
|
import { Graph, Shape } from "@antv/x6"; |
|
|
|
|
import { onMounted, ref } from "vue"; |
|
|
|
|
import { onMounted,ref } from "vue"; |
|
|
|
|
import { History } from "@antv/x6-plugin-history"; |
|
|
|
|
import wenduZK from "./components/wenduZK.vue"; |
|
|
|
|
import shiduZK from "./components/shiduZK.vue"; |
|
|
|
@ -68,7 +68,7 @@ import wenduValueSetting from "./components/wenduValueSetting.vue"; |
|
|
|
|
import shiduValueSetting from "./components/shiduValueSetting.vue"; |
|
|
|
|
import setzijie from "./components/setzijie.vue"; |
|
|
|
|
import { ElMessage } from "element-plus"; |
|
|
|
|
import tipView from "@/assets/images/guanxitu.png"; |
|
|
|
|
import tipView from '@/assets/images/guanxitu.png'; |
|
|
|
|
let graph = null; |
|
|
|
|
|
|
|
|
|
// 定义通用的端口配置,避免重复 |
|
|
|
@ -164,13 +164,9 @@ onMounted(() => { |
|
|
|
|
zIndex: 0, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
validateConnection({ sourceCell, targetCell }) { |
|
|
|
|
// 禁止连接到自身 |
|
|
|
|
if (sourceCell && targetCell && sourceCell.id === targetCell.id) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
validateConnection({ targetMagnet }) { |
|
|
|
|
return !!targetMagnet; // 验证连接点是否有效 |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
highlighting: { |
|
|
|
|
magnetAdsorbed: { |
|
|
|
@ -278,7 +274,6 @@ onMounted(() => { |
|
|
|
|
// 添加温度参数控件节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wenduValueSetting", |
|
|
|
|
id: "1", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 30, |
|
|
|
@ -292,7 +287,6 @@ onMounted(() => { |
|
|
|
|
// 添加湿度参数控件节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-shiduValueSetting", |
|
|
|
|
id: "2", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 30, |
|
|
|
@ -306,7 +300,6 @@ onMounted(() => { |
|
|
|
|
// 添加温度设置控件节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node", |
|
|
|
|
id: "3", |
|
|
|
|
width: 120, |
|
|
|
|
height: 100, |
|
|
|
|
x: 120, |
|
|
|
@ -326,7 +319,6 @@ onMounted(() => { |
|
|
|
|
// 添加代码控件1节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wenBenYu", |
|
|
|
|
id:'32', |
|
|
|
|
width: 210, |
|
|
|
|
height: 300, |
|
|
|
|
x: 320, |
|
|
|
@ -347,7 +339,6 @@ onMounted(() => { |
|
|
|
|
// 添加湿度设置控件节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-sd", |
|
|
|
|
id: "4", |
|
|
|
|
width: 110, |
|
|
|
|
height: 84, |
|
|
|
|
x: 120, |
|
|
|
@ -366,7 +357,6 @@ onMounted(() => { |
|
|
|
|
// 添加代码控件2节点 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wenBenYu2", |
|
|
|
|
id:'33', |
|
|
|
|
width: 210, |
|
|
|
|
height: 300, |
|
|
|
|
x: 400, |
|
|
|
@ -385,7 +375,6 @@ onMounted(() => { |
|
|
|
|
// 注册I组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-I", |
|
|
|
|
id: "5", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 50, |
|
|
|
@ -401,7 +390,6 @@ onMounted(() => { |
|
|
|
|
// 注册number10组件1 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-number10", |
|
|
|
|
id: "6", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 150, |
|
|
|
@ -414,7 +402,6 @@ onMounted(() => { |
|
|
|
|
// 注册number10组件2 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-number10", |
|
|
|
|
id: "7", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 150, |
|
|
|
@ -427,7 +414,6 @@ onMounted(() => { |
|
|
|
|
// 注册三角组件1 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-sanjiao", |
|
|
|
|
id: "8", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 230, |
|
|
|
@ -444,7 +430,6 @@ onMounted(() => { |
|
|
|
|
// 注册三角组件2 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-sanjiao", |
|
|
|
|
id: "9", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 230, |
|
|
|
@ -461,7 +446,6 @@ onMounted(() => { |
|
|
|
|
// 湿度数值组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-shiduNumber", |
|
|
|
|
id: "10", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 630, |
|
|
|
@ -475,7 +459,6 @@ onMounted(() => { |
|
|
|
|
// 温度数值组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wenduNumber", |
|
|
|
|
id: "11", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 600, |
|
|
|
@ -488,7 +471,6 @@ onMounted(() => { |
|
|
|
|
// 温度计组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-Wenduji", |
|
|
|
|
id: "12", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 620, |
|
|
|
@ -502,7 +484,6 @@ onMounted(() => { |
|
|
|
|
// 转换器组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-zhuanhuanqi", |
|
|
|
|
id: "13", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 670, |
|
|
|
@ -519,7 +500,6 @@ onMounted(() => { |
|
|
|
|
// 数字2组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-number2", |
|
|
|
|
id: "14", |
|
|
|
|
width: 20, |
|
|
|
|
height: 30, |
|
|
|
|
x: 600, |
|
|
|
@ -532,7 +512,6 @@ onMounted(() => { |
|
|
|
|
// 温度组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wendu", |
|
|
|
|
id: "15", |
|
|
|
|
width: 60, |
|
|
|
|
height: 20, |
|
|
|
|
x: 750, |
|
|
|
@ -545,7 +524,6 @@ onMounted(() => { |
|
|
|
|
// 转换器组件2 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-zhuanhuanqi", |
|
|
|
|
id: "16", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 700, |
|
|
|
@ -562,7 +540,6 @@ onMounted(() => { |
|
|
|
|
// 数字2组件2 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-number2", |
|
|
|
|
id: "17", |
|
|
|
|
width: 20, |
|
|
|
|
height: 30, |
|
|
|
|
x: 650, |
|
|
|
@ -575,7 +552,6 @@ onMounted(() => { |
|
|
|
|
// 温度仪表 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-wenduYibiao", |
|
|
|
|
id: "18", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 759, |
|
|
|
@ -588,7 +564,6 @@ onMounted(() => { |
|
|
|
|
// RH组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-RH", |
|
|
|
|
id: "19", |
|
|
|
|
width: 50, |
|
|
|
|
height: 20, |
|
|
|
|
x: 800, |
|
|
|
@ -601,7 +576,6 @@ onMounted(() => { |
|
|
|
|
// 电池组组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-dianchizu", |
|
|
|
|
id: "20", |
|
|
|
|
width: 40, |
|
|
|
|
height: 70, |
|
|
|
|
x: 880, |
|
|
|
@ -622,7 +596,6 @@ onMounted(() => { |
|
|
|
|
// 湿度组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-shidu", |
|
|
|
|
id: "21", |
|
|
|
|
width: 60, |
|
|
|
|
height: 20, |
|
|
|
|
x: 750, |
|
|
|
@ -635,7 +608,6 @@ onMounted(() => { |
|
|
|
|
// 摄氏度组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-du", |
|
|
|
|
id: "22", |
|
|
|
|
width: 25, |
|
|
|
|
height: 20, |
|
|
|
|
x: 759, |
|
|
|
@ -648,7 +620,6 @@ onMounted(() => { |
|
|
|
|
// 布尔组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-booleanCopm", |
|
|
|
|
id: "23", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1300, |
|
|
|
@ -661,7 +632,6 @@ onMounted(() => { |
|
|
|
|
// 开关组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-swatchComp", |
|
|
|
|
id: "24", |
|
|
|
|
width: 20, |
|
|
|
|
height: 20, |
|
|
|
|
x: 1350, |
|
|
|
@ -674,7 +644,6 @@ onMounted(() => { |
|
|
|
|
// 服务器IP组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-fuwiqiIP", |
|
|
|
|
id: "25", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 950, |
|
|
|
@ -687,7 +656,6 @@ onMounted(() => { |
|
|
|
|
// 服务器端口组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-fuwuqiProt", |
|
|
|
|
id: "26", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 950, |
|
|
|
@ -700,7 +668,6 @@ onMounted(() => { |
|
|
|
|
// 打开TCP组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-openTCP", |
|
|
|
|
id: "27", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1050, |
|
|
|
@ -718,7 +685,6 @@ onMounted(() => { |
|
|
|
|
// 写入TCP数据 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-setTCP", |
|
|
|
|
id: "28", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1150, |
|
|
|
@ -738,7 +704,6 @@ onMounted(() => { |
|
|
|
|
// TCP组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-setzijie", |
|
|
|
|
id: "29", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1300, |
|
|
|
@ -751,7 +716,6 @@ onMounted(() => { |
|
|
|
|
// TCP组件 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-TCP", |
|
|
|
|
id: "30", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1250, |
|
|
|
@ -768,7 +732,6 @@ onMounted(() => { |
|
|
|
|
// 错误输出 |
|
|
|
|
graph.addNode({ |
|
|
|
|
shape: "custom-vue-node-errorComp", |
|
|
|
|
id: "31", |
|
|
|
|
width: 40, |
|
|
|
|
height: 40, |
|
|
|
|
x: 1400, |
|
|
|
@ -793,28 +756,6 @@ onMounted(() => { |
|
|
|
|
graph.canRedo(); |
|
|
|
|
graph.canUndo(); |
|
|
|
|
}); |
|
|
|
|
graph.on("edge:connected", ({ edge }) => { |
|
|
|
|
const data = { |
|
|
|
|
type: "add", |
|
|
|
|
edge: edge.toJSON(), // toJSON 会自动包含正确的 port 数据 |
|
|
|
|
}; |
|
|
|
|
saveToLocalStorage(data); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// 记录删除连线 |
|
|
|
|
graph.on("edge:removed", ({ edge }) => { |
|
|
|
|
const data = { |
|
|
|
|
type: "remove", |
|
|
|
|
id: edge.id, |
|
|
|
|
}; |
|
|
|
|
saveToLocalStorage(data); |
|
|
|
|
}); |
|
|
|
|
setTimeout(() => { |
|
|
|
|
restoreGraph() |
|
|
|
|
}, 1000); |
|
|
|
|
graph.on('edge:added', ({ edge }) => { |
|
|
|
|
console.log('新增连线数据:', edge.toJSON()); |
|
|
|
|
}) |
|
|
|
|
// const nodes = graph.getNodes(); |
|
|
|
|
// console.log(nodes); |
|
|
|
|
// const data = graph.toJSON(); |
|
|
|
@ -831,8 +772,7 @@ const onRedo = () => { |
|
|
|
|
graph.redo(); |
|
|
|
|
}; |
|
|
|
|
const onSave = () => { |
|
|
|
|
if (standardData.length !== formatEdges().length) |
|
|
|
|
return ElMessage.error("请完善数据"); |
|
|
|
|
if(standardData.length !== formatEdges().length) return ElMessage.error("请完善数据"); |
|
|
|
|
validateRelationships(standardData, formatEdges()); |
|
|
|
|
ElMessage.success("保存成功"); |
|
|
|
|
// const data = graph.toJSON(); |
|
|
|
@ -1059,11 +999,9 @@ function validateRelationships(correctAnswers, userRelationships) { |
|
|
|
|
for (const relation of userRelationships) { |
|
|
|
|
const key = `${relation.source}-${relation.target}`; |
|
|
|
|
if (!correctSet.has(key)) { |
|
|
|
|
console.log(graph.getEdges(relation.id)); |
|
|
|
|
graph.getEdges(relation.id)[0].color = "red"; |
|
|
|
|
ElMessage.error( |
|
|
|
|
`错误的关系: source=${relation.source}, target=${relation.target}` |
|
|
|
|
); |
|
|
|
|
console.log( graph.getEdges(relation.id)); |
|
|
|
|
graph.getEdges(relation.id)[0].color = "red"; |
|
|
|
|
ElMessage.error(`错误的关系: source=${relation.source}, target=${relation.target}`); |
|
|
|
|
throw new Error( |
|
|
|
|
`错误的关系: source=${relation.source}, target=${relation.target}` |
|
|
|
|
); |
|
|
|
@ -1072,47 +1010,12 @@ function validateRelationships(correctAnswers, userRelationships) { |
|
|
|
|
|
|
|
|
|
return true; // 关系校验通过 |
|
|
|
|
} |
|
|
|
|
const falg = false; |
|
|
|
|
const falg = (false); |
|
|
|
|
const preview = ref(null); |
|
|
|
|
const onTip = () => { |
|
|
|
|
preview.value.$el.children[0].click(); |
|
|
|
|
preview.value.$el.children[0].click() |
|
|
|
|
console.log(preview.value); |
|
|
|
|
}; |
|
|
|
|
function restoreGraph() { |
|
|
|
|
const operations = loadFromLocalStorage(); |
|
|
|
|
|
|
|
|
|
// 先恢复节点 |
|
|
|
|
operations |
|
|
|
|
.filter(op => op.type === 'add' && op.node) |
|
|
|
|
.forEach(op => graph.addNode(op.node)); |
|
|
|
|
|
|
|
|
|
// 再恢复连线 |
|
|
|
|
operations |
|
|
|
|
.filter(op => op.type === 'add' && op.edge) |
|
|
|
|
.forEach(op => { |
|
|
|
|
const edgeData = op.edge; |
|
|
|
|
|
|
|
|
|
// 若发现 port 数据缺失,补上默认 port ID |
|
|
|
|
if (!edgeData.source.port) edgeData.source.port = "70"; |
|
|
|
|
if (!edgeData.target.port) edgeData.target.port = "70"; |
|
|
|
|
|
|
|
|
|
graph.addEdge(edgeData); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
const SESSION_KEY = 'graph_operations1'; |
|
|
|
|
|
|
|
|
|
function saveToLocalStorage(data) { |
|
|
|
|
const operations = JSON.parse(localStorage.getItem(SESSION_KEY)) || []; |
|
|
|
|
operations.push(data); |
|
|
|
|
localStorage.setItem(SESSION_KEY, JSON.stringify(operations)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function loadFromLocalStorage() { |
|
|
|
|
return JSON.parse(localStorage.getItem(SESSION_KEY)) || []; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function clearLocalStorage() { |
|
|
|
|
localStorage.removeItem(SESSION_KEY); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
@ -1128,5 +1031,7 @@ function clearLocalStorage() { |
|
|
|
|
height: 753px !important; |
|
|
|
|
} |
|
|
|
|
.tip-view { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
</style> |
|
|
|
|