From 9f7652d9f3eea06e86c38b6621c6668998ae2e32 Mon Sep 17 00:00:00 2001 From: lb Date: Fri, 19 Apr 2024 16:55:10 +0800 Subject: [PATCH] update ts->js --- .gitignore | 2 +- package.json | 1 + .../NatGasFlow/gasChart/chart.config.js | 1 - .../Common/TodayFaultType/index.jsx | 1 - src/utils/{IS.ts => IS.js} | 5 +- src/utils/checkTypeHelper.ts | 26 ---- src/utils/{cutting.ts => cutting.js} | 20 +-- src/utils/{dcs.ts => dcs.js} | 6 +- src/utils/{energe.ts => energe.js} | 4 +- src/utils/energeChartOption.js | 4 - src/utils/{index.ts => index.js} | 28 ++--- src/utils/index.types.ts | 4 - src/utils/smoke.js | 32 +++++ src/utils/smoke.ts | 114 ------------------ 14 files changed, 53 insertions(+), 195 deletions(-) rename src/utils/{IS.ts => IS.js} (89%) delete mode 100644 src/utils/checkTypeHelper.ts rename src/utils/{cutting.ts => cutting.js} (55%) rename src/utils/{dcs.ts => dcs.js} (95%) rename src/utils/{energe.ts => energe.js} (84%) rename src/utils/{index.ts => index.js} (90%) delete mode 100644 src/utils/index.types.ts create mode 100644 src/utils/smoke.js delete mode 100644 src/utils/smoke.ts diff --git a/.gitignore b/.gitignore index 4d29575..cc534c3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies -/node_modules +**/node_modules /.pnp .pnp.js diff --git a/package.json b/package.json index 6fffba9..e141282 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "scripts": { "start": "node scripts/start.js", "build": "node scripts/build.js", + "server": "node websocket/server.js", "test": "node scripts/test.js" }, "eslintConfig": { diff --git a/src/components/Common/NatGasFlow/gasChart/chart.config.js b/src/components/Common/NatGasFlow/gasChart/chart.config.js index afc443c..e6cd815 100644 --- a/src/components/Common/NatGasFlow/gasChart/chart.config.js +++ b/src/components/Common/NatGasFlow/gasChart/chart.config.js @@ -1,5 +1,4 @@ import * as echarts from "echarts"; -import { randomInt } from "../../../../utils"; export default function getOptions(seriesData, name) { const colors = [ diff --git a/src/components/Common/TodayFaultType/index.jsx b/src/components/Common/TodayFaultType/index.jsx index b8e2cd0..f319210 100644 --- a/src/components/Common/TodayFaultType/index.jsx +++ b/src/components/Common/TodayFaultType/index.jsx @@ -3,7 +3,6 @@ import GraphBase from "../GraphBase"; import ReactECharts from "echarts-for-react"; import { useSelector } from "react-redux"; import { useEffect, useState } from "react"; -import { randomInt } from "../../../utils"; import * as echarts from "echarts"; function FaultType(props) { diff --git a/src/utils/IS.ts b/src/utils/IS.js similarity index 89% rename from src/utils/IS.ts rename to src/utils/IS.js index 45844c4..97aaa23 100644 --- a/src/utils/IS.ts +++ b/src/utils/IS.js @@ -1,8 +1,7 @@ import { store } from "../store"; -import { MessageItem } from "./checkTypeHelper"; -export default function handler(msg: MessageEvent) { - let serializedData: MessageItem | null = null; +export default function handler(msg) { + let serializedData = null; try { serializedData = JSON.parse(msg.data); } catch (error) { diff --git a/src/utils/checkTypeHelper.ts b/src/utils/checkTypeHelper.ts deleted file mode 100644 index dfdf158..0000000 --- a/src/utils/checkTypeHelper.ts +++ /dev/null @@ -1,26 +0,0 @@ -type CheckTypeItem = { - checkDiscard?: boolean; - checkType: string; - checkNum: number; - ip?: string; - israDefectType?: string; - israSeriousGrade?: string; -}; - -type ProductLineItem = { - name: string; - sum: number; - data: CheckTypeItem[]; -}; - -export type MessageItem = { - type: string; - name: string; - detData: { - checkType: string[]; - dayStatistic?: ProductLineItem[]; - weekStatistic?: ProductLineItem[]; - monthStatistic?: ProductLineItem[]; - yearStatistic?: ProductLineItem[]; - }; -}; diff --git a/src/utils/cutting.ts b/src/utils/cutting.js similarity index 55% rename from src/utils/cutting.ts rename to src/utils/cutting.js index 6db47d5..a4931d1 100644 --- a/src/utils/cutting.ts +++ b/src/utils/cutting.js @@ -1,30 +1,14 @@ import { store } from "../store"; -type TableDataType = { - name: "table"; - type: "cutting"; - data: any[]; -}; -type ChartDataType = { - name: "chart"; - type: "cutting"; - nightPushData: any[]; - dayPushData: any[]; - allPushData: any[]; - dateType: "day" | "week" | "month" | "year"; -}; -export default function handler(msg: MessageEvent) { - let serializedData: TableDataType | ChartDataType | null = null; +export default function handler(msg) { + let serializedData = null; try { serializedData = JSON.parse(msg.data); } catch (error) { console.log("[*] websocket: [unable to serialize] ---> ", msg); } - console.log("[CUTTING DATA] ---> ", serializedData); - if (serializedData == null) return; - switch (serializedData.name) { case "table": store.dispatch({ diff --git a/src/utils/dcs.ts b/src/utils/dcs.js similarity index 95% rename from src/utils/dcs.ts rename to src/utils/dcs.js index 5c8459a..892fd5d 100644 --- a/src/utils/dcs.ts +++ b/src/utils/dcs.js @@ -1,8 +1,8 @@ import { store } from "../store"; import { setList } from "../store/features/alarmSlice"; -export default function handler(msg: MessageEvent) { - let serializedData: { type: string; data: any } | null = null; +export default function handler(msg) { + let serializedData = null; try { serializedData = JSON.parse(msg.data); } catch (error) { @@ -10,7 +10,7 @@ export default function handler(msg: MessageEvent) { } switch (serializedData?.type) { case "alarmList": { - store.dispatch(setList(serializedData.data)) + store.dispatch(setList(serializedData.data)); break; } case "KilnInfo": { diff --git a/src/utils/energe.ts b/src/utils/energe.js similarity index 84% rename from src/utils/energe.ts rename to src/utils/energe.js index e7fa54a..7b5d9ed 100644 --- a/src/utils/energe.ts +++ b/src/utils/energe.js @@ -1,7 +1,7 @@ import { store } from "../store"; -export default function handler(msg: MessageEvent) { - let serializedData: { type: string; data: any } | null = null; +export default function handler(msg) { + let serializedData = null; try { serializedData = JSON.parse(msg.data); } catch (error) { diff --git a/src/utils/energeChartOption.js b/src/utils/energeChartOption.js index 4d72482..0fc635f 100644 --- a/src/utils/energeChartOption.js +++ b/src/utils/energeChartOption.js @@ -88,9 +88,6 @@ export function getOptions(period, source, trend, options = {}) { color: "#213259a0", }, }, - // interval: 10, - // min: 0, - // max: 100, }, series: [ { @@ -123,7 +120,6 @@ export function getOptions(period, source, trend, options = {}) { type: "shadow", }, className: "xc-chart-tooltip", - // backgroundColor: '' }, ...options, }; diff --git a/src/utils/index.ts b/src/utils/index.js similarity index 90% rename from src/utils/index.ts rename to src/utils/index.js index c322f7b..d81aba8 100644 --- a/src/utils/index.ts +++ b/src/utils/index.js @@ -9,24 +9,16 @@ import smokeHandler from "./smoke"; * new XClient('ws://192.168.1.12:8081/xc-screen/websocket/xc001', 'DCS') */ class XClient { - url: string; - name: string; - ws: WebSocket; - timeout: number = 1000 * 5; - heartbeatDelay: number = 1000 * 60 * 3; - reconnectCount: number = 0; - onmessage: (msg: MessageEvent) => void; - hb: number = 0; + // url; + // name; + // ws; + // timeout = 1000 * 5; + // heartbeatDelay = 1000 * 60 * 3; + // reconnectCount = 0; + // onmessage = (msg) => console.log(msg); + // hb = 0; - constructor( - config: { - url: string; - name: string; - timeout?: number; - reconnectCount?: number; - }, - onmessage: (msg: MessageEvent) => void - ) { + constructor(config, onmessage = (msg) => console.log(msg)) { this.url = config.url; this.name = config.name; this.ws = new WebSocket(config.url); @@ -164,7 +156,7 @@ new XClient( smokeHandler ); -export function randomInt(min: number, max: number, includeMax = false) { +export function randomInt(min, max, includeMax = false) { let Fn = includeMax ? Math.ceil : Math.floor; let num = Fn(Math.random() * max); while (num < min) { diff --git a/src/utils/index.types.ts b/src/utils/index.types.ts deleted file mode 100644 index 482fff1..0000000 --- a/src/utils/index.types.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type MessageEvent = { - type: string; - data: any; -} \ No newline at end of file diff --git a/src/utils/smoke.js b/src/utils/smoke.js new file mode 100644 index 0000000..d222d4c --- /dev/null +++ b/src/utils/smoke.js @@ -0,0 +1,32 @@ +import { store } from "../store"; + +export default function handler(msg) { + let serializedData = null; + try { + serializedData = JSON.parse(msg.data); + } catch (error) { + console.log("[*] websocket: [unable to serialize] ---> ", msg); + } + switch (serializedData?.type) { + case "exhaustGas": { + store.dispatch({ + type: "smoke/setInfo", + payload: serializedData.realtime, + }); + store.dispatch({ + type: "smoke/setTrend", + payload: { + dayTrend: serializedData.dayTrend, + weekTrend: serializedData.weekTrend, + monthTrend: serializedData.monthTrend, + yearTrend: serializedData.yearTrend, + }, + }); + break; + } + + default: { + console.log("websocket message: [unknown] ---> ", msg.data); + } + } +} diff --git a/src/utils/smoke.ts b/src/utils/smoke.ts deleted file mode 100644 index 5c1c3ca..0000000 --- a/src/utils/smoke.ts +++ /dev/null @@ -1,114 +0,0 @@ -import { store } from "../store"; - -type SmokeMessageItem = { - type: string; - realtime: { - SO2_float: number; - NOX_float: number; - O2_float: number; - dust_float: number; - }; - dayTrend: { - SO2_float: Array<{ - time: string; - value: number; - }>; - NOX_float: Array<{ - time: string; - value: number; - }>; - O2_float: Array<{ - time: string; - value: number; - }>; - dust_float: Array<{ - time: string; - value: number; - }>; - }; - weekTrend: { - SO2_float: Array<{ - time: string; - value: number; - }>; - NOX_float: Array<{ - time: string; - value: number; - }>; - O2_float: Array<{ - time: string; - value: number; - }>; - dust_float: Array<{ - time: string; - value: number; - }>; - }; - monthTrend: { - SO2_float: Array<{ - time: string; - value: number; - }>; - NOX_float: Array<{ - time: string; - value: number; - }>; - O2_float: Array<{ - time: string; - value: number; - }>; - dust_float: Array<{ - time: string; - value: number; - }>; - }; - yearTrend: { - SO2_float: Array<{ - time: string; - value: number; - }>; - NOX_float: Array<{ - time: string; - value: number; - }>; - O2_float: Array<{ - time: string; - value: number; - }>; - dust_float: Array<{ - time: string; - value: number; - }>; - }; -}; - -export default function handler(msg: MessageEvent) { - let serializedData: SmokeMessageItem | null = null; - try { - serializedData = JSON.parse(msg.data); - } catch (error) { - console.log("[*] websocket: [unable to serialize] ---> ", msg); - } - switch (serializedData?.type) { - case "exhaustGas": { - store.dispatch({ - type: "smoke/setInfo", - payload: serializedData.realtime, - }); - store.dispatch({ - type: "smoke/setTrend", - payload: { - dayTrend: serializedData.dayTrend, - weekTrend: serializedData.weekTrend, - monthTrend: serializedData.monthTrend, - yearTrend: serializedData.yearTrend, - }, - }); - break; - } - - default: { - console.log("websocket message: [unknown] ---> ", msg.data); - } - } -}