update ts->js

This commit is contained in:
lb 2024-04-19 16:55:10 +08:00
parent e854b966dc
commit 9f7652d9f3
14 changed files with 53 additions and 195 deletions

2
.gitignore vendored
View File

@ -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

View File

@ -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": {

View File

@ -1,5 +1,4 @@
import * as echarts from "echarts";
import { randomInt } from "../../../../utils";
export default function getOptions(seriesData, name) {
const colors = [

View File

@ -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) {

View File

@ -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) {

View File

@ -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[];
};
};

View File

@ -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({

View File

@ -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": {

View File

@ -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) {

View File

@ -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,
};

View File

@ -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) {

View File

@ -1,4 +0,0 @@
export type MessageEvent = {
type: string;
data: any;
}

32
src/utils/smoke.js Normal file
View File

@ -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);
}
}
}

View File

@ -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);
}
}
}