add header

This commit is contained in:
lb 2023-09-10 15:09:12 +08:00
parent e87bca96d6
commit 6c1435c7ff
16 changed files with 1594 additions and 22 deletions

View File

@ -1,6 +1,7 @@
{ {
"private": true, "private": true,
"scripts": { "scripts": {
"server": "nodemon --watch websocket --exec ts-node websocket/server.ts",
"start": "umi dev", "start": "umi dev",
"build": "umi build", "build": "umi build",
"postinstall": "umi generate tmp", "postinstall": "umi generate tmp",
@ -22,18 +23,24 @@
"dependencies": { "dependencies": {
"@ant-design/icons": "^4.7.0", "@ant-design/icons": "^4.7.0",
"@jiaminghi/data-view-react": "^1.2.5", "@jiaminghi/data-view-react": "^1.2.5",
"@types/node": "^20.6.0",
"@types/ws": "^8.5.5",
"antd": "^4.20.6", "antd": "^4.20.6",
"echarts": "^5.3.2", "echarts": "^5.3.2",
"echarts-for-react": "^3.0.2", "echarts-for-react": "^3.0.2",
"framer-motion": "^6.3.3", "framer-motion": "^6.3.3",
"less": "^4.1.3", "less": "^4.1.3",
"less-loader": "^11.0.0", "less-loader": "^11.0.0",
"moment": "^2.29.4",
"nodemon": "^3.0.1",
"react": "^16.8.6", "react": "^16.8.6",
"react-dom": "^16.8.6", "react-dom": "^16.8.6",
"react-router-dom": "^6.3.0", "react-router-dom": "^6.3.0",
"style-components": "^0.1.0", "style-components": "^0.1.0",
"styled-components": "^5.3.5", "styled-components": "^5.3.5",
"umi": "^3.5.23" "ts-node": "^10.9.1",
"umi": "^3.5.23",
"ws": "^8.14.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/runtime": "^7.18.0", "@babel/runtime": "^7.18.0",
@ -43,7 +50,7 @@
"@umijs/test": "^3.5.23", "@umijs/test": "^3.5.23",
"lint-staged": "^10.0.7", "lint-staged": "^10.0.7",
"prettier": "^2.2.0", "prettier": "^2.2.0",
"typescript": "^4.1.2", "typescript": "^5.2.2",
"yorkie": "^2.0.0" "yorkie": "^2.0.0"
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 32 MiB

After

Width:  |  Height:  |  Size: 6.3 MiB

BIN
src/assets/yx-dark/bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
src/assets/yx-dark/date.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 KiB

BIN
src/assets/yx-dark/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -0,0 +1,26 @@
import React, { useEffect, useState, useRef } from 'react';
import './header.module.css';
import moment from 'moment';
export default (props) => {
let [today, setToday] = useState(new Date());
moment.locale('zh-cn');
setTimeout(() => {
setToday(new Date());
}, 1000);
return (
<header class="header">
<div>
<span class="header--logo"></span>
<h1>宜兴新能源生产线大数据指挥中心</h1>
</div>
<span class="header--wing absolute company">
设计单位中建材智能自动化研究院
</span>
<span class="header--wing absolute datetime">
{moment(today).format('YYYY.M.D dddd HH:mm:ss')}
</span>
</header>
);
};

View File

@ -0,0 +1,53 @@
header {
height: 121px;
width: 100%;
position: relative;
z-index: 10000;
background: url(../../assets/yx-dark/header.png) 100% 100% / contain no-repeat;
display: grid;
place-content: center;
}
header > div {
display: flex;
align-items: center;
margin-bottom: 0;
}
header > div .header--logo {
margin-top: 12px;
width: 48px;
height: 67px;
background: url(../../assets/yx-dark/logo.png) center/contain no-repeat;
}
header h1 {
margin-bottom: 0;
margin-left: 36px;
font-size: 52px;
/* line-height: 97px; */
user-select: none;
letter-spacing: 9px;
font-weight: 400;
color: #6bf2ff;
font-family: '微软雅黑', sans-serif;
}
.header--wing {
left: 0;
bottom: -12px;
height: 48px;
font-size: 28px;
line-height: 48px;
color: #51f0ff;
}
.company {
margin-left: 960px;
letter-spacing: 1px;
}
.datetime {
text-align: center;
left: unset;
right: 1100px;
letter-spacing: 1px;
}

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import './global.less'; import './global.less';
import './index.less'; import './index.less';
import Head from '../components/Head'; import Header from '../components/yx-dark/Header';
import LeftBar from '../components/LeftBar'; import LeftBar from '../components/LeftBar';
import BottomBar from '../components/BottomBar'; import BottomBar from '../components/BottomBar';
import RightBar from '../components/RightBar'; import RightBar from '../components/RightBar';
@ -9,11 +9,8 @@ import CenterTopData from '../components/CenterTopData';
import Slider from '../components/Slider'; import Slider from '../components/Slider';
import { SocketContextProvider } from '../store/socket-data-provider'; import { SocketContextProvider } from '../store/socket-data-provider';
import V3DBG from '../assets/V3DBG.png';
// import V3D from './V3D';
export default function index() { export default function index() {
const [value, setValue] = useState(100); const [value, setValue] = useState(50);
const v = (value / 100).toFixed(2); const v = (value / 100).toFixed(2);
const styles = { const styles = {
@ -24,13 +21,11 @@ export default function index() {
useEffect(() => { useEffect(() => {
let fn = (e) => { let fn = (e) => {
console.log('add fn');
if (e.shiftKey && e.key === 'L') { if (e.shiftKey && e.key === 'L') {
document.getElementById('slider').classList.toggle('show'); document.getElementById('slider').classList.toggle('show');
} }
}; };
let fn2 = () => { let fn2 = () => {
console.log('add fn2');
setTimeout(() => { setTimeout(() => {
document.getElementById('slider').classList.remove('show'); document.getElementById('slider').classList.remove('show');
}, 200); }, 200);
@ -40,7 +35,6 @@ export default function index() {
document.getElementById('slider').addEventListener('mouseleave', fn2); document.getElementById('slider').addEventListener('mouseleave', fn2);
return () => { return () => {
console.log('remove fn, fn2');
document.removeEventListener('keydown', fn); document.removeEventListener('keydown', fn);
document.getElementById('slider').removeEventListener('mouseleave', fn2); document.getElementById('slider').removeEventListener('mouseleave', fn2);
}; };
@ -50,20 +44,19 @@ export default function index() {
// <FullScreenContainer> // <FullScreenContainer>
<SocketContextProvider> <SocketContextProvider>
<div id="FullScreen" style={styles}> <div id="FullScreen" style={styles}>
<Head /> <Header />
<div className="Main"> <div className="Main">
<LeftBar /> {/* <LeftBar />
<div className="Center"> <div className="Center">
<div className="CenterData"> <div className="CenterData">
<CenterTopData /> <CenterTopData />
</div> </div>
<img src={V3DBG} alt="图片加载错误" className="V3DBG" /> <div className="V3DBorder"></div>
<div className="V3DBorder">{/* <V3D /> */}</div>
<div className="Button"> <div className="Button">
<BottomBar /> <BottomBar />
</div> </div>
</div> </div>
<RightBar /> <RightBar /> */}
</div> </div>
</div> </div>
<Slider handleSlide={setValue} /> <Slider handleSlide={setValue} />

View File

@ -1,13 +1,16 @@
#FullScreen { #FullScreen {
width: 3840px; width: 4320px;
height: 1080px; height: 1080px;
transform-origin: 'lefttop'; background: url(../assets/yx-dark/bg.png) 100% / cover no-repeat;
background-color: #040c1c; display: flex;
flex-direction: column;
.Main { .Main {
// background: #a935355f; // background: #a935355f;
width: 3840px; width: 4320px;
height: 996px; height: 1px;
flex: 1;
background: #ccc3;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
@ -28,7 +31,6 @@
width: 2472px; width: 2472px;
height: 640px; height: 640px;
z-index: 1; z-index: 1;
box-shadow: inset 0 0 128px 64px #0a2859;
} }
.V3DBorder { .V3DBorder {

View File

@ -9,7 +9,8 @@ export const SocketContextProvider = (props) => {
useEffect(() => { useEffect(() => {
// const socket = new WebSocket('ws://172.16.1.55:8081/xc-screen/websocket/1'); // const socket = new WebSocket('ws://172.16.1.55:8081/xc-screen/websocket/1');
const socket = new WebSocket( const socket = new WebSocket(
'ws://192.168.1.12:8081/xc-screen/websocket/1', // 'ws://192.168.1.12:8081/xc-screen/websocket/1',
'ws://127.0.0.1:9800',
); );
socket.onopen = () => { socket.onopen = () => {
console.log('[*] socket connected!'); console.log('[*] socket connected!');

458
websocket/d.txt Normal file
View File

@ -0,0 +1,458 @@
推送火向,剩余换火时间,压力,换火时间等信息
目前缺少四个温度
循环水温
熔化温度
碹顶温度
支通路温度
{
"data": {
"waterFlow": "99.0m³/h",
"fireChangeTime": "46.0S",
"compressedAirPressure": "95.0MPa",
"combustionAirPressure": "73.0Pa",
"waterPressure": "29.0MPa",
"lastFireChangeTime": "10分20秒",
"combustionAirPressureArr": [
"1.0m³/h",
"16.0m³/h",
"23.0m³/h",
"65.0m³/h",
"70.0m³/h",
"78.0m³/h",
"9.0m³/h",
"94.0m³/h"
],
"kilnPressure": "99.0Pa",
"fireDirection": "东火"
},
"type": "RunData"
}左右投料机信息{"rightFeeder":"运行","leftFeeder":"运行"}
天然气流量历史趋势
{
"kilnGasT1": {
"FE111R": [
53.02,
69.84,
99.33,
17.21,
1.17,
27.84,
95.44,
30.72,
32.24,
64.16,
59.65,
14.59,
78.58,
99.15,
58.91,
34.13,
99.62,
2.23,
28.31,
91.17,
97.15,
60.62,
94.12,
23.24
],
"FE113R": [
22.04,
40.78,
75.62,
61.01,
72.7,
48.46,
32.44,
42.51,
59.61,
22.86,
32.95,
21.32,
23.59,
84.16,
55.14,
55.71,
10.81,
56.53,
75.51,
2.85,
27.77,
52.42,
43.34,
22.04
],
"FE112R": [
77.02,
13.83,
1.71,
53.99,
4.03,
1,
22.17,
61.73,
11.25,
31.69,
90.31,
69.26,
68.72,
80.79,
3.08,
39.17,
12.6,
35.31,
97.2,
38.77,
27.5,
11.78,
72.32,
23.13
],
"FE115R": [
28.31,
10.16,
13.22,
41.44,
97.19,
60.08,
34.13,
16.75,
92.7,
79.48,
3.08,
14.71,
4.4,
0.88,
77.6,
57,
31,
86.14,
44.31,
45.7,
6.85,
65.62,
77.97,
49.2
],
"FE114R": [
17.72,
32.45,
1.42,
24.51,
68.57,
61.48,
2.08,
3.1,
38.27,
20.07,
25.71,
85.58,
48.31,
78.14,
22.43,
87.47,
83.78,
17.66,
72.36,
19,
20.69,
33.92,
25.66,
91.28
],
"FE117R": [
47.8,
62.27,
90.23,
28.31,
73.09,
34.04,
9.03,
44.69,
32.62,
25.78,
27.79,
25.42,
28.96,
56.52,
75.43,
50.56,
90.22,
11.85,
4.56,
39.9,
9.83,
65.98,
91.22,
92.43
],
"FE116R": [
64.79,
46.14,
58.67,
54.46,
15.67,
72.02,
15.06,
5.88,
38.19,
66.98,
89.24,
33.13,
87.57,
43.95,
55.06,
93.26,
96.91,
56.5,
20.75,
83.76,
60.88,
62.04,
22.34,
82.43
],
"FE118R": [
94.32,
86.26,
5.13,
47.33,
40.01,
34.97,
18.69,
81.81,
87.37,
96.47,
16.04,
23.33,
0.66,
16.86,
13.19,
67.32,
37.63,
13.74,
22.85,
78.89,
9.52,
75.46,
0.2,
1.51
]
},
"kilnGasT2": {
"FE124R": [
53.02,
69.84,
99.33,
17.21,
1.17,
27.84,
95.44,
30.72,
32.24,
64.16,
59.65,
14.59,
78.58,
99.15,
58.91,
34.13,
99.62,
2.23,
28.31,
91.17,
97.15,
60.62,
94.12,
23.24
],
"FE123aR": [
17.72,
32.45,
1.42,
24.51,
68.57,
61.48,
2.08,
3.1,
38.27,
20.07,
25.71,
85.58,
48.31,
78.14,
22.43,
87.47,
83.78,
17.66,
72.36,
19,
20.69,
33.92,
25.66,
91.28
],
"FE123R": [
77.02,
13.83,
1.71,
53.99,
4.03,
1,
22.17,
61.73,
11.25,
31.69,
90.31,
69.26,
68.72,
80.79,
3.08,
39.17,
12.6,
35.31,
97.2,
38.77,
27.5,
11.78,
72.32,
23.13
],
"FE124aR": [
22.04,
40.78,
75.62,
61.01,
72.7,
48.46,
32.44,
42.51,
59.61,
22.86,
32.95,
21.32,
23.59,
84.16,
55.14,
55.71,
10.81,
56.53,
75.51,
2.85,
27.77,
52.42,
43.34,
22.04
],
"FE126R": [
64.79,
46.14,
58.67,
54.46,
15.67,
72.02,
15.06,
5.88,
38.19,
66.98,
89.24,
33.13,
87.57,
43.95,
55.06,
93.26,
96.91,
56.5,
20.75,
83.76,
60.88,
62.04,
22.34,
82.43
],
"FE125aR": [
47.8,
62.27,
90.23,
28.31,
73.09,
34.04,
9.03,
44.69,
32.62,
25.78,
27.79,
25.42,
28.96,
56.52,
75.43,
50.56,
90.22,
11.85,
4.56,
39.9,
9.83,
65.98,
91.22,
92.43
],
"FE125R": [
28.31,
10.16,
13.22,
41.44,
97.19,
60.08,
34.13,
16.75,
92.7,
79.48,
3.08,
14.71,
4.4,
0.88,
77.6,
57,
31,
86.14,
44.31,
45.7,
6.85,
65.62,
77.97,
49.2
],
"FE126aR": [
94.32,
86.26,
5.13,
47.33,
40.01,
34.97,
18.69,
81.81,
87.37,
96.47,
16.04,
23.33,
0.66,
16.86,
13.19,
67.32,
37.63,
13.74,
22.85,
78.89,
9.52,
75.46,
0.2,
1.51
]
}
}

856
websocket/demo.json Normal file
View File

@ -0,0 +1,856 @@
{
"baseInfo": {
"fireChangeTime": "20分钟",
"waterInTemp": "75.0",
"lastFireChangeTime": "10分15秒",
"kilnPressure": "94.0",
"fireDirection": "南火",
"waterOutTemp": "26.0"
},
"fan": [
["8#压延冷却风机", "4373Hz", "正常"],
["7#压延冷却风机", "4772Hz", "正常"],
["6#压延冷却风机", "1704Hz", "正常"],
["5#压延冷却风机", "3109Hz", "正常"],
["4#压延冷却风机", "2595Hz", "正常"],
["3#压延冷却风机", "8903Hz", "正常"],
["2#压延冷却风机", "3741Hz", "正常"],
["1#压延冷却风机", "9035Hz", "正常"],
["4#熔化部风机", "5223Hz", "正常"],
["3#熔化部风机", "9722Hz", "正常"],
["2#熔化部风机", "9617Hz", "正常"],
["1#熔化部风机", "7135Hz", "正常"],
["4#澄清部风机", "1699Hz", "正常"],
["3#澄清部风机", "2511Hz", "正常"],
["2#澄清部风机", "9780Hz", "正常"],
["1#澄清部风机", "3809Hz", "正常"],
["2#助燃风机", "435Hz", "正常"],
["1#助燃风机", "6270Hz", "正常"],
["2#L吊墙风机", "8181Hz", "正常"],
["1#L吊墙风机", "5587Hz", "正常"],
["2#钢碹碴池壁风机", "6652Hz", "正常"],
["1#钢碹碴池壁风机", "2000Hz", "正常"],
["2#池壁拐角风机", "1972Hz", "正常"],
["1#池壁拐角风机", "7730Hz", "正常"]
],
"gas": {
"kilnGasT1": {
"FE111R": [
53.02,
69.84,
99.33,
17.21,
1.17,
27.84,
95.44,
30.72,
32.24,
64.16,
59.65,
14.59,
78.58,
99.15,
58.91,
34.13,
99.62,
2.23,
28.31,
91.17,
97.15,
60.62,
94.12,
23.24
],
"FE113R": [
22.04,
40.78,
75.62,
61.01,
72.7,
48.46,
32.44,
42.51,
59.61,
22.86,
32.95,
21.32,
23.59,
84.16,
55.14,
55.71,
10.81,
56.53,
75.51,
2.85,
27.77,
52.42,
43.34,
22.04
],
"FE112R": [
77.02,
13.83,
1.71,
53.99,
4.03,
1,
22.17,
61.73,
11.25,
31.69,
90.31,
69.26,
68.72,
80.79,
3.08,
39.17,
12.6,
35.31,
97.2,
38.77,
27.5,
11.78,
72.32,
23.13
],
"FE115R": [
28.31,
10.16,
13.22,
41.44,
97.19,
60.08,
34.13,
16.75,
92.7,
79.48,
3.08,
14.71,
4.4,
0.88,
77.6,
57,
31,
86.14,
44.31,
45.7,
6.85,
65.62,
77.97,
49.2
],
"FE114R": [
17.72,
32.45,
1.42,
24.51,
68.57,
61.48,
2.08,
3.1,
38.27,
20.07,
25.71,
85.58,
48.31,
78.14,
22.43,
87.47,
83.78,
17.66,
72.36,
19,
20.69,
33.92,
25.66,
91.28
],
"FE117R": [
47.8,
62.27,
90.23,
28.31,
73.09,
34.04,
9.03,
44.69,
32.62,
25.78,
27.79,
25.42,
28.96,
56.52,
75.43,
50.56,
90.22,
11.85,
4.56,
39.9,
9.83,
65.98,
91.22,
92.43
],
"FE116R": [
64.79,
46.14,
58.67,
54.46,
15.67,
72.02,
15.06,
5.88,
38.19,
66.98,
89.24,
33.13,
87.57,
43.95,
55.06,
93.26,
96.91,
56.5,
20.75,
83.76,
60.88,
62.04,
22.34,
82.43
],
"FE118R": [
94.32,
86.26,
5.13,
47.33,
40.01,
34.97,
18.69,
81.81,
87.37,
96.47,
16.04,
23.33,
0.66,
16.86,
13.19,
67.32,
37.63,
13.74,
22.85,
78.89,
9.52,
75.46,
0.2,
1.51
]
},
"kilnGasT2": {
"FE124R": [
53.02,
69.84,
99.33,
17.21,
1.17,
27.84,
95.44,
30.72,
32.24,
64.16,
59.65,
14.59,
78.58,
99.15,
58.91,
34.13,
99.62,
2.23,
28.31,
91.17,
97.15,
60.62,
94.12,
23.24
],
"FE123aR": [
17.72,
32.45,
1.42,
24.51,
68.57,
61.48,
2.08,
3.1,
38.27,
20.07,
25.71,
85.58,
48.31,
78.14,
22.43,
87.47,
83.78,
17.66,
72.36,
19,
20.69,
33.92,
25.66,
91.28
],
"FE123R": [
77.02,
13.83,
1.71,
53.99,
4.03,
1,
22.17,
61.73,
11.25,
31.69,
90.31,
69.26,
68.72,
80.79,
3.08,
39.17,
12.6,
35.31,
97.2,
38.77,
27.5,
11.78,
72.32,
23.13
],
"FE124aR": [
22.04,
40.78,
75.62,
61.01,
72.7,
48.46,
32.44,
42.51,
59.61,
22.86,
32.95,
21.32,
23.59,
84.16,
55.14,
55.71,
10.81,
56.53,
75.51,
2.85,
27.77,
52.42,
43.34,
22.04
],
"FE126R": [
64.79,
46.14,
58.67,
54.46,
15.67,
72.02,
15.06,
5.88,
38.19,
66.98,
89.24,
33.13,
87.57,
43.95,
55.06,
93.26,
96.91,
56.5,
20.75,
83.76,
60.88,
62.04,
22.34,
82.43
],
"FE125aR": [
47.8,
62.27,
90.23,
28.31,
73.09,
34.04,
9.03,
44.69,
32.62,
25.78,
27.79,
25.42,
28.96,
56.52,
75.43,
50.56,
90.22,
11.85,
4.56,
39.9,
9.83,
65.98,
91.22,
92.43
],
"FE125R": [
28.31,
10.16,
13.22,
41.44,
97.19,
60.08,
34.13,
16.75,
92.7,
79.48,
3.08,
14.71,
4.4,
0.88,
77.6,
57,
31,
86.14,
44.31,
45.7,
6.85,
65.62,
77.97,
49.2
],
"FE126aR": [
94.32,
86.26,
5.13,
47.33,
40.01,
34.97,
18.69,
81.81,
87.37,
96.47,
16.04,
23.33,
0.66,
16.86,
13.19,
67.32,
37.63,
13.74,
22.85,
78.89,
9.52,
75.46,
0.2,
1.51
]
}
},
"kilnBottom": {
"kilnTempBottomT1": {
"TE316": [
44,
49,
20,
29,
96,
76,
20,
82,
28,
86,
69,
18,
23,
58,
83,
84,
94,
99,
36,
51,
32
],
"TE315": [
84,
61,
87,
82,
33,
9,
20,
23,
81,
0,
16,
81,
9,
78,
30,
16,
49,
16,
95,
53,
19
],
"TE314": [
45,
93,
11,
47,
27,
69,
91,
17,
0,
67,
60,
15,
84,
36,
89,
30,
36,
90,
38,
94,
87
],
"TE313": [
60,
9,
59,
15,
43,
41,
83,
93,
99,
91,
29,
47,
2,
40,
65,
39,
12,
20,
57,
64,
95
],
"TE312": [
22,
46,
93,
69,
44,
3,
62,
49,
4,
18,
87,
76,
36,
16,
50,
36,
54,
90,
1,
66,
68
]
},
"kilnTempBottomT2": {
"TE319": [
48,
56,
40,
44,
31,
82,
35,
36,
0,
84,
49,
38,
28,
34,
98,
60,
4,
69,
15,
86,
19
],
"TE318": [
7,
30,
57,
78,
47,
99,
1,
98,
47,
86,
55,
10,
98,
27,
97,
85,
54,
41,
27,
85,
44
],
"TE317": [
72,
13,
7,
69,
77,
36,
6,
34,
97,
48,
75,
29,
75,
4,
70,
80,
31,
10,
39,
86,
52
],
"TE321": [
6,
60,
32,
19,
79,
99,
98,
81,
82,
68,
3,
94,
7,
29,
48,
52,
36,
59,
28,
77,
17
],
"TE320": [
23,
47,
4,
15,
7,
74,
75,
60,
78,
89,
15,
95,
74,
85,
20,
48,
79,
51,
63,
82,
68
]
}
},
"kilnTop": {
"kilnTempTopT2": {
"TE215": [
81,
12,
86,
55,
50,
59,
20,
67,
66,
29,
17,
74,
11,
12,
63,
23,
34,
86,
9,
38,
99,
3,
33,
77
],
"TE214": [
51,
12,
49,
60,
3,
67,
95,
62,
22,
89,
69,
14,
41,
79,
77,
27,
26,
34,
69,
44,
89,
86,
92,
1
],
"TE213": [
76,
14,
35,
1,
36,
67,
40,
5,
53,
98,
46,
29,
71,
12,
43,
42,
53,
56,
9,
17,
34,
42,
82,
73
]
},
"kilnTempTopT1": {
"TE209": [
51,
12,
49,
60,
3,
67,
95,
62,
22,
89,
69,
14,
41,
79,
77,
27,
26,
34,
69,
44,
89,
86,
92,
1
],
"TE208": [
76,
14,
35,
1,
36,
67,
40,
5,
53,
98,
46,
29,
71,
12,
43,
42,
53,
56,
9,
17,
34,
42,
82,
73
],
"TE210": [
81,
12,
86,
55,
50,
59,
20,
67,
66,
29,
17,
74,
11,
12,
63,
23,
34,
86,
9,
38,
99,
3,
33,
77
]
}
}
}

67
websocket/server.ts Normal file
View File

@ -0,0 +1,67 @@
import { WebSocket, WebSocketServer } from 'ws';
import demoData from './demo.json';
const wss = new WebSocketServer({ port: 9800 });
const frequency = 3; // seconds
wss.on('connection', function (ws, req) {
// console.log("ws", ws);
console.log(
'Client in: ',
req.socket.remoteAddress,
'current users:',
wss.clients.size,
);
// ws.on("error", console.error);
// ws.emit("message", "connected");
ws.on('open', function () {
console.log('connected');
ws.send('connected');
});
ws.on('message', function (msg) {
console.log('message from client', msg);
ws.send('echo ' + msg.toString());
});
ws.on('error', console.error);
const timer = setInterval(() => {
sendMsg(ws, 'base-info');
sendMsg(ws, 'fan');
sendMsg(ws, 'gas');
sendMsg(ws, 'kiln-top');
sendMsg(ws, 'kiln-bottom');
}, frequency * 1000);
ws.on('close', function () {
console.log('停止监听');
clearInterval(timer);
});
});
type MsgType = 'base-info' | 'fan' | 'gas' | 'kiln-top' | 'kiln-bottom';
function sendMsg(ws: WebSocket, type: MsgType) {
let data: any;
switch (type) {
case 'base-info':
data = demoData.baseInfo;
break;
case 'fan':
data = demoData.fan;
break;
case 'gas':
data = demoData.gas;
break;
case 'kiln-top':
data = demoData.kilnTop;
break;
case 'kiln-bottom':
data = demoData.kilnBottom;
break;
default:
data = 'You are connected!';
break;
}
// console.log("sendMsg: ", ws);
// ws.emit("message", JSON.stringify(data));
ws.send(JSON.stringify(data));
}

109
websocket/tsconfig.json Normal file
View File

@ -0,0 +1,109 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "commonjs" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
"resolveJsonModule": true /* Enable importing .json files. */,
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}