diff --git a/client/src/sections/wuyuanbiaoba/components/CameraView.jsx b/client/src/sections/wuyuanbiaoba/components/CameraView.jsx index d85589a..e0c653f 100644 --- a/client/src/sections/wuyuanbiaoba/components/CameraView.jsx +++ b/client/src/sections/wuyuanbiaoba/components/CameraView.jsx @@ -282,11 +282,15 @@ const CameraView = ({ const videoRect = screenToVideoCoordinates(x, y, w, h); if (videoRect && rectangles.length < maxRectangles) { + // 只取时间戳后4位作为id和key + const ts = Date.now().toString(); + const shortId = ts.slice(-4); // 根据选中的模板预设参数 const templateParams = selectedTemplate ? { // 从模板中获取参数 - name: `target${rectangles.length + 1}` || selectedTemplate.name, + name: + `target${rectangles.length + 1}` || selectedTemplate.name, radius: selectedTemplate.physicalRadius || 40.0, isReferencePoint: selectedTemplate.isBaseline || false, gradientThreshold: @@ -309,8 +313,8 @@ const CameraView = ({ }; const newRect = { - id: Date.now(), // 使用时间戳作为唯一ID - key: Date.now().toString(), + id: shortId, + key: shortId, ...videoRect, ...templateParams, // 保存矩形区域信息用于服务端 @@ -735,8 +739,13 @@ const CameraView = ({ const targets = {}; // console.log(rectangles, "当前矩形数据"); - rectangles.forEach((rect, index) => { - targets[index.toString()] = { + rectangles.forEach((rect) => { + // 使用标靶的原始ID,而不是数组索引 + const targetKey = rect.id + ? rect.id.toString() + : Date.now().toString(); + + targets[targetKey] = { info: { rectangle_area: { x: rect.x, @@ -751,8 +760,8 @@ const CameraView = ({ anchor: rect.anchorThreshold || 80, }, radius: rect.radius || 40.0, - id: index, - desc: rect.name || `${index}_target`, + id: rect.id || targetKey, // 使用原始ID + desc: rect.name || `target_${targetKey}`, base: rect.isReferencePoint || false, }, perspective: [ @@ -1167,35 +1176,43 @@ const CameraView = ({ {/* 保存按钮 */} {/* 信息显示 */} diff --git a/client/src/sections/wuyuanbiaoba/components/RealtimeCharts.jsx b/client/src/sections/wuyuanbiaoba/components/RealtimeCharts.jsx index 9215667..b1a5b16 100644 --- a/client/src/sections/wuyuanbiaoba/components/RealtimeCharts.jsx +++ b/client/src/sections/wuyuanbiaoba/components/RealtimeCharts.jsx @@ -38,7 +38,7 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { } // 固定的设备颜色映射,确保颜色一致性 - const getDeviceColor = (deviceId) => { + const getDeviceColor = (deviceDesc) => { const colorMap = { target1: "#52c41a", // 绿色 target2: "#faad14", // 橙色 @@ -52,7 +52,7 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { target10: "#1890ff", // 蓝色 }; - return colorMap[deviceId] || "#1890ff"; + return colorMap[deviceDesc] || "#1890ff"; }; // 数据采样函数 - 每秒采样一次,最多保留25个数据点 @@ -118,6 +118,18 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { // 初始化可见目标状态 const { deviceIds } = sampleData(tableData); + + // 获取 deviceId 到 desc 的映射 + const deviceDescMap = useMemo(() => { + const map = {}; + tableData.forEach(item => { + if (item.deviceId && item.desc) { + map[item.deviceId] = item.desc; + } + }); + return map; + }, [tableData]); + useEffect(() => { if (deviceIds.length > 0) { const initialVisible = {}; @@ -203,11 +215,12 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { : null; }); + const deviceDesc = deviceDescMap[deviceId] || deviceId; return { label: deviceId, data: data, - borderColor: getDeviceColor(deviceId), - backgroundColor: getDeviceColor(deviceId) + "20", + borderColor: getDeviceColor(deviceDesc), + backgroundColor: getDeviceColor(deviceDesc) + "20", borderWidth: 2, pointRadius: 3, pointHoverRadius: 5, @@ -245,11 +258,12 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { : null; }); + const deviceDesc = deviceDescMap[deviceId] || deviceId; return { label: deviceId, data: data, - borderColor: getDeviceColor(deviceId), - backgroundColor: getDeviceColor(deviceId) + "20", + borderColor: getDeviceColor(deviceDesc), + backgroundColor: getDeviceColor(deviceDesc) + "20", borderWidth: 2, pointRadius: 3, pointHoverRadius: 5, @@ -266,8 +280,8 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { } }, [tableData, visibleTargets]); - // Chart.js配置选项 - const chartOptions = { + // Chart.js配置选项 - 移到组件内部以访问 deviceDescMap + const chartOptions = useMemo(() => ({ responsive: true, maintainAspectRatio: false, interaction: { @@ -282,6 +296,17 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { filter: function (tooltipItem) { return tooltipItem.parsed.y !== null; }, + callbacks: { + title: function(context) { + return context[0].label; // 显示时间 + }, + label: function(context) { + const deviceId = context.dataset.label; + const deviceDesc = deviceDescMap[deviceId] || deviceId; + const value = context.parsed.y; + return `${deviceDesc}: ${value}`; + } + } }, }, scales: { @@ -323,10 +348,10 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { tension: 0, }, }, - }; + }), [deviceDescMap]); // X轴图表配置 - const xChartOptions = { + const xChartOptions = useMemo(() => ({ ...chartOptions, plugins: { ...chartOptions.plugins, @@ -348,10 +373,10 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { }, }, }, - }; + }), [chartOptions]); // Y轴图表配置 - const yChartOptions = { + const yChartOptions = useMemo(() => ({ ...chartOptions, plugins: { ...chartOptions.plugins, @@ -373,7 +398,7 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { }, }, }, - }; + }), [chartOptions]); // 如果没有数据,显示空状态 if (!tableData || tableData.length === 0) { @@ -451,19 +476,19 @@ const RealtimeCharts = ({ tableData, lastUpdateTime }) => { > 全部隐藏 - {deviceIds.map(deviceId => ( + {deviceIds.map((deviceId,index) => ( ))} diff --git a/client/src/sections/wuyuanbiaoba/components/RealtimeDataTable.jsx b/client/src/sections/wuyuanbiaoba/components/RealtimeDataTable.jsx index 2881194..b4a6771 100644 --- a/client/src/sections/wuyuanbiaoba/components/RealtimeDataTable.jsx +++ b/client/src/sections/wuyuanbiaoba/components/RealtimeDataTable.jsx @@ -5,7 +5,12 @@ const { Title } = Typography; const RealtimeDataTable = ({ realtimeData }) => { const tableColumns = [ - { title: "设备编号", dataIndex: "deviceId", key: "deviceId" }, + { + title: "设备编号", + dataIndex: "deviceId", + key: "deviceId", + render: (deviceId, record) => record.desc || deviceId + }, { title: "X值(mm)", dataIndex: "xValue", diff --git a/client/src/sections/wuyuanbiaoba/container/index.jsx b/client/src/sections/wuyuanbiaoba/container/index.jsx index ba3de9c..4d22d9a 100644 --- a/client/src/sections/wuyuanbiaoba/container/index.jsx +++ b/client/src/sections/wuyuanbiaoba/container/index.jsx @@ -74,7 +74,8 @@ const WuyuanbiaobaContent = () => { return data.data.map((item) => ({ key: item.pos, - deviceId: `target${Number(item.pos) + 1}`, + deviceId: item.pos, // 使用 pos 作为 deviceId + desc: item.desc, // 添加 desc 字段 xValue: item.x, yValue: item.y, updateTime: data.time || new Date().toLocaleString(), @@ -372,18 +373,6 @@ const WuyuanbiaobaContent = () => {