修改b,c类设备的采集

This commit is contained in:
Mac mini git server 2026-04-18 13:56:26 +08:00
parent b583feb2a4
commit bc93fb4d61
17 changed files with 1398 additions and 135 deletions

24
.env.example Normal file
View File

@ -0,0 +1,24 @@
# MQTT over WebSocket
VITE_MQTT_WS_URL=ws://127.0.0.1:9001/mqtt
# ---------- topic 形如 topic/device/rbiot-xxx/data ----------
# 代码默认:仅写短 id(且不设 PREFIX)时,会自动订 topic/device/{id}/data,与 MQTTX 发布一致。
# VITE_MQTT_TOPICS=rbiot-b01-001,rbiot-c01-001
# 方式 A:直接写完整 topic
# VITE_MQTT_TOPICS=topic/device/rbiot-b01-001/data,topic/device/rbiot-c01-001/data
# 方式 B:自定义模板(覆盖默认)
# VITE_MQTT_TOPIC_TEMPLATE=topic/device/{id}/data
# 方式 C:仅前缀 + 短名(会禁用「默认模板」,需同时设 PREFIX)
# VITE_MQTT_TOPIC_PREFIX=topic/device
# VITE_MQTT_TOPICS=rbiot-b01-001/data,rbiot-c01-001/data
# 额外订阅通配(可选,与上面设备列表配合;消息仍需能匹配到已配置设备)
# VITE_MQTT_EXTRA_SUBSCRIBE=topic/device/+/data
VITE_MQTT_OFFLINE_MS=30000
# VITE_MQTT_DEBUG=true
# VITE_MQTT_USERNAME=
# VITE_MQTT_PASSWORD=

View File

@ -8,7 +8,7 @@
## 001
![alt text](images/image001.png)
alt text
```json
{
@ -293,13 +293,9 @@
}
```
## 002
![alt text](images/image002.jpg)
alt text
```json
{
@ -584,10 +580,9 @@
}
```
## 003
![alt text](images/image003.jpg)
alt text
```json
{
@ -872,10 +867,9 @@
}
```
## 004
![alt text](images/image004.jpg)
alt text
```json
{
@ -1160,10 +1154,9 @@
}
```
## 005
![alt text](images/image005.jpg)
alt text
```json
{
@ -1453,10 +1446,9 @@
}
```
## 006
![alt text](images/image006.jpg)
alt text
```json
{
@ -1741,10 +1733,9 @@
}
```
## 007
![alt text](images/image007.jpg)
alt text
```json
{
@ -2034,10 +2025,9 @@
}
```
## 008
![alt text](images/image008.jpg)
alt text
```json
{
@ -2327,12 +2317,11 @@
}
```
## 009
![alt text](images/image009.jpg)
alt text
![alt text](images/image009-panel.jpg)
alt text
设备连接不上。面板显示 MAC地址 为空。采集设备的网口灯没有亮。
@ -2340,12 +2329,11 @@
```
## 010
![alt text](images/image010.jpg)
alt text
![alt text](images/image010-panel.jpg)
alt text
设备连接不上。面板显示 MAC地址 为空。采集设备的网口灯没有亮。
@ -2353,12 +2341,11 @@
```
## 011
![alt text](images/image011.jpg)
alt text
![alt text](images/image011-USB-port.jpg)
alt text
只找到USB口,没有找到网口。

View File

@ -2,4 +2,4 @@
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).
Learn more about IDE Support for Vue in the [Vue Docs Scaling up Guide](https://vuejs.org/guide/scaling-up/tooling.html#ide-support).

BIN
dist.zip Normal file

Binary file not shown.

View File

@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=1920, initial-scale=1.0" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>工厂设备智能监控平台</title>
<meta name="description" content="工厂设备实时监控大屏,展示激光切割、CNC加工中心、电力监测设备状态" />
<style>

549
package-lock.json generated
View File

@ -11,6 +11,7 @@
"@kjgl77/datav-vue3": "^1.7.4",
"axios": "^1.13.6",
"echarts": "^6.0.0",
"mqtt": "^5.15.1",
"vue": "^3.5.25",
"vue-echarts": "^8.0.1",
"vue-router": "^4.5.0"
@ -54,9 +55,9 @@
}
},
"node_modules/@babel/runtime": {
"version": "7.28.6",
"resolved": "https://registry.npmmirror.com/@babel/runtime/-/runtime-7.28.6.tgz",
"integrity": "sha512-05WQkdpL9COIMz4LjTxGpPNCdlpyimKppYNoJ5Di5EUObifl8t4tuLuUBBZEpoLYOmfvIWrsp9fCl0HoPRVTdA==",
"version": "7.29.2",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.29.2.tgz",
"integrity": "sha512-JiDShH45zKHWyGe4ZNVRrCjBz8Nh9TMmZG1kh4QTK8hCBTWBi8Da+i7s1fJw7/lYpM4ccepSNfqzZ/QvABBi5g==",
"license": "MIT",
"engines": {
"node": ">=6.9.0"
@ -945,12 +946,39 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/node": {
"version": "25.6.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.6.0.tgz",
"integrity": "sha512-+qIYRKdNYJwY3vRCZMdJbPLJAtGjQBudzZzdzwQYkEPQd+PJGixUL5QfvCLDaULoLv+RhT3LDkwEfKaAkgSmNQ==",
"license": "MIT",
"dependencies": {
"undici-types": "~7.19.0"
}
},
"node_modules/@types/readable-stream": {
"version": "4.0.23",
"resolved": "https://registry.npmjs.org/@types/readable-stream/-/readable-stream-4.0.23.tgz",
"integrity": "sha512-wwXrtQvbMHxCbBgjHaMGEmImFTQxxpfMOR/ZoQnXxB1woqkUbdLGFDgauo00Py9IudiaqSeiBiulSV9i6XIPig==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/web-bluetooth": {
"version": "0.0.20",
"resolved": "https://registry.npmmirror.com/@types/web-bluetooth/-/web-bluetooth-0.0.20.tgz",
"integrity": "sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==",
"license": "MIT"
},
"node_modules/@types/ws": {
"version": "8.18.1",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-ThVF6DCVhA8kUGy+aazFQ4kXQ7E1Ty7A3ypFOe0IcJV8O/M511G99AW24irKrW56Wt44yG9+ij8FaqoBGkuBXg==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@vitejs/plugin-vue": {
"version": "6.0.4",
"resolved": "https://registry.npmmirror.com/@vitejs/plugin-vue/-/plugin-vue-6.0.4.tgz",
@ -1162,6 +1190,18 @@
}
}
},
"node_modules/abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"license": "MIT",
"dependencies": {
"event-target-shim": "^5.0.0"
},
"engines": {
"node": ">=6.5"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmmirror.com/asynckit/-/asynckit-0.4.0.tgz",
@ -1179,6 +1219,86 @@
"proxy-from-env": "^1.1.0"
}
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/bl": {
"version": "6.1.6",
"resolved": "https://registry.npmjs.org/bl/-/bl-6.1.6.tgz",
"integrity": "sha512-jLsPgN/YSvPUg9UX0Kd73CXpm2Psg9FxMeCSXnk3WBO3CMT10JMwijubhGfHCnFu6TPn1ei3b975dxv7K2pWVg==",
"license": "MIT",
"dependencies": {
"@types/readable-stream": "^4.0.0",
"buffer": "^6.0.3",
"inherits": "^2.0.4",
"readable-stream": "^4.2.0"
}
},
"node_modules/broker-factory": {
"version": "3.1.14",
"resolved": "https://registry.npmjs.org/broker-factory/-/broker-factory-3.1.14.tgz",
"integrity": "sha512-L45k5HMbPIrMid0nTOZ/UPXG/c0aRuQKVrSDFIb1zOkvfiyHgYmIjc3cSiN1KwQIvRDOtKE0tfb3I9EZ3CmpQQ==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"fast-unique-numbers": "^9.0.27",
"tslib": "^2.8.1",
"worker-factory": "^7.0.49"
}
},
"node_modules/broker-factory/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/buffer": {
"version": "6.0.3",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT",
"dependencies": {
"base64-js": "^1.3.1",
"ieee754": "^1.2.1"
}
},
"node_modules/buffer-from": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"license": "MIT"
},
"node_modules/call-bind-apply-helpers": {
"version": "1.0.2",
"resolved": "https://registry.npmmirror.com/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz",
@ -1204,12 +1324,64 @@
"node": ">= 0.8"
}
},
"node_modules/commist": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/commist/-/commist-3.2.0.tgz",
"integrity": "sha512-4PIMoPniho+LqXmpS5d3NuGYncG6XWlkBSVGiWycL22dd42OYdUGil2CWuzklaJoNxyxUSpO4MKIBU94viWNAw==",
"license": "MIT"
},
"node_modules/concat-stream": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-2.0.0.tgz",
"integrity": "sha512-MWufYdFw53ccGjCA+Ol7XJYpAlW6/prSMzuPOTRnJGcGzuhLn4Scrz7qf6o8bROZ514ltazcIFJZevcfbo0x7A==",
"engines": [
"node >= 6.0"
],
"license": "MIT",
"dependencies": {
"buffer-from": "^1.0.0",
"inherits": "^2.0.3",
"readable-stream": "^3.0.2",
"typedarray": "^0.0.6"
}
},
"node_modules/concat-stream/node_modules/readable-stream": {
"version": "3.6.2",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz",
"integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==",
"license": "MIT",
"dependencies": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/csstype": {
"version": "3.2.3",
"resolved": "https://registry.npmmirror.com/csstype/-/csstype-3.2.3.tgz",
"integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==",
"license": "MIT"
},
"node_modules/debug": {
"version": "4.4.3",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
"integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
"license": "MIT",
"dependencies": {
"ms": "^2.1.3"
},
"engines": {
"node": ">=6.0"
},
"peerDependenciesMeta": {
"supports-color": {
"optional": true
}
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",
@ -1348,6 +1520,43 @@
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"license": "MIT"
},
"node_modules/event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
"license": "MIT",
"engines": {
"node": ">=6"
}
},
"node_modules/events": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
"license": "MIT",
"engines": {
"node": ">=0.8.x"
}
},
"node_modules/fast-unique-numbers": {
"version": "9.0.27",
"resolved": "https://registry.npmjs.org/fast-unique-numbers/-/fast-unique-numbers-9.0.27.tgz",
"integrity": "sha512-nDA9ADeINN8SA2u2wCtU+siWFTTDqQR37XvgPIDDmboWQeExz7X0mImxuaN+kJddliIqy2FpVRmnvRZ+j8i1/A==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"tslib": "^2.8.1"
},
"engines": {
"node": ">=18.2.0"
}
},
"node_modules/fast-unique-numbers/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/fdir": {
"version": "6.5.0",
"resolved": "https://registry.npmmirror.com/fdir/-/fdir-6.5.0.tgz",
@ -1514,6 +1723,63 @@
"node": ">= 0.4"
}
},
"node_modules/help-me": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/help-me/-/help-me-5.0.0.tgz",
"integrity": "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg==",
"license": "MIT"
},
"node_modules/ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "BSD-3-Clause"
},
"node_modules/inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"license": "ISC"
},
"node_modules/ip-address": {
"version": "10.1.0",
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.1.0.tgz",
"integrity": "sha512-XXADHxXmvT9+CRxhXg56LJovE+bmWnEWB78LB83VZTprKTmaC5QfruXocxzTZ2Kl0DNwKuBdlIhjL8LeY8Sf8Q==",
"license": "MIT",
"engines": {
"node": ">= 12"
}
},
"node_modules/js-sdsl": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.3.0.tgz",
"integrity": "sha512-mifzlm2+5nZ+lEcLJMoBK0/IH/bDg8XnJfd/Wq6IP+xoCjLZsTOnV2QpxlVbX9bMnkl5PdEjNtBJ9Cj1NjifhQ==",
"license": "MIT",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/js-sdsl"
}
},
"node_modules/lru-cache": {
"version": "10.4.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
"license": "ISC"
},
"node_modules/magic-string": {
"version": "0.30.21",
"resolved": "https://registry.npmmirror.com/magic-string/-/magic-string-0.30.21.tgz",
@ -1553,6 +1819,64 @@
"node": ">= 0.6"
}
},
"node_modules/minimist": {
"version": "1.2.8",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
"integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/mqtt": {
"version": "5.15.1",
"resolved": "https://registry.npmjs.org/mqtt/-/mqtt-5.15.1.tgz",
"integrity": "sha512-V1WnkGuJh3ec9QXzy5Iylw8OOBK+Xu1WhxcQ9mMpLThG+/JZIMV1PgLNRgIiqXhZnvnVLsuyxHl5A/3bHHbcAA==",
"license": "MIT",
"dependencies": {
"@types/readable-stream": "^4.0.21",
"@types/ws": "^8.18.1",
"commist": "^3.2.0",
"concat-stream": "^2.0.0",
"debug": "^4.4.1",
"help-me": "^5.0.0",
"lru-cache": "^10.4.3",
"minimist": "^1.2.8",
"mqtt-packet": "^9.0.2",
"number-allocator": "^1.0.14",
"readable-stream": "^4.7.0",
"rfdc": "^1.4.1",
"socks": "^2.8.6",
"split2": "^4.2.0",
"worker-timers": "^8.0.23",
"ws": "^8.18.3"
},
"bin": {
"mqtt": "build/bin/mqtt.js",
"mqtt_pub": "build/bin/pub.js",
"mqtt_sub": "build/bin/sub.js"
},
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/mqtt-packet": {
"version": "9.0.2",
"resolved": "https://registry.npmjs.org/mqtt-packet/-/mqtt-packet-9.0.2.tgz",
"integrity": "sha512-MvIY0B8/qjq7bKxdN1eD+nrljoeaai+qjLJgfRn3TiMuz0pamsIWY2bFODPZMSNmabsLANXsLl4EMoWvlaTZWA==",
"license": "MIT",
"dependencies": {
"bl": "^6.0.8",
"debug": "^4.3.4",
"process-nextick-args": "^2.0.1"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
"license": "MIT"
},
"node_modules/nanoid": {
"version": "3.3.11",
"resolved": "https://registry.npmmirror.com/nanoid/-/nanoid-3.3.11.tgz",
@ -1571,6 +1895,16 @@
"node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1"
}
},
"node_modules/number-allocator": {
"version": "1.0.14",
"resolved": "https://registry.npmjs.org/number-allocator/-/number-allocator-1.0.14.tgz",
"integrity": "sha512-OrL44UTVAvkKdOdRQZIJpLkAdjXGTRda052sN4sO77bKEzYYqWKMBjQvrJFzqygI99gL6Z4u2xctPW1tB8ErvA==",
"license": "MIT",
"dependencies": {
"debug": "^4.3.1",
"js-sdsl": "4.3.0"
}
},
"node_modules/picocolors": {
"version": "1.1.1",
"resolved": "https://registry.npmmirror.com/picocolors/-/picocolors-1.1.1.tgz",
@ -1618,12 +1952,49 @@
"node": "^10 || ^12 || >=14"
}
},
"node_modules/process": {
"version": "0.11.10",
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
"license": "MIT",
"engines": {
"node": ">= 0.6.0"
}
},
"node_modules/process-nextick-args": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==",
"license": "MIT"
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmmirror.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/readable-stream": {
"version": "4.7.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.7.0.tgz",
"integrity": "sha512-oIGGmcpTLwPga8Bn6/Z75SVaH1z5dUut2ibSyAMVhmUggWpmDn2dapB0n7f8nwaSiRtepAsfJyfXIO5DCVAODg==",
"license": "MIT",
"dependencies": {
"abort-controller": "^3.0.0",
"buffer": "^6.0.3",
"events": "^3.3.0",
"process": "^0.11.10",
"string_decoder": "^1.3.0"
},
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
"node_modules/rfdc": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz",
"integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==",
"license": "MIT"
},
"node_modules/rollup": {
"version": "4.59.0",
"resolved": "https://registry.npmmirror.com/rollup/-/rollup-4.59.0.tgz",
@ -1669,6 +2040,50 @@
"fsevents": "~2.3.2"
}
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
},
"node_modules/smart-buffer": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz",
"integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==",
"license": "MIT",
"engines": {
"node": ">= 6.0.0",
"npm": ">= 3.0.0"
}
},
"node_modules/socks": {
"version": "2.8.7",
"resolved": "https://registry.npmjs.org/socks/-/socks-2.8.7.tgz",
"integrity": "sha512-HLpt+uLy/pxB+bum/9DzAgiKS8CX1EvbWxI4zlmgGCExImLdiad2iCwXT5Z4c9c3Eq8rP2318mPW2c+QbtjK8A==",
"license": "MIT",
"dependencies": {
"ip-address": "^10.0.1",
"smart-buffer": "^4.2.0"
},
"engines": {
"node": ">= 10.0.0",
"npm": ">= 3.0.0"
}
},
"node_modules/source-map-js": {
"version": "1.2.1",
"resolved": "https://registry.npmmirror.com/source-map-js/-/source-map-js-1.2.1.tgz",
@ -1678,6 +2093,24 @@
"node": ">=0.10.0"
}
},
"node_modules/split2": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz",
"integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==",
"license": "ISC",
"engines": {
"node": ">= 10.x"
}
},
"node_modules/string_decoder": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
"license": "MIT",
"dependencies": {
"safe-buffer": "~5.2.0"
}
},
"node_modules/tinyglobby": {
"version": "0.2.15",
"resolved": "https://registry.npmmirror.com/tinyglobby/-/tinyglobby-0.2.15.tgz",
@ -1701,6 +2134,24 @@
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==",
"license": "0BSD"
},
"node_modules/typedarray": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==",
"license": "MIT"
},
"node_modules/undici-types": {
"version": "7.19.2",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.19.2.tgz",
"integrity": "sha512-qYVnV5OEm2AW8cJMCpdV20CDyaN3g0AjDlOGf1OW4iaDEx8MwdtChUp4zu4H0VP3nDRF/8RKWH+IPp9uW0YGZg==",
"license": "MIT"
},
"node_modules/util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
"license": "MIT"
},
"node_modules/vite": {
"version": "7.3.1",
"resolved": "https://registry.npmmirror.com/vite/-/vite-7.3.1.tgz",
@ -1822,6 +2273,98 @@
"vue": "^3.5.0"
}
},
"node_modules/worker-factory": {
"version": "7.0.49",
"resolved": "https://registry.npmjs.org/worker-factory/-/worker-factory-7.0.49.tgz",
"integrity": "sha512-lW7tpgy6aUv2dFsQhv1yv+XFzdkCf/leoKRTGMPVK5/die6RrUjqgJHJf556qO+ZfytNG6wPXc17E8zzsOLUDw==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"fast-unique-numbers": "^9.0.27",
"tslib": "^2.8.1"
}
},
"node_modules/worker-factory/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/worker-timers": {
"version": "8.0.31",
"resolved": "https://registry.npmjs.org/worker-timers/-/worker-timers-8.0.31.tgz",
"integrity": "sha512-ngkq5S6JuZyztom8tDgBzorLo9byhBMko/sXfgiUD945AuzKGg1GCgDMCC3NaYkicLpGKXutONM36wEX8UbBCA==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"tslib": "^2.8.1",
"worker-timers-broker": "^8.0.16",
"worker-timers-worker": "^9.0.14"
}
},
"node_modules/worker-timers-broker": {
"version": "8.0.16",
"resolved": "https://registry.npmjs.org/worker-timers-broker/-/worker-timers-broker-8.0.16.tgz",
"integrity": "sha512-JyP3AvUGyPGbBGW7XiUewm2+0pN/aYo1QpVf5kdXAfkDZcN3p7NbWrG6XnyDEpDIvfHk/+LCnOW/NsuiU9riYA==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"broker-factory": "^3.1.14",
"fast-unique-numbers": "^9.0.27",
"tslib": "^2.8.1",
"worker-timers-worker": "^9.0.14"
}
},
"node_modules/worker-timers-broker/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/worker-timers-worker": {
"version": "9.0.14",
"resolved": "https://registry.npmjs.org/worker-timers-worker/-/worker-timers-worker-9.0.14.tgz",
"integrity": "sha512-/qF06C60sXmSLfUl7WglvrDIbspmPOM8UrG63Dnn4bi2x4/DfqHS/+dxF5B+MdHnYO5tVuZYLHdAodrKdabTIg==",
"license": "MIT",
"dependencies": {
"@babel/runtime": "^7.29.2",
"tslib": "^2.8.1",
"worker-factory": "^7.0.49"
}
},
"node_modules/worker-timers-worker/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/worker-timers/node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
},
"node_modules/ws": {
"version": "8.20.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.20.0.tgz",
"integrity": "sha512-sAt8BhgNbzCtgGbt2OxmpuryO63ZoDk/sqaB/znQm94T4fCEsy/yV+7CdC1kJhOU9lboAEU7R3kquuycDoibVA==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/zrender": {
"version": "6.0.0",
"resolved": "https://registry.npmmirror.com/zrender/-/zrender-6.0.0.tgz",

View File

@ -12,6 +12,7 @@
"@kjgl77/datav-vue3": "^1.7.4",
"axios": "^1.13.6",
"echarts": "^6.0.0",
"mqtt": "^5.15.1",
"vue": "^3.5.25",
"vue-echarts": "^8.0.1",
"vue-router": "^4.5.0"

View File

@ -3,6 +3,33 @@
</template>
<script setup>
import { onMounted, onUnmounted } from 'vue'
import { startMqttDeviceRealtime, stopMqttDeviceRealtime } from './services/mqttDeviceStore.js'
const DESIGN_W = 1920
const DESIGN_H = 1080
function applyScale() {
const scaleX = window.innerWidth / DESIGN_W
const scaleY = window.innerHeight / DESIGN_H
const scale = Math.min(scaleX, scaleY)
const app = document.getElementById('app')
if (!app) return
app.style.transform = `scale(${scale})`
document.body.style.width = '100vw'
document.body.style.height = '100vh'
}
onMounted(() => {
applyScale()
window.addEventListener('resize', applyScale)
startMqttDeviceRealtime()
})
onUnmounted(() => {
window.removeEventListener('resize', applyScale)
stopMqttDeviceRealtime()
})
</script>
<style>

View File

@ -1,7 +1,7 @@
<template>
<div class="laser-card" :class="`status-${status.key}`" @click="$emit('click')">
<div class="card-top">
<span class="device-name">{{ device.name }} <span class="app-tag">{{ device.appName }}</span></span>
<span class="device-name">{{ device.name }} <span v-if="device.appName" class="app-tag">{{ device.appName }}</span></span>
<span class="status-badge" :style="{ color: statusColor }">
<span class="status-dot" :class="`dot-${status.key}`"></span>
{{ status.label }}
@ -26,11 +26,11 @@
</div>
</div>
<div class="right-stats">
<div class="right-stats" v-if="device.machineData">
<div class="stat"><span class="stat-label">穿孔</span><span class="stat-val green">{{ (device.machineData.pierceCount || 0).toLocaleString() }}<small>次</small></span></div>
<div class="stat"><span class="stat-label">切割</span><span class="stat-val cyan">{{ (device.machineData.cutLength / 1000).toFixed(1) }}<small>m</small></span></div>
<div class="stat"><span class="stat-label">开机率</span><span class="stat-val">{{ device.machineData.startRate }}</span></div>
<div class="stat"><span class="stat-label">切割率</span><span class="stat-val">{{ device.machineData.cutRate }}</span></div>
<div class="stat"><span class="stat-label">切割</span><span class="stat-val cyan">{{ ((device.machineData.cutLength || 0) / 1000).toFixed(1) }}<small>m</small></span></div>
<div class="stat"><span class="stat-label">开机率</span><span class="stat-val">{{ device.machineData.startRate || '--' }}</span></div>
<div class="stat"><span class="stat-label">切割率</span><span class="stat-val">{{ device.machineData.cutRate || '--' }}</span></div>
</div>
</div>
</div>
@ -44,7 +44,10 @@ const props = defineProps({ device: { type: Object, required: true } })
defineEmits(['click'])
const nc = computed(() => props.device.machineData?.CutSystemState?.NcState)
const status = computed(() => getLaserStatus(props.device.machineData))
const status = computed(() => {
if (!props.device.online) return { key: 'offline', label: '离线' }
return getLaserStatus(props.device.machineData)
})
const statusColor = computed(() => STATUS_COLORS[status.value.key] || '#fff')
</script>

View File

@ -24,7 +24,10 @@ import { getPowerStatus, STATUS_COLORS } from '../composables/useDeviceStatus.js
const props = defineProps({ device: { type: Object, required: true } })
defineEmits(['click'])
const status = computed(() => getPowerStatus(props.device.machineData))
const status = computed(() => {
if (!props.device.online) return { key: 'offline', label: '离线' }
return getPowerStatus(props.device.machineData)
})
const statusColor = computed(() => STATUS_COLORS[status.value.key] || '#555')
const phases = computed(() => {

View File

@ -0,0 +1,430 @@
/**
* MQTT(WebSocket) 实时设备数据:按 topic 订阅、JSON 合并、接收超时判离线
*
* 支持:
* - 短名且无 PREFIX:默认按 topic/device/{id}/data 展开(可用 VITE_MQTT_TOPIC_TEMPLATE 覆盖)
* - VITE_MQTT_TOPIC_PREFIX:短名会订成 prefix/短名(无 TEMPLATE、且短名不含 / 时)
* - VITE_MQTT_TOPICS 中直接写完整路径(含 /)则原样订阅,如 topic/device/rbiot-c01-001/data
* - 类型/展示名:从路径中识别 rbiot-a|b|c 段(避免末段为 data 时误判)
* - 与 MQTTX 一致:同时订阅「有/无」前导 /
*/
import { reactive } from 'vue'
import mqtt from 'mqtt'
const NESTED_CNC = ['allCoors', 'statusInfo', 'programCurrent', 'spindleSpeedAndFeedRate', 'sysInfo']
const DEFAULT_MQTT_TOPICS = 'rbiot-c01-001,rbiot-b01-001'
/** 未单独配置模板/前缀时,短 id 默认展开为现场常见路径(避免只订 rbiot-xxx 与 topic/device/.../data 不一致) */
const DEFAULT_TOPIC_TEMPLATE = 'topic/device/{id}/data'
function parseTopicList() {
const envRaw = (import.meta.env.VITE_MQTT_TOPICS ?? '').trim()
const raw = envRaw || DEFAULT_MQTT_TOPICS
const list = raw.split(',').map(s => s.trim()).filter(Boolean)
return list.length ? list : DEFAULT_MQTT_TOPICS.split(',').map(s => s.trim()).filter(Boolean)
}
/** 公共路径前缀,不含首尾 / */
function getMqttTopicPrefix() {
return (import.meta.env.VITE_MQTT_TOPIC_PREFIX ?? '').trim().replace(/^\/+|\/+$/g, '')
}
/** 显式配置的模板;空则与 PREFIX 一起决定是否用内置默认 */
function getMqttTopicTemplate() {
return (import.meta.env.VITE_MQTT_TOPIC_TEMPLATE ?? '').trim()
}
/**
* 配置里的一项 → 实际 MQTT topic(不含前导 /,便于统一匹配)
* - 已含 / 则视为完整 topic
* - 否则若有 VITE_MQTT_TOPIC_TEMPLATE,按模板展开
* - 否则拼接 VITE_MQTT_TOPIC_PREFIX
*/
function expandMqttTopicFromConfigEntry(raw) {
const s = String(raw).trim()
if (!s) return ''
const noLead = s.replace(/^\/+/g, '')
if (noLead.includes('/')) return normalizeTopicString(noLead)
let tpl = getMqttTopicTemplate()
// 未配置 TEMPLATE 且未配置 PREFIX 时,用默认 topic/device/{id}/data,与多数现场发布路径一致
if (!tpl && !getMqttTopicPrefix()) {
tpl = DEFAULT_TOPIC_TEMPLATE
}
if (tpl) {
return normalizeTopicString(
tpl
.replace(/\{id\}/gi, noLead)
.replace(/\{deviceId\}/gi, noLead)
)
}
const pre = getMqttTopicPrefix()
return pre ? `${pre}/${noLead}` : noLead
}
function buildFullTopicList() {
return parseTopicList().map(expandMqttTopicFromConfigEntry).filter(Boolean)
}
/**
* 从完整 topic 中取出设备 id 段(如 rbiot-c01-001)。
* 优先匹配路径中的 rbiot-a|b|c…;若末级为 data 则取倒数第二段。
*/
function topicDeviceId(mqttTopicFull) {
const parts = normalizeTopicString(mqttTopicFull).split('/').filter(Boolean)
const rob = parts.find(p => /^rbiot-[abc][a-z0-9.-]*$/i.test(p))
if (rob) return rob
if (parts.length >= 2 && parts[parts.length - 1].toLowerCase() === 'data') {
return parts[parts.length - 2] || parts[parts.length - 1]
}
return parts.length ? parts[parts.length - 1] : String(mqttTopicFull)
}
function inferTypeFromTopic(mqttTopicFull) {
const t = topicDeviceId(mqttTopicFull).toLowerCase()
if (t.startsWith('rbiot-c')) return 'power'
if (t.startsWith('rbiot-b')) return 'cnc'
if (t.startsWith('rbiot-a')) return 'laser'
return 'power'
}
/** 路由 param 安全:含 / 的 topic 必须编码,否则无法进 /device/:id */
function routeIdFromMqttTopic(mqttTopicCanonical) {
return encodeURIComponent(String(mqttTopicCanonical))
}
function normalizeTopicString(t) {
return String(t || '').trim().replace(/^\/+/g, '')
}
/** 同一逻辑 topic 的多种 broker 写法,全部订阅 */
function subscriptionVariants(canonical) {
const c = normalizeTopicString(canonical)
if (!c) return []
const set = new Set([c, `/${c}`])
return [...set]
}
function emptyWeeklyStats() {
return {
produce: [0, 0, 0, 0, 0, 0, 0],
cuttime: [0, 0, 0, 0, 0, 0, 0],
dates: null
}
}
function makeDeviceShell(mqttTopicCanonical) {
const mqttTopic = normalizeTopicString(mqttTopicCanonical)
const devId = topicDeviceId(mqttTopic)
const type = inferTypeFromTopic(mqttTopic)
const routeId = routeIdFromMqttTopic(mqttTopic)
return {
id: routeId,
mqttTopic,
name: devId,
appName: '',
type,
online: false,
offlineReason: '等待首条数据',
machineData: null,
weeklyStats: type === 'cnc' || type === 'laser' ? emptyWeeklyStats() : null,
powerHistory: type === 'power' ? [] : undefined,
lastReceivedAt: 0
}
}
function clone(obj) {
try {
return obj ? JSON.parse(JSON.stringify(obj)) : {}
} catch {
return {}
}
}
function mergeLaser(prev, next) {
const p = clone(prev)
for (const key of Object.keys(next)) {
if (key === 'CutSystemState' && next.CutSystemState && typeof next.CutSystemState === 'object') {
p.CutSystemState = p.CutSystemState || {}
const cs = next.CutSystemState
if (cs.NcState) p.CutSystemState.NcState = { ...(p.CutSystemState.NcState || {}), ...cs.NcState }
if (cs.DeviceState) p.CutSystemState.DeviceState = { ...(p.CutSystemState.DeviceState || {}), ...cs.DeviceState }
} else {
p[key] = next[key]
}
}
return p
}
function mergeCnc(prev, next) {
const p = clone(prev)
for (const key of Object.keys(next)) {
if (NESTED_CNC.includes(key) && next[key] && typeof next[key] === 'object' && !Array.isArray(next[key])) {
p[key] = { ...(p[key] || {}), ...next[key] }
} else {
p[key] = next[key]
}
}
return p
}
function mergePower(prev, next) {
return {
...(prev || {}),
...next,
slave1: { ...(prev?.slave1 || {}), ...(next.slave1 || {}) }
}
}
function stampNow() {
const now = new Date()
return now.getFullYear() + '-' +
String(now.getMonth() + 1).padStart(2, '0') + '-' +
String(now.getDate()).padStart(2, '0') + ' ' +
String(now.getHours()).padStart(2, '0') + ':' +
String(now.getMinutes()).padStart(2, '0') + ':' +
String(now.getSeconds()).padStart(2, '0')
}
function parseAmpere(v) {
if (v === undefined || v === null || v === 'invalid') return NaN
const s = String(v).replace(/A$/i, '').trim()
const n = parseFloat(s)
return Number.isFinite(n) ? n : NaN
}
function apparentPowerKw(slave1) {
if (!slave1) return 0
const i1 = parseAmpere(slave1.current1)
const i2 = parseAmpere(slave1.current2)
const i3 = parseAmpere(slave1.current3)
if (![i1, i2, i3].every(Number.isFinite)) return 0
const iAvg = (i1 + i2 + i3) / 3
return (Math.sqrt(3) * 380 * iAvg) / 1000
}
const DEBUG = import.meta.env.VITE_MQTT_DEBUG === 'true'
function log(...args) {
if (DEBUG) console.log('[MQTT]', ...args)
}
export const mqttRuntime = reactive({
devices: [],
connected: false,
reconnecting: false,
error: null,
lastRouteHint: '',
lastMessageTopic: '',
lastMessageAt: '',
offlineThresholdMs: Number(import.meta.env.VITE_MQTT_OFFLINE_MS || 30000),
/** 逻辑 topic 列表(canonical,无首 /) */
topics: [],
/** 实际已向 broker 订阅的字符串(含前导 / 变体) */
subscribedPatterns: []
})
let client = null
let offlineTimer = null
function applyPayload(device, data) {
const ts = data.timestamp || stampNow()
if (device.type === 'power') {
device.machineData = mergePower(device.machineData, { ...data, timestamp: ts })
const kw = apparentPowerKw(device.machineData.slave1)
if (!device.powerHistory) device.powerHistory = []
device.powerHistory.push({
t: ts.split(' ')[1] || ts,
kw: Math.round(kw * 1000) / 1000,
i1: device.machineData.slave1?.current1,
i2: device.machineData.slave1?.current2,
i3: device.machineData.slave1?.current3
})
if (device.powerHistory.length > 120) device.powerHistory.splice(0, device.powerHistory.length - 120)
if (data.client_id) device.name = String(data.client_id)
} else if (device.type === 'cnc') {
device.machineData = mergeCnc(device.machineData, { ...data, timestamp: ts })
} else if (device.type === 'laser') {
device.machineData = mergeLaser(device.machineData, { ...data, timestamp: ts })
if (data.appName) device.appName = String(data.appName)
}
device.lastReceivedAt = Date.now()
device.online = true
device.offlineReason = ''
}
function findDeviceForMessage(topic, data) {
const tNorm = normalizeTopicString(topic)
const list = mqttRuntime.devices
let d = list.find(x => normalizeTopicString(x.mqttTopic) === tNorm)
if (d) return d
d = list.find(x => tNorm.endsWith('/' + normalizeTopicString(x.mqttTopic)))
if (d) return d
const cid = data?.client_id != null ? String(data.client_id).trim().replace(/^\/+/g, '') : ''
if (cid) {
d = list.find(x => {
const xn = normalizeTopicString(x.mqttTopic)
const dev = topicDeviceId(xn)
return (
xn === cid ||
x.name === cid ||
dev === cid ||
xn.split('/').includes(cid) ||
xn.endsWith('/' + cid)
)
})
if (d) return d
}
return null
}
function onMessage(topic, payloadBuf) {
const raw = payloadBuf.toString()
log('message', topic, raw.slice(0, 200))
let data
try {
data = JSON.parse(raw)
} catch {
mqttRuntime.error = 'JSON 解析失败:请发送合法 JSON 正文(MQTTX 不要用纯文本)'
mqttRuntime.lastRouteHint = `topic=${topic},前 80 字:${raw.slice(0, 80)}`
return
}
if (data !== null && typeof data !== 'object') {
mqttRuntime.error = '载荷必须是 JSON 对象,不能是单个数字/字符串'
return
}
const device = findDeviceForMessage(topic, data)
if (!device) {
const subscribed = mqttRuntime.subscribedPatterns.join(', ')
mqttRuntime.lastRouteHint =
`未匹配设备:收到 topic「${topic}」→ 规范化「${normalizeTopicString(topic)}」。已订阅:${subscribed}。请与 VITE_MQTT_TOPICS / VITE_MQTT_TOPIC_TEMPLATE / VITE_MQTT_TOPIC_PREFIX 对齐,或在 JSON 中带 client_id(如 rbiot-c01-001)。`
mqttRuntime.error = 'topic 与设备列表不匹配'
log('no device for topic', topic)
return
}
try {
applyPayload(device, data)
mqttRuntime.lastMessageTopic = topic
mqttRuntime.lastMessageAt = stampNow()
mqttRuntime.error = null
mqttRuntime.lastRouteHint = ''
} catch (e) {
mqttRuntime.error = e?.message || '合并数据失败'
}
}
function tickOffline() {
const now = Date.now()
const th = mqttRuntime.offlineThresholdMs
for (const d of mqttRuntime.devices) {
if (!d.lastReceivedAt) continue
if (now - d.lastReceivedAt > th) {
if (d.online) {
d.online = false
d.offlineReason = '数据接收超时'
}
}
}
}
function parseExtraSubscriptions() {
const raw = (import.meta.env.VITE_MQTT_EXTRA_SUBSCRIBE ?? '').trim()
if (!raw) return []
return raw.split(',').map(s => s.trim()).filter(Boolean)
}
function collectAllSubscriptionStrings(fullTopicList, extraSubs) {
const bag = new Set()
fullTopicList.forEach(ft => subscriptionVariants(ft).forEach(v => bag.add(v)))
extraSubs.forEach(ex => subscriptionVariants(ex).forEach(v => bag.add(v)))
return [...bag]
}
export function startMqttDeviceRealtime() {
stopMqttDeviceRealtime()
const fullTopics = buildFullTopicList()
const extraSubs = parseExtraSubscriptions()
mqttRuntime.topics = fullTopics
mqttRuntime.devices = fullTopics.map(makeDeviceShell)
mqttRuntime.offlineThresholdMs = Number(import.meta.env.VITE_MQTT_OFFLINE_MS || 30000)
const allSubs = collectAllSubscriptionStrings(fullTopics, extraSubs)
mqttRuntime.subscribedPatterns = allSubs
const url = import.meta.env.VITE_MQTT_WS_URL || 'ws://127.0.0.1:9001/mqtt'
const user = import.meta.env.VITE_MQTT_USERNAME || undefined
const pass = import.meta.env.VITE_MQTT_PASSWORD || undefined
client = mqtt.connect(url, {
clientId: `dash-web-${Math.random().toString(16).slice(2, 10)}`,
username: user || undefined,
password: pass || undefined,
reconnectPeriod: 5000,
connectTimeout: 15000
})
client.on('connect', () => {
mqttRuntime.connected = true
mqttRuntime.reconnecting = false
mqttRuntime.error = null
log('subscribe', allSubs)
allSubs.forEach(t => {
client.subscribe(t, { qos: 0 }, err => {
if (err) mqttRuntime.error = `订阅失败: ${t}`
})
})
})
client.on('reconnect', () => {
mqttRuntime.reconnecting = true
})
client.on('error', err => {
mqttRuntime.error = err?.message || String(err)
})
client.on('close', () => {
mqttRuntime.connected = false
})
client.on('message', onMessage)
offlineTimer = setInterval(tickOffline, 1000)
}
export function stopMqttDeviceRealtime() {
if (offlineTimer) {
clearInterval(offlineTimer)
offlineTimer = null
}
if (client) {
client.removeAllListeners()
client.end(true)
client = null
}
mqttRuntime.connected = false
mqttRuntime.reconnecting = false
}
/** 详情页:根据路由 param 找设备(兼容编码前后) */
export function findDeviceByRouteParam(routeParamId) {
const p = String(routeParamId || '')
if (!p) return null
let decoded = p
try {
decoded = decodeURIComponent(p)
} catch { /* ignore */ }
return mqttRuntime.devices.find(
d => d.id === p || d.mqttTopic === p || d.mqttTopic === decoded || normalizeTopicString(d.mqttTopic) === normalizeTopicString(decoded)
) || null
}

View File

@ -8,8 +8,8 @@
}
html, body {
width: 1920px;
height: 1080px;
width: 100%;
height: 100%;
overflow: hidden;
background: #020c20;
font-family: 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', sans-serif;
@ -21,6 +21,7 @@ html, body {
#app {
width: 1920px;
height: 1080px;
transform-origin: left top;
overflow: hidden;
}

14
src/utils/weekLabels.js Normal file
View File

@ -0,0 +1,14 @@
/** 生成本周日期标签(周一至周日),用于趋势图横轴 */
export function getWeeklyInfo() {
const today = new Date()
const todayIdx = (today.getDay() + 6) % 7
const monday = new Date(today)
monday.setDate(today.getDate() - todayIdx)
const labels = []
for (let i = 0; i < 7; i++) {
const d = new Date(monday)
d.setDate(monday.getDate() + i)
labels.push(`${(d.getMonth() + 1).toString().padStart(2, '0')}/${d.getDate().toString().padStart(2, '0')}`)
}
return { labels, todayIdx }
}

View File

@ -6,7 +6,7 @@
<!-- ===== 左侧面板 ===== -->
<div class="left-panel panel-box">
<StatusSummary
:devices="devices"
:devices="mqtt.devices"
:weeklyLabels="weeklyLabels"
:weeklyProduce="weeklyProduceTotal"
:todayIdx="todayIdx"
@ -61,14 +61,20 @@
<!-- 底部状态栏 -->
<div class="refresh-indicator">
<span class="refresh-dot" :class="{ pulse: refreshing }"></span>
数据刷新间隔:{{ REFRESH_SEC }}s &nbsp;|&nbsp; 上次刷新:{{ lastRefresh }}
<span class="refresh-dot" :class="{ pulse: mqtt.connected }"></span>
MQTT:{{ mqtt.connected ? '已连接' : '未连接' }}{{ mqtt.reconnecting ? '(重连中)' : '' }}
&nbsp;|&nbsp; 超时阈值:{{ mqtt.offlineThresholdMs / 1000 }}s
<template v-if="mqtt.lastMessageAt">
&nbsp;|&nbsp; 最近消息:{{ mqtt.lastMessageTopic }} @ {{ mqtt.lastMessageAt }}
</template>
<span v-if="mqtt.error" class="mqtt-err">&nbsp;|&nbsp; {{ mqtt.error }}</span>
</div>
<div v-if="mqtt.lastRouteHint" class="mqtt-hint">{{ mqtt.lastRouteHint }}</div>
</div>
</template>
<script setup>
import { ref, reactive, computed, onMounted, onUnmounted } from 'vue'
import { computed } from 'vue'
import { useRouter } from 'vue-router'
import HeaderBar from '../components/HeaderBar.vue'
import LaserCard from '../components/LaserCard.vue'
@ -76,28 +82,24 @@ import CncCard from '../components/CncCard.vue'
import PowerCard from '../components/PowerCard.vue'
import StatusSummary from '../components/StatusSummary.vue'
import AlarmPanel from '../components/AlarmPanel.vue'
import { baseDevices, applyMutations, getWeeklyInfo } from '../services/mockData.js'
import { mqttRuntime } from '../services/mqttDeviceStore.js'
import { getWeeklyInfo } from '../utils/weekLabels.js'
import { getDeviceStatus } from '../composables/useDeviceStatus.js'
const router = useRouter()
const REFRESH_SEC = 5
const refreshing = ref(false)
const lastRefresh = ref('--')
// 创建 reactive 设备数据(基于真实格式的深拷贝)
const devices = reactive(JSON.parse(JSON.stringify(baseDevices)))
const mqtt = mqttRuntime
// 按类型过滤
const laserDevices = computed(() => devices.filter(d => d.type === 'laser'))
const cncDevices = computed(() => devices.filter(d => d.type === 'cnc'))
const powerDevices = computed(() => devices.filter(d => d.type === 'power'))
const laserDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'laser'))
const cncDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'cnc'))
const powerDevices = computed(() => mqttRuntime.devices.filter(d => d.type === 'power'))
// 周报表
const { labels: weeklyLabels, todayIdx } = getWeeklyInfo()
const weeklyProduceTotal = computed(() => {
const totals = [0, 0, 0, 0, 0, 0, 0]
devices.forEach(d => {
mqttRuntime.devices.forEach(d => {
if (d.weeklyStats?.produce) {
d.weeklyStats.produce.forEach((v, i) => {
if (i <= todayIdx) totals[i] += v
@ -111,7 +113,7 @@ const weeklyProduceTotal = computed(() => {
const alarms = computed(() => {
const arr = []
const now = new Date()
devices.forEach(d => {
mqttRuntime.devices.forEach(d => {
if (!d.online || !d.machineData) return
const status = getDeviceStatus(d)
if (status.key !== 'alarm') return
@ -137,19 +139,6 @@ function goDetail(id) {
router.push({ name: 'DeviceDetail', params: { id } })
}
function refresh() {
refreshing.value = true
applyMutations(devices)
lastRefresh.value = new Date().toLocaleTimeString('zh-CN', { hour12: false })
setTimeout(() => { refreshing.value = false }, 400)
}
let timer = null
onMounted(() => {
refresh()
timer = setInterval(refresh, REFRESH_SEC * 1000)
})
onUnmounted(() => clearInterval(timer))
</script>
<style scoped>
@ -258,4 +247,15 @@ onUnmounted(() => clearInterval(timer))
animation: pulse-dot 0.4s ease-in-out;
}
@keyframes pulse-dot { 0%{transform:scale(1)} 50%{transform:scale(1.6)} 100%{transform:scale(1)} }
.mqtt-err { color: #ff6b6b; }
.mqtt-hint {
flex-shrink: 0;
padding: 4px 16px 6px;
font-size: 10px;
line-height: 1.35;
color: #c9a227;
background: rgba(40, 30, 0, 0.35);
border-top: 1px solid rgba(201, 162, 39, 0.25);
word-break: break-all;
}
</style>

View File

@ -1,12 +1,19 @@
<template>
<div class="detail-page">
<div class="offline-page" v-if="!allDevices.length">
<div class="offline-box">
<div class="offline-title">未配置设备</div>
<div class="offline-reason">请配置 VITE_MQTT_TOPICS(逗号分隔);可选 VITE_MQTT_TOPIC_PREFIX 拼接路径,或直接写完整 topic(如 topic/xx/rbiot-c01-001)</div>
</div>
</div>
<template v-else>
<!-- 顶部导航 -->
<div class="detail-header">
<div class="header-left">
<button class="back-btn" @click="goBack">← 返回全景看板</button>
<select v-model="selectedId" @change="switchDevice" class="device-select">
<option v-for="d in allDevices" :key="d.id" :value="d.id">
{{ d.id }} · {{ d.name }} ({{ typeLabel(d.type) }})
{{ d.mqttTopic }} · {{ d.name }} ({{ typeLabel(d.type) }})
</option>
</select>
</div>
@ -16,7 +23,7 @@
</div>
<!-- 离线设备 -->
<div class="offline-page" v-if="!device?.online">
<div class="offline-page" v-if="device && !device.online">
<div class="offline-box">
<div class="offline-icon">⚠</div>
<div class="offline-title">设备离线</div>
@ -25,7 +32,7 @@
</div>
<!-- ===== CNC 明细 ===== -->
<div class="detail-content" v-else-if="device.type === 'cnc'">
<div class="detail-content" v-else-if="device && device.type === 'cnc'">
<div class="cards-row">
<!-- 基本状态 -->
<div class="detail-card">
@ -67,14 +74,14 @@
<div class="param-item"><span class="p-label">实际转速</span><span class="p-val text-cyan">{{ md.spindleSpeedAndFeedRate?.speed || 0 }} RPM</span></div>
<div class="param-item"><span class="p-label">实际进给</span><span class="p-val text-cyan">{{ md.spindleSpeedAndFeedRate?.feedRate || 0 }} mm/m</span></div>
</div>
<div class="load-bars">
<div class="load-bars" v-if="md.axisNames?.length">
<div class="axis-load" v-for="(name, idx) in md.axisNames" :key="name">
<span class="ax-name">{{ name }}轴</span>
<div class="load-bg"><div class="load-fill" :class="loadClass(md.axisLoad?.[idx])" :style="{ width: Math.min(Math.abs(md.axisLoad?.[idx] || 0), 100) + '%' }"></div></div>
<span class="ax-val" :class="loadClass(md.axisLoad?.[idx])">{{ md.axisLoad?.[idx] }}%</span>
</div>
</div>
<div class="coords-box">
<div class="coords-box" v-if="md.axisNames?.length">
<div class="coords-title">绝对坐标</div>
<div class="coords-vals">
<span class="coord" v-for="(name, idx) in md.axisNames" :key="name">{{ name }}: <span class="mono text-cyan">{{ (md.allCoors?.absolute[idx] || 0).toFixed(3) }}</span></span>
@ -91,7 +98,7 @@
</div>
<!-- ===== 激光明细 ===== -->
<div class="detail-content" v-else-if="device.type === 'laser'">
<div class="detail-content" v-else-if="device && device.type === 'laser'">
<div class="cards-row">
<div class="detail-card">
<div class="card-title">系统状态与作业</div>
@ -160,10 +167,14 @@
</div>
<!-- ===== 电力明细 ===== -->
<div class="detail-content" v-else-if="device.type === 'power'">
<div class="detail-content" v-else-if="device && device.type === 'power'">
<div class="cards-row">
<div class="detail-card" style="flex:0 0 50%;">
<div class="card-title">实时三相电流</div>
<div class="detail-card" style="flex:0 0 42%;">
<div class="card-title">实时三相电流(线电压 380V)</div>
<div class="power-kw-row">
<span class="kw-label">估算视在功率</span>
<span class="kw-val">{{ lastPowerKw }} <small>kVA</small></span>
</div>
<div class="power-display">
<div class="phase-big" v-for="(item, idx) in powerPhases" :key="idx">
<div class="phase-label">{{ item.label }}</div>
@ -171,8 +182,13 @@
</div>
</div>
</div>
<div class="detail-card chart-card-power" v-if="device.online">
<div class="card-title">实时功率曲线(√3×380V×Ī,仅供参考)</div>
<div class="chart-container" ref="powerChartRef"></div>
</div>
</div>
</div>
</template>
</div>
</template>
@ -180,15 +196,37 @@
import { ref, computed, onMounted, onUnmounted, nextTick, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import * as echarts from 'echarts'
import { baseDevices } from '../services/mockData.js'
import { mqttRuntime, findDeviceByRouteParam } from '../services/mqttDeviceStore.js'
import { getCncWorkModeText, getLaserSysStateText } from '../composables/useDeviceStatus.js'
const router = useRouter()
const route = useRoute()
const allDevices = baseDevices
const selectedId = ref(route.params.id || allDevices[0]?.id)
const device = computed(() => allDevices.find(d => d.id === selectedId.value))
const allDevices = computed(() => mqttRuntime.devices)
const selectedId = ref(String(route.params.id || ''))
const device = computed(() => findDeviceByRouteParam(selectedId.value) || findDeviceByRouteParam(route.params.id))
watch(
() => route.params.id,
(id) => {
const sid = id ? String(id) : ''
if (sid && findDeviceByRouteParam(sid)) selectedId.value = sid
},
{ immediate: true }
)
watch(
() => mqttRuntime.devices.map(d => d.id).join(','),
() => {
const list = mqttRuntime.devices
if (!list.length) return
if (!selectedId.value || !findDeviceByRouteParam(selectedId.value)) {
const rid = route.params?.id ? String(route.params.id) : ''
selectedId.value = (rid && findDeviceByRouteParam(rid)) ? rid : list[0].id
}
},
{ immediate: true }
)
const md = computed(() => device.value?.machineData || {})
const nc = computed(() => md.value?.CutSystemState?.NcState)
const ds = computed(() => md.value?.CutSystemState?.DeviceState)
@ -197,13 +235,34 @@ const lmd = computed(() => md.value || {})
const powerPhases = computed(() => {
const s = md.value?.slave1
if (!s) return []
const n = (v) => {
if (v === 'invalid') return NaN
return parseFloat(String(v).replace(/A$/i, ''))
}
return [
{ label: 'A相电流', value: s.current1, warn: parseFloat(s.current1) > 16 },
{ label: 'B相电流', value: s.current2, warn: parseFloat(s.current2) > 16 },
{ label: 'C相电流', value: s.current3, warn: parseFloat(s.current3) > 16 }
{ label: 'A相电流', value: s.current1, warn: Number.isFinite(n(s.current1)) && n(s.current1) > 16 },
{ label: 'B相电流', value: s.current2, warn: Number.isFinite(n(s.current2)) && n(s.current2) > 16 },
{ label: 'C相电流', value: s.current3, warn: Number.isFinite(n(s.current3)) && n(s.current3) > 16 }
]
})
function parseAmpereVal(v) {
if (v === undefined || v === null || v === 'invalid') return NaN
return parseFloat(String(v).replace(/A$/i, '').trim())
}
const lastPowerKw = computed(() => {
const s = md.value?.slave1
if (!s) return '0'
const i1 = parseAmpereVal(s.current1)
const i2 = parseAmpereVal(s.current2)
const i3 = parseAmpereVal(s.current3)
if (![i1, i2, i3].every(Number.isFinite)) return '--'
const iAvg = (i1 + i2 + i3) / 3
const kw = (Math.sqrt(3) * 380 * iAvg) / 1000
return (Math.round(kw * 1000) / 1000).toLocaleString('zh-CN')
})
function typeLabel(t) {
return { laser: '激光', cnc: 'CNC', power: '电力' }[t] || t
}
@ -225,15 +284,61 @@ function formatSec(sec) {
return `${h}H ${m}M`
}
// ====== ECharts ======
// ====== ECharts(CNC / 激光周趋势)======
const chartRef = ref(null)
let chartInstance = null
// ====== 电力实时功率曲线 ======
const powerChartRef = ref(null)
let powerChartInstance = null
function initChart() {
if (!chartRef.value || !device.value?.weeklyStats) return
if (device.value.type === 'power') return
if (chartInstance) {
chartInstance.dispose()
chartInstance = null
}
chartInstance = echarts.init(chartRef.value)
updateChart()
window.addEventListener('resize', () => chartInstance?.resize())
}
function onChartResize() {
chartInstance?.resize()
powerChartInstance?.resize()
}
function initPowerChart() {
if (!powerChartRef.value || device.value?.type !== 'power') return
if (powerChartInstance) {
powerChartInstance.dispose()
powerChartInstance = null
}
powerChartInstance = echarts.init(powerChartRef.value)
updatePowerChart()
}
function updatePowerChart() {
if (!powerChartInstance || device.value?.type !== 'power') return
const hist = device.value.powerHistory || []
const times = hist.map(h => h.t)
const kws = hist.map(h => h.kw)
powerChartInstance.setOption({
backgroundColor: 'transparent',
tooltip: { trigger: 'axis' },
grid: { left: '3%', right: '4%', bottom: '8%', top: '28px', containLabel: true },
xAxis: { type: 'category', data: times, axisLabel: { color: '#6a8a9a', fontSize: 10 } },
yAxis: {
type: 'value', name: 'kVA', nameTextStyle: { color: '#6a8a9a' },
axisLabel: { color: '#6a8a9a' }, splitLine: { lineStyle: { color: 'rgba(26,58,106,0.3)' } }
},
series: [{
name: '估算视在功率', type: 'line', smooth: true, symbol: 'none',
lineStyle: { width: 2, color: '#ff9800' },
areaStyle: { color: 'rgba(255,152,0,0.15)' },
data: kws
}]
}, true)
}
function updateChart() {
@ -279,14 +384,36 @@ function updateChart() {
watch(selectedId, () => {
nextTick(() => {
if (chartInstance) { chartInstance.dispose(); chartInstance = null }
if (powerChartInstance) { powerChartInstance.dispose(); powerChartInstance = null }
initChart()
initPowerChart()
})
})
onMounted(() => { nextTick(initChart) })
watch(
() => [device.value?.type, device.value?.powerHistory?.length, device.value?.machineData?.timestamp],
() => {
if (device.value?.type === 'power' && device.value?.online) {
nextTick(() => {
if (!powerChartInstance && powerChartRef.value) initPowerChart()
else updatePowerChart()
})
}
},
{ deep: true }
)
onMounted(() => {
window.addEventListener('resize', onChartResize)
nextTick(() => {
initChart()
initPowerChart()
})
})
onUnmounted(() => {
window.removeEventListener('resize', () => chartInstance?.resize())
window.removeEventListener('resize', onChartResize)
chartInstance?.dispose()
powerChartInstance?.dispose()
})
</script>
@ -401,4 +528,15 @@ onUnmounted(() => {
.phase-label { font-size: 14px; color: #5a7a9a; margin-bottom: 8px; }
.phase-value { font-size: 42px; font-weight: 800; color: #00e5ff; font-family: 'Consolas',monospace; }
.phase-value.warn { color: #ff4444; }
.power-kw-row {
display: flex; justify-content: space-between; align-items: center;
margin-bottom: 12px; padding: 8px 12px; background: #0d2654; border-radius: 6px;
}
.kw-label { font-size: 13px; color: #5a7a9a; }
.kw-val { font-size: 22px; font-weight: 800; color: #ff9800; font-family: Consolas, monospace; }
.kw-val small { font-size: 12px; color: #8a9aaa; font-weight: 600; }
.cards-row .chart-card-power { flex: 1; min-height: 280px; display: flex; flex-direction: column; }
.chart-card-power .chart-container { flex: 1; min-height: 220px; }
</style>

View File

@ -1,4 +1,3 @@
# A类设备
## 基础信息(现场设备)
@ -9,14 +8,13 @@
`机床001`: 192.168.1.101 (软件型号:HypCut)对应现场右手边的机床
`机床002`: {机床002 ip} 该机床ip地址是DHCP的,请使用api获取机床的ip地址: GET http://192.168.1.188:8080/api/datacenter/list 。(软件型号:TubePro)对应现场左手边的机床
`机床002`: {机床002 ip} 该机床ip地址是DHCP的,请使用api获取机床的ip地址: GET [http://192.168.1.188:8080/api/datacenter/list](http://192.168.1.188:8080/api/datacenter/list) 。(软件型号:TubePro)对应现场左手边的机床
## API 说明
示例中的 http:// 链接可以直接赋值到浏览器中打开查看示例,最终显示结果并不是示例中的内容。
![alt text](images/image.png)
alt text
### 关于局域网机床应用接口
@ -28,12 +26,11 @@
http://192.168.1.188:8080/api/datacenter/list
```
#### 获取应用列表
示例:
http://192.168.1.188:8080/api/datacenter/listRunningApp
[http://192.168.1.188:8080/api/datacenter/listRunningApp](http://192.168.1.188:8080/api/datacenter/listRunningApp)
#### 获取机床设备信息
@ -45,7 +42,6 @@ http://192.168.1.188:8080/api/datacenter/info?ip=192.168.1.101
http://192.168.1.188:8080/api/datacenter/info?ip={机床002 ip}
```
#### 获取应用详细信
- 接口url: GET http://{魔盒ip}:8080/api/datacenter/appInfo
@ -55,10 +51,12 @@ http://192.168.1.188:8080/api/datacenter/info?ip={机床002 ip}
请求参数:
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --- | --- | --- | --- | --- | --- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
| appName | string | 是 | 无 | 应用名称 | HypCut / TubePro |
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| ------- | ------ | ---- | --- | ------ | ------------------------- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
| appName | string | 是 | 无 | 应用名称 | HypCut / TubePro |
示例:
@ -68,7 +66,6 @@ http://192.168.1.188:8080/api/datacenter/appInfo?ip=192.168.1.101&appName=HypCut
http://192.168.1.188:8080/api/datacenter/appInfo?ip={机床002 ip}&appName=TubePro
```
#### 获取机床运行状态信息
- 接口url: GET http://{魔盒ip}:8080/api/monitor/cutSystemState
@ -78,10 +75,12 @@ http://192.168.1.188:8080/api/datacenter/appInfo?ip={机床002 ip}&appName=TubeP
请求参数:
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --- | --- | --- | --- | --- | --- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
| appName | string | 是 | 无 | 应用名称 | CypCut / TubePro |
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| ------- | ------ | ---- | --- | ------ | ------------------------- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
| appName | string | 是 | 无 | 应用名称 | CypCut / TubePro |
示例:
@ -91,7 +90,6 @@ http://192.168.1.188:8080/api/monitor/cutSystemState?ip=192.168.1.101&appName=Hy
http://192.168.1.188:8080/api/monitor/cutSystemState?ip={机床002 ip}&appName=TubePro
```
#### 获取机床本地加工记录
示例:
@ -111,9 +109,11 @@ http://192.168.1.188:8080/api/monitor/machine/history?ip={机床002 ip}&startDat
请求参数:
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --- | --- | --- | --- | --- | --- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --- | ------ | ---- | --- | ------ | ------------------------- |
| ip | string | 是 | 无 | 机床ip地址 | 正确的IP地址格式,如 192.168.1.101 |
示例:
@ -132,15 +132,17 @@ http://192.168.1.188:8080/api/machine/running/tech?ip={机床002 ip}
请求参数:
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --- | --- | --- | --- | --- | --- |
| ip | string | 是 | 无 | 机床ip地址 | 设备ip |
| startDate | string | 是 | 无 | 开始时间 | yyyy-MM-dd HH:mm:ss 形式,开始时间不得早于一年前 |
| endDate | string | 是 | 无 | 结束时间 | yyyy-MM-dd HH:mm:ss 形式 |
| appName | string | 是 | 无 | 应用名称 | CypCut , TubePro 等 |
| 名称 | 类型 | 是否必选 | 默认值 | 描述 | 备注 |
| --------- | ------ | ---- | --- | ------ | ---------------------------------- |
| ip | string | 是 | 无 | 机床ip地址 | 设备ip |
| startDate | string | 是 | 无 | 开始时间 | yyyy-MM-dd HH:mm:ss 形式,开始时间不得早于一年前 |
| endDate | string | 是 | 无 | 结束时间 | yyyy-MM-dd HH:mm:ss 形式 |
| appName | string | 是 | 无 | 应用名称 | CypCut , TubePro 等 |
示例:
```
http://192.168.1.188:8080/api/machine/alarm/v2?ip=192.168.1.101&appName=CypCut&startDate=2026-01-15 00:00:00&endDate=2026-01-19 16:00:00
@ -148,14 +150,11 @@ http://192.168.1.188:8080/api/machine/alarm/v2?ip={机床002 ip}&appName=TubePro
```
### 任务类接口
暂无示例
#### 推送任务
#### 推送任务
#### 指派任务到机床
@ -163,7 +162,6 @@ http://192.168.1.188:8080/api/machine/alarm/v2?ip={机床002 ip}&appName=TubePro
#### 远程打开图纸
### 统计类接口
统计接口目前只针对于CypCut,TubePro统计不准确不稳定,慎用!!!
@ -243,21 +241,14 @@ http://192.168.1.188:8080/api/statistic/extreme?ip={机床002 ip}&startDate=2026
```
# B类设备
## 提示
下面的均为同一台 Series 0i-MF 设备的示例数据,其他设备可能有所不同。请查看 [`B类设备信息核对.md`](B类设备信息核对.md)
下面的均为同一台 Series 0i-MF 设备的示例数据,其他设备可能有所不同。请查看 `[B类设备信息核对.md](B类设备信息核对.md)`
1. 刚部署或者重新部署后会先发送下面两条数据,然后才会发送所需的数据。
2. 有可能在下面两条数据之前先返回所需数据的报错内容(不正常返回内容)。
3. timestamp字段为读取该数据的时间
```json
@ -284,12 +275,10 @@ http://192.168.1.188:8080/api/statistic/extreme?ip={机床002 ip}&startDate=2026
}
```
## 功能示例(单独)
非正常数据
```json
// 非正常返回内容
{
@ -843,6 +832,7 @@ Status of alarm
## 所有信息示例
### 所有信息
```json
{
"alarm": [],
@ -1126,9 +1116,6 @@ Status of alarm
}
```
# C类设备
## 设备信息示例

105
设备可采集字段表.md Normal file
View File

@ -0,0 +1,105 @@
# 设备可采集字段表
| 设备类型 | 字段键 | 客户展示名称 | 说明 | 单位/格式 |
| ------- | ----------------------------------------- | --------- | ----------------------------- | --------------------- |
| A类(激光) | `ip` | 设备IP | 机床网络地址 | IPv4 |
| A类(激光) | `appName` | 当前应用 | 当前运行软件(HypCut/TubePro/CypCut) | 文本 |
| A类(激光) | `online` | 在线状态 | 设备是否在线 | 在线/离线 |
| A类(激光) | `runStatus` / `SysState` | 运行状态 | 待机/加工中/暂停等 | 文本枚举 |
| A类(激光) | `alarmCount` | 当前报警数 | 当前报警数量 | 条 |
| A类(激光) | `alarmMsg` | 当前报警信息 | 当前报警内容 | 文本 |
| A类(激光) | `taskName` | 当前任务名 | 当前加工任务/图纸名 | 文本 |
| A类(激光) | `cutPercent` | 加工进度 | 当前任务进度 | % |
| A类(激光) | `pierceCount` | 穿孔数 | 当日/当班加工计数(按统计口径) | 次 |
| A类(激光) | `cutLength` | 切割长度 | 切割总长度/区间长度 | m |
| A类(激光) | `laserTime` | 开光时长 | 激光开启累计时长 | h/min |
| A类(激光) | `gasTime` | 开气时长 | 辅助气体开启累计时长 | h/min |
| A类(激光) | `runTime` | 运行时长 | 设备运行累计时长 | h/min |
| A类(激光) | `historyRecords` | 加工历史 | 按时间段查询历史加工记录 | 列表 |
| A类(激光) | `dailyLength[]` | 每日切割/空移统计 | 每天切割和空移统计 | m/天 |
| A类(激光) | `dailyPierceCount[]` | 每日加工统计 | 每天加工次数统计 | 次/天 |
| A类(激光) | `summary` | 总体统计 | 区间汇总指标 | 对象 |
| A类(激光) | `serverName` | 设备名称 | 机床主机名称/设备名 | 文本 |
| A类(激光) | `gmid` | 设备唯一编号 | 机床唯一标识 | 数字 |
| A类(激光) | `macAddress` | 设备MAC地址 | 网络物理地址 | MAC 地址 |
| A类(激光) | `cardId` | 控制卡ID | 控制卡标识 | 文本 |
| A类(激光) | `aliveTime` | 最后心跳时间 | 设备最近在线上报时间 | `YYYY-MM-DD HH:mm:ss` |
| A类(激光) | `appInfos[].appVer` | 软件版本 | 运行软件版本号 | 文本 |
| A类(激光) | `CutSystemState.NcState.WorkTime` | 当前加工时长 | 当前任务加工累计时长 | s 或天(按软件版本) |
| A类(激光) | `CutSystemState.NcState.TotalWorkTime` | 累计加工时长 | 历史累计加工时长 | s 或天(按软件版本) |
| A类(激光) | `CutSystemState.NcState.WorkSpeed` | 当前加工速度 | 实时加工速度 | mm/s 或 m/min |
| A类(激光) | `CutSystemState.NcState.FeedRate` | 当前进给倍率 | 进给倍率 | % |
| A类(激光) | `CutSystemState.NcState.LaserPower` | 激光器功率 | 当前激光器功率 | W |
| A类(激光) | `CutSystemState.DeviceState.GasType` | 气体类型 | 当前切割气体类型(空气/氧气/氮气等) | 枚举 |
| A类(激光) | `CutSystemState.DeviceState.GasPressure` | 切割气压 | 当前切割气压 | bar |
| A类(激光) | `CutSystemState.DeviceState.IsLaserOn` | 激光开关状态 | 是否开激光 | 是/否 |
| A类(激光) | `CutSystemState.DeviceState.IsGasOn` | 出气状态 | 是否出气 | 是/否 |
| A类(激光) | `CutSystemState.DeviceState.PwmFreq` | 脉冲频率 | PWM 脉冲频率 | Hz |
| A类(激光) | `CutSystemState.DeviceState.PwmRatio` | 占空比 | 激光占空比 | % |
| A类(激光) | `CutSystemState.DeviceState.CurrentX/Y/Z` | 实时坐标 | 设备实时坐标位置 | mm |
| A类(激光) | `history[].FileName` | 加工文件名 | 历史加工记录中的文件名 | 文本 |
| A类(激光) | `history[].StartTime` | 开始时间 | 历史任务开始加工时间 | `YYYY-MM-DD HH:mm:ss` |
| A类(激光) | `history[].EndTime` | 结束时间 | 历史任务结束加工时间 | `YYYY-MM-DD HH:mm:ss` |
| A类(激光) | `history[].TimeTaken` | 单次加工时长 | 单条任务加工耗时 | s |
| A类(激光) | `history[].PartCount` | 完成零件数 | 单条任务完成零件数量 | 件 |
| A类(激光) | `history[].MoveLength` | 空移长度 | 单条任务空移距离 | mm |
| A类(激光) | `history[].CurveLength` | 切割长度 | 单条任务切割长度 | mm |
| A类(激光) | `history[].Material` | 材质 | 加工材质 | 文本 |
| A类(激光) | `history[].Thickness` | 板材厚度 | 加工板材厚度 | mm |
| A类(激光) | `history[].Size` | 板材尺寸 | 板材规格 | 文本(如 `2000 x 3000`) |
| A类(激光) | `tech.techName` | 当前工艺名 | 设备当前使用工艺名称(加工中可获取) | 文本 |
| A类(激光) | `tech.WorkSpeed` | 工艺切割速度 | 当前工艺参数中的切割速度 | mm/s |
| A类(激光) | `tech.Focus` | 工艺焦点位置 | 当前工艺焦点参数 | mm |
| A类(激光) | `tech.GasPressure` | 工艺气压 | 当前工艺参数中的气压 | bar |
| A类(激光) | `tech.LaserDiodeCurrent` | 工艺峰值功率 | 当前工艺参数中的峰值功率 | % |
| A类(激光) | `alarms[].AlarmCode` | 报警代号 | 报警代码 | 数字 |
| A类(激光) | `alarms[].AlarmClass` | 报警模块 | 报警所属模块 | 文本 |
| A类(激光) | `alarms[].AlarmDesc` | 报警描述 | 报警内容说明 | 文本 |
| A类(激光) | `alarms[].StartTime` | 报警开始时间 | 报警开始时间 | `YYYY-MM-DD HH:mm:ss` |
| A类(激光) | `alarms[].RemoveTime` | 报警解除时间 | 报警解除时间 | `YYYY-MM-DD HH:mm:ss` |
| A类(激光) | `dailyLaser[]` | 每日开光时长 | 每天激光开启时长 | s/天 |
| A类(激光) | `dailyGasTime[]` | 每日开气时长 | 每天气体开启时长 | s/天 |
| A类(激光) | `dailyRunTime[].workTime` | 每日加工时长 | 每天加工时长 | s/天 |
| A类(激光) | `dailyRunTime[].idleTime` | 每日空闲时长 | 每天空闲时长 | s/天 |
| A类(激光) | `extreme.maxCutlength` | 最大切割长度 | 统计区间内单日最大切割长度 | mm |
| A类(激光) | `extreme.maxMoveLength` | 最大空移长度 | 统计区间内单日最大空移长度 | mm |
| A类(激光) | `extreme.maxPierceCount` | 最大穿孔数 | 统计区间内单日最大穿孔数 | 次 |
| A类(激光) | `extreme.maxWorkTime` | 最大加工时长 | 统计区间内单日最长加工时长 | s |
| A类(激光) | `extreme.maxIdleTime` | 最大空闲时长 | 统计区间内单日最长空闲时长 | s |
| B类(CNC) | `sysInfo.cncType` | CNC型号 | 设备控制系统型号 | 文本 |
| B类(CNC) | `sysInfo.series` | 系列号 | 控制系统系列 | 文本 |
| B类(CNC) | `sysInfo.version` | 系统版本 | 控制系统版本号 | 文本 |
| B类(CNC) | `sysInfo.axes` | 轴数 | 机床轴数量 | 个 |
| B类(CNC) | `statusInfo.WorkMode` | 工作模式 | AUTO/JOG/EDIT等 | 文本枚举 |
| B类(CNC) | `statusInfo.RunStatus` | 运行状态 | START/RESET等 | 文本枚举 |
| B类(CNC) | `statusInfo.Emergency` | 急停状态 | 是否急停 | 0/1 或 是/否 |
| B类(CNC) | `statusInfo.Alarm` | 报警状态 | 是否处于报警态 | 0/1 或 是/否 |
| B类(CNC) | `alarm[]` | 报警列表 | 当前报警内容列表 | 列表 |
| B类(CNC) | `allCoors.absolute[]` | 绝对坐标 | X/Y/Z绝对坐标 | mm |
| B类(CNC) | `allCoors.relative[]` | 相对坐标 | X/Y/Z相对坐标 | mm |
| B类(CNC) | `allCoors.machine[]` | 机械坐标 | X/Y/Z机械坐标 | mm |
| B类(CNC) | `spindleSpeedAndFeedRate.speed` | 主轴转速 | 主轴实际转速 | rpm |
| B类(CNC) | `spindleSpeedAndFeedRate.feedRate` | 进给速度 | 当前进给速度 | mm/min |
| B类(CNC) | `setSpindleSpeed` | 主轴倍率 | 主轴倍率设定值 | % |
| B类(CNC) | `setFeedRate` | 进给倍率 | 进给倍率设定值 | % |
| B类(CNC) | `programCurrent.number` | 当前程序号 | 当前执行程序编号 | 数字 |
| B类(CNC) | `programCurrent.name` | 当前程序名 | 当前执行程序名称 | 文本 |
| B类(CNC) | `programList[]` | 程序列表 | 可用程序编号列表 | 列表 |
| B类(CNC) | `currentProgram` | 程序内容 | 当前程序正文(G代码) | 长文本 |
| B类(CNC) | `currentForegroundDir` | 程序路径 | 当前程序目录 | 文本路径 |
| B类(CNC) | `cutterNumber` | 当前刀号 | 当前刀库刀号 | 号 |
| B类(CNC) | `cutters[]` | 刀具补偿 | 长度/半径补偿参数 | mm |
| B类(CNC) | `currentProduceCount` | 已加工数量 | 累计加工件数 | 件 |
| B类(CNC) | `boottime` | 开机时长 | 累计开机时间 | `H M S` |
| B类(CNC) | `runtime` | 运行时长 | 累计运行时间 | `H M S` |
| B类(CNC) | `cuttime` | 切削时间 | 累计切削/加工时间 | `H M S` |
| B类(CNC) | `cycletime` | 循环时间 | 加工循环累计时间 | `H M S` |
| B类(CNC) | `currentDateTime.str` | 机床时间 | CNC当前系统时间 | `YYYY/MM/DD HH:mm:ss` |
| B类(CNC) | `axisNames[]` | 轴名称 | 轴名(X/Y/Z) | 列表 |
| C类(电力) | `client_id` | 设备编号 | 电力监测设备ID | 文本 |
| C类(电力) | `slave1.current1` | A相电流 | A相电流值(无效可能为`invalid`) | A(1位小数) |
| C类(电力) | `slave1.current2` | B相电流 | B相电流值(无效可能为`invalid`) | A(1位小数) |
| C类(电力) | `slave1.current3` | C相电流 | C相电流值(无效可能为`invalid`) | A(1位小数) |