1.被检设备监测点新增是否参与检测

2.调整通道配对只显示绑定和参与检测的通道数
This commit is contained in:
sjl
2025-09-17 14:08:58 +08:00
parent 95c68942ed
commit c88128b63b
8 changed files with 174 additions and 54 deletions

View File

@@ -39,7 +39,7 @@
</template>
<script lang="ts" setup>
import { h, ref, onMounted } from 'vue'
import { h, ref, onMounted, PropType } from 'vue'
import { VueFlow, useVueFlow } from '@vue-flow/core'
import { dialogBig } from '@/utils/elementBind'
import { Platform, Flag } from '@element-plus/icons-vue'
@@ -68,6 +68,10 @@ const prop = defineProps({
planIdKey: {
type: String,
default: ''
},
deviceMonitor: {
type: Map as PropType<Map<string, any[]>>,
default: () => new Map()
}
})
// 计算对话框高度
@@ -222,7 +226,7 @@ const open = async () => {
devIds.value = prop.devIdList.map(d => d.id)
standardDevIds.value = prop.pqStandardDevList.map(d => d.id)
planId.value = prop.planIdKey
nodes.value = createNodes(prop.devIdList, prop.pqStandardDevList)
nodes.value = createNodes(prop.devIdList, prop.pqStandardDevList,prop.deviceMonitor)
dialogVisible.value = true
onPaneReady()
}
@@ -258,6 +262,8 @@ const handleNext = async () => {
{} as Record<string, string>
)
await generateChannelMapping()
console.log('通道映射:', channelMapping.value)
return
await checkStore.setChnNum(chnNumList)
return {
title: dialogTitle.value,
@@ -346,12 +352,12 @@ const generateChannelMapping = () => {
channelMapping.value = mapping
}
const createNodes = (device: Device.ResPqDev[], standardDev: StandardDevice.ResPqStandardDevice[]) => {
const createNodes = (device: Device.ResPqDev[], standardDev: StandardDevice.ResPqStandardDevice[], deviceMonitor: Map<string, any[]>) => {
const channelCounts: Record<string, number> = {}
device.forEach(device => {
channelCounts[device.id] = device.devChns || 0
})
const inspectionDevices = device.map(d => ({
id: d.id,
name: d.name,
@@ -381,83 +387,140 @@ const createNodes = (device: Device.ResPqDev[], standardDev: StandardDevice.ResP
const outputChannelX = 1050
const standardWidth = 1170
const yPosition = (vueFlowElement.value - Object.keys(channelCounts).length * 50) / 2
const yPosition2 = (vueFlowElement.value - Object.keys(channelCounts2).length * 50) / 2
// const yPosition = ref(75)
// const yPosition2 = ref(75)
// 添加被检通道
let currentYPosition = 50; // 初始Y位置
const deviceSpacing = 30; // 设备间的垂直间距
Object.entries(channelCounts).forEach(([deviceId, count]) => {
const yPosition = (vueFlowElement.value - count * 52) / 2
for (let i = 1; i <= count; i++) {
const channelId = `被检通道-${deviceId}-${i}`
// 从deviceMonitor中获取实际通道信息
let actualChannels = []; // 存储实际的通道号
// 如果deviceMonitor中有该设备的数据则使用实际监测点信息
if (deviceMonitor.has(deviceId)) {
const monitorPoints = deviceMonitor.get(deviceId) || [];
// 提取监测点的num值作为通道号
actualChannels = monitorPoints.map(point => point.num);
//console.log('deviceId', deviceId, '实际通道号:', actualChannels, '监测点:', monitorPoints);
} else {
// 如果没有monitor数据默认使用连续的通道号
actualChannels = Array.from({length: count}, (_, i) => i + 1);
}
const yPosition = currentYPosition;
// 遍历实际通道号而不是连续的数字
actualChannels.forEach((channelNum, index) => {
const channelId = `被检通道-${deviceId}-${channelNum}`;
newNodes.push({
id: channelId,
type: 'input',
data: { label: createLabel3(`被检通道${i}`) },
position: { x: inputChannelX, y: yPosition + (i - 1) * 50 },
// position: { x: inputChannelX, y: yPosition.value },
data: { label: createLabel3(`被检通道${channelNum}`) },
position: { x: inputChannelX, y: yPosition + index * 50 },
sourcePosition: 'right',
style: { width: '120px', border: 'none', boxShadow: 'none' }
})
});
deviceChannelGroups.push({
deviceId,
centerY: 0
})
}
})
centerY: 0
});
});
// 更新currentYPosition为下一台设备留出空间
// 每台设备需要的空间 = 实际通道数 * 50 + 设备间距
currentYPosition += actualChannels.length * 50 + deviceSpacing;
});
// 添加标准通道
let currentYPosition2 = 50; // 初始Y位置
const standardDeviceSpacing = 30; // 标准设备间的垂直间距
Object.entries(channelCounts2).forEach(([deviceId, count]) => {
const yPosition2 = (vueFlowElement.value - count * 52) / 2
const yPosition2 = currentYPosition2;
for (let i = 1; i <= count; i++) {
const channelId = `标准通道-${deviceId}-${i}`
const channelId = `标准通道-${deviceId}-${i}`;
newNodes.push({
id: channelId,
type: 'output',
data: { label: createLabel3(`标准通道${i}`) },
// position: { x: outputChannelX, y: yPosition2.value },
position: { x: outputChannelX, y: yPosition2 + (i - 1) * 50 },
targetPosition: 'left',
style: { width: '120px', border: 'none', boxShadow: 'none' }
})
});
standardChannelGroups.push({
deviceId,
centerY: 0 //yPosition2.value - 25
})
centerY: 0
});
}
})
// 更新currentYPosition2为下一台标准设备留出空间
currentYPosition2 += count * 50 + standardDeviceSpacing;
});
// 添加被检设备
let deviceCurrentYPosition = 50; // 与通道计算保持一致的初始位置
let lastDeviceId = ''; // 记录上一个处理的设备ID
// 添加被检设备
deviceChannelGroups.forEach(({ deviceId, centerY }) => {
const device = inspectionDevices.find(d => d.id === deviceId)
if (device) {
newNodes.push({
id: device.id,
data: { label: createLabel(device.name, device.deviceType, 1) },
// position: { x: deviceWidth, y: centerY },
position: { x: deviceWidth, y: (vueFlowElement.value - 112) / 2 },
class: 'no-handle-node',
style: { width: '300px', border: 'none', boxShadow: 'none' }
})
// 只有当设备ID变化时才计算新位置
if (lastDeviceId !== deviceId) {
// 计算该设备对应的实际通道数量
let actualChannelCount = channelCounts[deviceId] || 0;
// 如果deviceMonitor中有该设备的数据则使用实际监测点数量
if (deviceMonitor.has(deviceId)) {
const monitorPoints = deviceMonitor.get(deviceId) || [];
actualChannelCount = monitorPoints.length;
}
// 计算设备高度居中位置 - 基于该设备组的实际位置
const deviceCenterY = deviceCurrentYPosition + (actualChannelCount * 50) / 2 - 50
console.log('deviceCenterY', deviceId, deviceCenterY)
newNodes.push({
id: device.id,
data: { label: createLabel(device.name, device.deviceType, 1) },
position: { x: deviceWidth, y: deviceCenterY },
class: 'no-handle-node',
style: { width: '300px', border: 'none', boxShadow: 'none' }
})
// 更新位置为下一台设备的起始位置
deviceCurrentYPosition += actualChannelCount * 50 + 30
// 更新上一个设备ID
lastDeviceId = deviceId
}
}
})
// 添加标准设备
let standardDeviceCurrentYPosition = 50; // 与标准通道计算保持一致的初始位置
let lastStandardDeviceId = ''; // 记录上一个处理的标准设备ID
standardChannelGroups.forEach(({ deviceId, centerY }) => {
const device = standardDevices.find(d => d.id === deviceId)
if (device) {
newNodes.push({
id: device.id,
data: { label: createLabel(device.name, device.deviceType, 2) },
position: { x: standardWidth, y: (vueFlowElement.value - 112) / 2 },
// position: { x: standardWidth, y: centerY + 25 },
class: 'no-handle-node',
style: { width: '300px', border: 'none', boxShadow: 'none' }
})
// 只有当设备ID变化时才计算新位置
if (lastStandardDeviceId !== deviceId) {
// 计算该标准设备对应的通道数量
const channelCount = channelCounts2[deviceId] || 0
// 计算设备高度居中位置 - 基于该设备组的实际位置
const deviceCenterY = standardDeviceCurrentYPosition + (channelCount * 50) / 2 - 50
newNodes.push({
id: device.id,
data: { label: createLabel(device.name, device.deviceType, 2) },
position: { x: standardWidth, y: deviceCenterY },
class: 'no-handle-node',
style: { width: '300px', border: 'none', boxShadow: 'none' }
})
// 更新位置为下一台标准设备的起始位置
standardDeviceCurrentYPosition += channelCount * 50 + 30
// 更新上一个标准设备ID
lastStandardDeviceId = deviceId
}
}
})