Browse Source

feat: 添加 DeflectionCollection 和 ImageCollection 组件; 更新相关样式和依赖

master
cles 2 weeks ago
parent
commit
96143e1852
  1. 32
      package-lock.json
  2. 4
      package.json
  3. 6
      src/renderer/src/App.jsx
  4. 311
      src/renderer/src/components/DeflectionCollection/DeflectionCollection.jsx
  5. 3
      src/renderer/src/components/DeflectionCollection/DeflectionCollection.module.css
  6. 7
      src/renderer/src/components/ImageCollection/ImageCollection.jsx
  7. 0
      src/renderer/src/components/ImageCollection/ImageCollection.module.css
  8. 2
      src/renderer/src/components/MeasurementPointSetting/MeasurementPointSetting.module.css
  9. 1
      src/renderer/src/components/SystemSettings/SystemSettings.module.css

32
package-lock.json

@ -13,7 +13,9 @@
"@electron-toolkit/preload": "^3.0.2",
"@electron-toolkit/utils": "^4.0.0",
"antd": "^5.27.1",
"electron-updater": "^6.3.9"
"chart.js": "^4.5.0",
"electron-updater": "^6.3.9",
"react-chartjs-2": "^5.3.0"
},
"devDependencies": {
"@electron-toolkit/eslint-config": "^2.0.0",
@ -1729,6 +1731,12 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@kurkle/color": {
"version": "0.3.4",
"resolved": "https://registry.npmmirror.com/@kurkle/color/-/color-0.3.4.tgz",
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
"license": "MIT"
},
"node_modules/@malept/cross-spawn-promise": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz",
@ -3614,6 +3622,18 @@
"url": "https://github.com/chalk/chalk?sponsor=1"
}
},
"node_modules/chart.js": {
"version": "4.5.0",
"resolved": "https://registry.npmmirror.com/chart.js/-/chart.js-4.5.0.tgz",
"integrity": "sha512-aYeC/jDgSEx8SHWZvANYMioYMZ2KX02W6f6uVfyteuCGcadDLcYVHdfdygsTQkQ4TKn5lghoojAsPj5pu0SnvQ==",
"license": "MIT",
"dependencies": {
"@kurkle/color": "^0.3.0"
},
"engines": {
"pnpm": ">=8"
}
},
"node_modules/chownr": {
"version": "2.0.0",
"resolved": "https://registry.npmmirror.com/chownr/-/chownr-2.0.0.tgz",
@ -8746,6 +8766,16 @@
"node": ">=0.10.0"
}
},
"node_modules/react-chartjs-2": {
"version": "5.3.0",
"resolved": "https://registry.npmmirror.com/react-chartjs-2/-/react-chartjs-2-5.3.0.tgz",
"integrity": "sha512-UfZZFnDsERI3c3CZGxzvNJd02SHjaSJ8kgW1djn65H1KK8rehwTjyrRKOG3VTMG8wtHZ5rgAO5oTHtHi9GCCmw==",
"license": "MIT",
"peerDependencies": {
"chart.js": "^4.1.1",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
}
},
"node_modules/react-dom": {
"version": "19.1.1",
"resolved": "https://registry.npmmirror.com/react-dom/-/react-dom-19.1.1.tgz",

4
package.json

@ -22,7 +22,9 @@
"@electron-toolkit/preload": "^3.0.2",
"@electron-toolkit/utils": "^4.0.0",
"antd": "^5.27.1",
"electron-updater": "^6.3.9"
"chart.js": "^4.5.0",
"electron-updater": "^6.3.9",
"react-chartjs-2": "^5.3.0"
},
"devDependencies": {
"@electron-toolkit/eslint-config": "^2.0.0",

6
src/renderer/src/App.jsx

@ -4,17 +4,19 @@ const { Sider, Content } = Layout
import SiderHeader from './components/SiderHeader/SiderHeader'
import { FundFilled, CameraFilled } from '@ant-design/icons'
import { Tabs } from 'antd'
import DeflectionCollection from './components/DeflectionCollection/DeflectionCollection'
import ImageCollection from './components/ImageCollection/ImageCollection'
const tabItem = [
{
key: '1',
label: `挠度数据采集`,
children: `挠度数据采集`,
children: <DeflectionCollection />,
icon: <FundFilled />
},
{
key: '2',
label: `图像数据采集`,
children: `图像数据采集`,
children: <ImageCollection />,
icon: <CameraFilled />
}
]

311
src/renderer/src/components/DeflectionCollection/DeflectionCollection.jsx

@ -0,0 +1,311 @@
import { Line } from 'react-chartjs-2'
import {
Chart as ChartJS,
CategoryScale,
LinearScale,
PointElement,
LineElement,
Title,
Tooltip,
Legend
} from 'chart.js'
import { FileTextOutlined, ClockCircleOutlined, EyeOutlined } from '@ant-design/icons'
ChartJS.register(CategoryScale, LinearScale, PointElement, LineElement, Title, Tooltip, Legend)
function randomAround(base, delta) {
return base + Math.round((Math.random() * 2 - 1) * delta)
}
function getTimeLabels(count) {
const now = new Date()
return Array.from({ length: count }).map((_, i) => {
const d = new Date(now.getTime() - (count - 1 - i) * 2 * 1000)
return d.toTimeString().slice(0, 8)
})
}
function DeflectionCollection() {
const count = 10
const targetCount = 5 // target
// target
const targetColors = [
'rgba(75,192,192,1)', //
'rgba(255,99,132,1)', //
'rgba(54,162,235,1)', //
'rgba(255,206,86,1)', //
'rgba(153,102,255,1)' //
]
// target
const targetsData = Array.from({ length: targetCount }).map((_, targetIndex) => ({
name: `Target ${targetIndex + 1}`,
color: targetColors[targetIndex % targetColors.length],
data: Array.from({ length: count }).map((_, i) => ({
x: 350 + targetIndex * 50 + Math.sin(i * 0.5 + targetIndex) * 20 + randomAround(0, 3),
y: 50 + targetIndex * 20 + Math.cos(i * 0.3 + targetIndex) * 15 + randomAround(0, 2),
w: randomAround(125, 5),
h: randomAround(115, 5)
}))
}))
const timeLabels = getTimeLabels(count)
const dataY = {
labels: timeLabels,
datasets: targetsData.map((target) => ({
label: `${target.name}`,
data: target.data.map((d) => d.y),
borderColor: target.color,
backgroundColor: target.color.replace('1)', '0.2)'),
tension: 0.3,
pointRadius: 3,
pointHoverRadius: 5
}))
}
const dataX = {
labels: timeLabels,
datasets: targetsData.map((target) => ({
label: `${target.name}`,
data: target.data.map((d) => d.x),
borderColor: target.color,
backgroundColor: target.color.replace('1)', '0.2)'),
tension: 0.3,
pointRadius: 3,
pointHoverRadius: 5
}))
}
const options = {
responsive: true,
maintainAspectRatio: false,
plugins: {
legend: {
display: true,
labels: {
boxWidth: 8,
boxHeight: 8,
font: {
size: 10
},
padding: 5
},
position: 'top'
},
title: { display: false }
},
scales: {
x: {
title: { display: true, text: '时间' },
ticks: { font: { size: 10 } }
},
y: {
title: { display: true, text: '挠度值' },
ticks: { font: { size: 10 } }
}
}
}
return (
<div
style={{
height: 'calc(100vh - 100px)',
maxHeight: '100%',
display: 'flex',
overflow: 'hidden',
margin: '0',
boxSizing: 'border-box'
}}
>
<div
style={{
flex: 1,
minWidth: 0,
display: 'flex',
flexDirection: 'column',
padding: '10px',
gap: '10px',
overflow: 'hidden'
}}
>
<div
style={{
flex: 1,
minHeight: 0,
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
border: '1px solid var(--border-color)'
}}
>
<p style={{ margin: '0 0 5px 0', fontSize: '14px', fontWeight: '500' }}>Y方向曲线</p>
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
<Line data={dataY} options={options} />
</div>
</div>
<div
style={{
flex: 1,
minHeight: 0,
display: 'flex',
flexDirection: 'column',
overflow: 'hidden',
border: '1px solid var(--border-color)'
}}
>
<p style={{ margin: '0 0 5px 0', fontSize: '14px', fontWeight: '500' }}>X方向曲线</p>
<div style={{ flex: 1, minHeight: 0, position: 'relative' }}>
<Line data={dataX} options={options} />
</div>
</div>
</div>
<div
style={{
width: '300px',
minWidth: '300px',
maxWidth: '300px',
margin: '10px',
padding: '10px',
border: '1px solid var(--border-color)',
overflow: 'auto',
boxSizing: 'border-box'
}}
>
<div
style={{
fontSize: '14px',
fontWeight: '600',
marginBottom: '10px',
color: '#333'
}}
>
实时数据
</div>
{targetsData.map((target, index) => {
const latestData = target.data[target.data.length - 1]
const latestTime = timeLabels[timeLabels.length - 1]
return (
<div
key={index}
style={{
marginBottom: '15px',
padding: '10px',
backgroundColor: '#fafafa',
border: '1px solid #e8e8e8',
borderRadius: '4px'
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
marginBottom: '8px'
}}
>
<div
style={{
width: '8px',
height: '8px',
backgroundColor: target.color,
borderRadius: '50%',
marginRight: '8px'
}}
></div>
<span
style={{
fontSize: '14px',
fontWeight: '500',
color: '#333'
}}
>
测点位置{index + 1}
</span>
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
marginBottom: '5px'
}}
>
<FileTextOutlined style={{ fontSize: '12px', color: '#666' }} />
<span
style={{
fontSize: '12px',
color: '#666',
marginLeft: '5px'
}}
>
测点描述
</span>
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
marginBottom: '5px'
}}
>
<ClockCircleOutlined style={{ fontSize: '12px', color: '#666' }} />
<span
style={{
fontSize: '12px',
color: '#666',
marginLeft: '5px'
}}
>
采集时间{new Date().toLocaleDateString()} {latestTime}
</span>
</div>
<div
style={{
display: 'flex',
alignItems: 'center',
marginBottom: '3px'
}}
>
<EyeOutlined style={{ fontSize: '12px', color: '#666' }} />
<span
style={{
fontSize: '12px',
color: '#333',
marginLeft: '5px'
}}
>
X {latestData.x.toFixed(3)}
</span>
</div>
<div
style={{
display: 'flex',
alignItems: 'center'
}}
>
<EyeOutlined style={{ fontSize: '12px', color: '#666' }} />
<span
style={{
fontSize: '12px',
color: '#333',
marginLeft: '5px'
}}
>
Y {latestData.y.toFixed(3)}
</span>
</div>
</div>
)
})}
</div>
</div>
)
}
export default DeflectionCollection

3
src/renderer/src/components/DeflectionCollection/DeflectionCollection.module.css

@ -0,0 +1,3 @@
.chartContainer {
width: 100%;
}

7
src/renderer/src/components/ImageCollection/ImageCollection.jsx

@ -0,0 +1,7 @@
import React from 'react'
function ImageCollection() {
return <div>ImageCollection</div>
}
export default ImageCollection

0
src/renderer/src/components/ImageCollection/ImageCollection.module.css

2
src/renderer/src/components/MeasurementPointSetting/MeasurementPointSetting.module.css

@ -24,7 +24,6 @@
display: flex;
flex-direction: column;
gap: 4px;
background: #f9f9f9;
}
.sectionTitle {
@ -62,7 +61,6 @@
border-radius: 4px;
margin: 4px 0;
padding: 8px;
background: #f9f9f9;
flex: 1;
display: flex;
flex-direction: column;

1
src/renderer/src/components/SystemSettings/SystemSettings.module.css

@ -24,6 +24,7 @@
border-radius: 6px;
margin: 4px;
padding: 4px;
background-color: #f9f9f9;
}
.sectionTitle {

Loading…
Cancel
Save