From 40791bc619427c4528da2d99730f8ea434ef1bfe Mon Sep 17 00:00:00 2001 From: juzi <819872918@qq.com> Date: Thu, 6 Mar 2025 08:27:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=93=BE=E6=8E=A5=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E6=94=B9=E6=88=90=E5=9C=A8=E6=AF=8F=E4=B8=AA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/babylonjs/AllLinePageBabylon.tsx | 4 +- src/babylonjs/LinePageBabylonNew.tsx | 29 +- .../Component/LineChartRight/chart.config.ts | 2 +- src/page/Component/ScrollBoard/index.tsx | 1 - src/page/ErrorPage.tsx | 2 - src/page/LDPage/Left/LeftDown.tsx | 1 - src/page/LinePage1-1/Center/CenterDown.tsx | 24 +- src/page/LinePage1-1/Left/LeftDown.tsx | 6 +- src/page/LinePage1-1/Left/LeftUp.tsx | 12 +- src/page/LinePage1-1/Right/RightDown.tsx | 6 +- src/page/LinePage1-1/Right/RightUp.tsx | 2 +- src/page/LinePage1-1/index.tsx | 24 ++ src/page/LinePage1-2/Center/CenterDown.tsx | 24 +- src/page/LinePage1-2/Left/LeftDown.tsx | 6 +- src/page/LinePage1-2/Left/LeftUp.tsx | 12 +- src/page/LinePage1-2/Right/RightDown.tsx | 6 +- src/page/LinePage1-2/Right/RightUp.tsx | 2 +- src/page/LinePage1-2/index.tsx | 24 ++ src/page/LinePage2-1/Center/CenterDown.tsx | 24 +- src/page/LinePage2-1/Left/LeftDown.tsx | 6 +- src/page/LinePage2-1/Left/LeftUp.tsx | 12 +- src/page/LinePage2-1/Right/RightDown.tsx | 6 +- src/page/LinePage2-1/Right/RightUp.tsx | 2 +- src/page/LinePage2-1/index.tsx | 24 ++ src/page/LinePage2-2/Center/CenterDown.tsx | 24 +- src/page/LinePage2-2/Left/LeftDown.tsx | 6 +- src/page/LinePage2-2/Left/LeftUp.tsx | 12 +- src/page/LinePage2-2/Right/RightDown.tsx | 6 +- src/page/LinePage2-2/Right/RightUp.tsx | 2 +- src/page/LinePage2-2/index.tsx | 24 ++ src/page/LinePage3-1/Center/CenterDown.tsx | 24 +- src/page/LinePage3-1/Left/LeftDown.tsx | 6 +- src/page/LinePage3-1/Left/LeftUp.tsx | 12 +- src/page/LinePage3-1/Right/RightDown.tsx | 6 +- src/page/LinePage3-1/Right/RightUp.tsx | 2 +- src/page/LinePage3-1/index.tsx | 24 ++ src/page/LinePage3-2/Center/CenterDown.tsx | 24 +- src/page/LinePage3-2/Left/LeftDown.tsx | 6 +- src/page/LinePage3-2/Left/LeftUp.tsx | 12 +- src/page/LinePage3-2/Right/RightDown.tsx | 6 +- src/page/LinePage3-2/Right/RightUp.tsx | 2 +- src/page/LinePage3-2/index.tsx | 24 ++ src/page/LinePage4-1/Center/CenterDown.tsx | 24 +- src/page/LinePage4-1/Left/LeftDown.tsx | 6 +- src/page/LinePage4-1/Left/LeftUp.tsx | 12 +- src/page/LinePage4-1/Right/RightDown.tsx | 6 +- src/page/LinePage4-1/Right/RightUp.tsx | 2 +- src/page/LinePage4-1/index.tsx | 24 ++ src/page/LinePage4-2/Center/CenterDown.tsx | 24 +- src/page/LinePage4-2/Left/LeftDown.tsx | 6 +- src/page/LinePage4-2/Left/LeftUp.tsx | 12 +- src/page/LinePage4-2/index.tsx | 24 ++ src/page/LinePage5-1/index.tsx | 24 ++ src/page/LinePage5-2/Center/CenterDown.tsx | 2 +- src/page/LinePage5-2/index.tsx | 24 ++ src/store/UpdateData.tsx | 376 +++++++++--------- 57 files changed, 657 insertions(+), 394 deletions(-) diff --git a/package.json b/package.json index fa97fa6..82cbadc 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ "workbox-webpack-plugin": "^6.4.1" }, "scripts": { - "start": "node scripts/start.js", + "start": "node --max-old-space-size=4096 scripts/start.js", "build": "node scripts/build.js", "test": "node scripts/test.js" }, diff --git a/src/babylonjs/AllLinePageBabylon.tsx b/src/babylonjs/AllLinePageBabylon.tsx index 3557fa3..3e0408d 100644 --- a/src/babylonjs/AllLinePageBabylon.tsx +++ b/src/babylonjs/AllLinePageBabylon.tsx @@ -185,7 +185,7 @@ function MybabylonJS({ modelPath }: MybabylonJSProps) { currentMeshesRef.current.push(...LOD0MESH2.meshes); // ...为新加载的模型设置交互逻辑 - LOD0MESH1.meshes.map((mesh) => { + LOD0MESH1.meshes.forEach((mesh) => { mesh.isPickable = true; mesh.actionManager = new BABYLON.ActionManager(scene); if (modelPath.slice(-1) === "1") { @@ -227,7 +227,7 @@ function MybabylonJS({ modelPath }: MybabylonJSProps) { setSelectedMeshId(MeshNameId); }; }); - LOD0MESH2.meshes.map((mesh) => { + LOD0MESH2.meshes.forEach((mesh) => { mesh.isPickable = true; mesh.actionManager = new BABYLON.ActionManager(scene); if (modelPath.slice(-1) === "1") { diff --git a/src/babylonjs/LinePageBabylonNew.tsx b/src/babylonjs/LinePageBabylonNew.tsx index ad8b429..9cfdd43 100644 --- a/src/babylonjs/LinePageBabylonNew.tsx +++ b/src/babylonjs/LinePageBabylonNew.tsx @@ -12,6 +12,15 @@ import AlarmTipGreen from "./../page/assets/icon/g.png"; import AlarmTipYellow from "./../page/assets/icon/y.png"; import AlarmTipRed from "./../page/assets/icon/r.png"; import {selectLine1Before} from "../store/LinePageSlice"; +import {selectLine1After} from "../store/LinePageSlice"; +import {selectLine2Before} from "../store/LinePageSlice"; +import {selectLine2After} from "../store/LinePageSlice"; +import {selectLine3Before} from "../store/LinePageSlice"; +import {selectLine3After} from "../store/LinePageSlice"; +import {selectLine4Before} from "../store/LinePageSlice"; +import {selectLine4After} from "../store/LinePageSlice"; +import {selectLine5Before} from "../store/LinePageSlice"; +import {selectLine5After} from "../store/LinePageSlice"; const lineNameNo = ["一","二","三","四","五"] const myStyle = { @@ -40,7 +49,6 @@ interface EqMsg { } function MybabylonJS({ modelPath }: MybabylonJSProps) { const [eqList, setEqList] = useState({}); - const allData = useAppSelector(selectLine1Before) as any; // 使用`any`来绕过类型检查 const canvasRef = useRef(null); const resetRef = useRef<(() => void) | null>(null); const [selectedMeshName, setSelectedMeshName] = useState(null); @@ -52,6 +60,23 @@ function MybabylonJS({ modelPath }: MybabylonJSProps) { }); const [showInfo, setShowInfo] = useState(true); + const selectorMap: Record any> = { + "Line1-1": selectLine1Before, + "Line1-2": selectLine1After, + "Line2-1": selectLine2Before, + "Line2-2": selectLine2After, + "Line3-1": selectLine3Before, + "Line3-2": selectLine3After, + "Line4-1": selectLine4Before, + "Line4-2": selectLine4After, + "Line5-1": selectLine5Before, + "Line5-2": selectLine5After + }; + const selectedSelector = selectorMap[modelPath]; + const allData = useAppSelector(selectedSelector); + // const allData = useAppSelector(selectLine1Before) as any; + + // 使用 useRef 来存储当前加载的模型引用 const currentMeshesRef = useRef>([]); useEffect(() => { @@ -183,7 +208,7 @@ function MybabylonJS({ modelPath }: MybabylonJSProps) { // ...为新加载的模型设置交互逻辑 - LOD0MESH.meshes.map((mesh) => { + LOD0MESH.meshes.forEach((mesh) => { mesh.isPickable = true; mesh.actionManager = new BABYLON.ActionManager(scene); if (modelPath.slice(-1) === "1") { diff --git a/src/page/Component/LineChartRight/chart.config.ts b/src/page/Component/LineChartRight/chart.config.ts index 7dc2840..7dd7a11 100644 --- a/src/page/Component/LineChartRight/chart.config.ts +++ b/src/page/Component/LineChartRight/chart.config.ts @@ -1,4 +1,4 @@ -import * as echarts from "echarts"; + export default function getOptions(tempData: any) { if (Object.keys(tempData).length === 0) { return null; diff --git a/src/page/Component/ScrollBoard/index.tsx b/src/page/Component/ScrollBoard/index.tsx index 703d20c..aa52e6f 100644 --- a/src/page/Component/ScrollBoard/index.tsx +++ b/src/page/Component/ScrollBoard/index.tsx @@ -5,7 +5,6 @@ import { deepClone } from "./util/utils"; import { co } from "./util"; import classnames from "classnames"; import "./index.css"; -import { current } from "@reduxjs/toolkit"; interface ScrollBoardProps { config?: object; onClick?: () => void; diff --git a/src/page/ErrorPage.tsx b/src/page/ErrorPage.tsx index b1f3d51..12b7551 100644 --- a/src/page/ErrorPage.tsx +++ b/src/page/ErrorPage.tsx @@ -1,6 +1,4 @@ -import React from "react"; import "./style/standard.css" -import intl from "react-intl-universal"; function ErrorPage() { diff --git a/src/page/LDPage/Left/LeftDown.tsx b/src/page/LDPage/Left/LeftDown.tsx index bc8dbf4..bf529b6 100644 --- a/src/page/LDPage/Left/LeftDown.tsx +++ b/src/page/LDPage/Left/LeftDown.tsx @@ -3,7 +3,6 @@ import TitleBox from "../Component/TitleBox"; import getOptions from "../../Component/BarLineChart/chart.config"; import {useAppSelector} from "./../../../store/hooks" import { selectAllLine } from "./../../../store/LeaderPageSlice"; -import { Fragment } from "react/jsx-runtime"; function LeftDown() { const data = useAppSelector(selectAllLine); interface Detail { diff --git a/src/page/LinePage1-1/Center/CenterDown.tsx b/src/page/LinePage1-1/Center/CenterDown.tsx index 23cbd13..71623fd 100644 --- a/src/page/LinePage1-1/Center/CenterDown.tsx +++ b/src/page/LinePage1-1/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage1-1/Left/LeftUp.tsx b/src/page/LinePage1-1/Left/LeftUp.tsx index 6db365c..b69229d 100644 --- a/src/page/LinePage1-1/Left/LeftUp.tsx +++ b/src/page/LinePage1-1/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage1-1/Right/RightDown.tsx b/src/page/LinePage1-1/Right/RightDown.tsx index 4a271c2..0d04cde 100644 --- a/src/page/LinePage1-1/Right/RightDown.tsx +++ b/src/page/LinePage1-1/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage1-1/Right/RightUp.tsx b/src/page/LinePage1-1/Right/RightUp.tsx index cf9de73..146b18e 100644 --- a/src/page/LinePage1-1/Right/RightUp.tsx +++ b/src/page/LinePage1-1/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage1-1/index.tsx b/src/page/LinePage1-1/index.tsx index e9f97a1..27907ae 100644 --- a/src/page/LinePage1-1/index.tsx +++ b/src/page/LinePage1-1/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine1Before } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket1_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-1-" + Date.now()); + // @ts-ignore + websocket1_1.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine1Before(msgData)); + } + // 清理函数 + return () => { + websocket1_1.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage1-2/Center/CenterDown.tsx b/src/page/LinePage1-2/Center/CenterDown.tsx index 096ed9a..eadc48f 100644 --- a/src/page/LinePage1-2/Center/CenterDown.tsx +++ b/src/page/LinePage1-2/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage1-2/Left/LeftUp.tsx b/src/page/LinePage1-2/Left/LeftUp.tsx index 52bec78..aeb4eb8 100644 --- a/src/page/LinePage1-2/Left/LeftUp.tsx +++ b/src/page/LinePage1-2/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage1-2/Right/RightDown.tsx b/src/page/LinePage1-2/Right/RightDown.tsx index 7077534..a5e0a7b 100644 --- a/src/page/LinePage1-2/Right/RightDown.tsx +++ b/src/page/LinePage1-2/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage1-2/Right/RightUp.tsx b/src/page/LinePage1-2/Right/RightUp.tsx index f8886e1..ccaf15f 100644 --- a/src/page/LinePage1-2/Right/RightUp.tsx +++ b/src/page/LinePage1-2/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage1-2/index.tsx b/src/page/LinePage1-2/index.tsx index 425a1d9..c01f689 100644 --- a/src/page/LinePage1-2/index.tsx +++ b/src/page/LinePage1-2/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine1After } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket1_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-2-" + Date.now()); + // @ts-ignore + websocket1_2.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine1After(msgData)); + } + // 清理函数 + return () => { + websocket1_2.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage2-1/Center/CenterDown.tsx b/src/page/LinePage2-1/Center/CenterDown.tsx index b1f2fa3..cb82b06 100644 --- a/src/page/LinePage2-1/Center/CenterDown.tsx +++ b/src/page/LinePage2-1/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage2-1/Left/LeftUp.tsx b/src/page/LinePage2-1/Left/LeftUp.tsx index cf25aac..e046b00 100644 --- a/src/page/LinePage2-1/Left/LeftUp.tsx +++ b/src/page/LinePage2-1/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage2-1/Right/RightDown.tsx b/src/page/LinePage2-1/Right/RightDown.tsx index 36c7bf7..a8f982c 100644 --- a/src/page/LinePage2-1/Right/RightDown.tsx +++ b/src/page/LinePage2-1/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage2-1/Right/RightUp.tsx b/src/page/LinePage2-1/Right/RightUp.tsx index 5db0782..537722e 100644 --- a/src/page/LinePage2-1/Right/RightUp.tsx +++ b/src/page/LinePage2-1/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage2-1/index.tsx b/src/page/LinePage2-1/index.tsx index bebcf33..09501ac 100644 --- a/src/page/LinePage2-1/index.tsx +++ b/src/page/LinePage2-1/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine2Before } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket2_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-1-" + Date.now()); + // @ts-ignore + websocket2_1.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine2Before(msgData)); + } + // 清理函数 + return () => { + websocket2_1.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage2-2/Center/CenterDown.tsx b/src/page/LinePage2-2/Center/CenterDown.tsx index 3d1242b..581b09b 100644 --- a/src/page/LinePage2-2/Center/CenterDown.tsx +++ b/src/page/LinePage2-2/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage2-2/Left/LeftUp.tsx b/src/page/LinePage2-2/Left/LeftUp.tsx index d812370..bc5aba0 100644 --- a/src/page/LinePage2-2/Left/LeftUp.tsx +++ b/src/page/LinePage2-2/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage2-2/Right/RightDown.tsx b/src/page/LinePage2-2/Right/RightDown.tsx index 3adfaca..d31b5f6 100644 --- a/src/page/LinePage2-2/Right/RightDown.tsx +++ b/src/page/LinePage2-2/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage2-2/Right/RightUp.tsx b/src/page/LinePage2-2/Right/RightUp.tsx index d8de53d..df41ac5 100644 --- a/src/page/LinePage2-2/Right/RightUp.tsx +++ b/src/page/LinePage2-2/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage2-2/index.tsx b/src/page/LinePage2-2/index.tsx index e3be42c..3a84ed4 100644 --- a/src/page/LinePage2-2/index.tsx +++ b/src/page/LinePage2-2/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine2After } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket2_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-2-" + Date.now()); + // @ts-ignore + websocket2_2.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine2After(msgData)); + } + // 清理函数 + return () => { + websocket2_2.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage3-1/Center/CenterDown.tsx b/src/page/LinePage3-1/Center/CenterDown.tsx index f5ed287..2472cc6 100644 --- a/src/page/LinePage3-1/Center/CenterDown.tsx +++ b/src/page/LinePage3-1/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage3-1/Left/LeftUp.tsx b/src/page/LinePage3-1/Left/LeftUp.tsx index ceafe41..1989462 100644 --- a/src/page/LinePage3-1/Left/LeftUp.tsx +++ b/src/page/LinePage3-1/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage3-1/Right/RightDown.tsx b/src/page/LinePage3-1/Right/RightDown.tsx index f6df6f2..f395a75 100644 --- a/src/page/LinePage3-1/Right/RightDown.tsx +++ b/src/page/LinePage3-1/Right/RightDown.tsx @@ -80,7 +80,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -96,7 +96,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -112,7 +112,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage3-1/Right/RightUp.tsx b/src/page/LinePage3-1/Right/RightUp.tsx index f3dde67..58f2179 100644 --- a/src/page/LinePage3-1/Right/RightUp.tsx +++ b/src/page/LinePage3-1/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage3-1/index.tsx b/src/page/LinePage3-1/index.tsx index b43ab75..4176e61 100644 --- a/src/page/LinePage3-1/index.tsx +++ b/src/page/LinePage3-1/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine3Before } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket3_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-1-" + Date.now()); + // @ts-ignore + websocket3_1.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine3Before(msgData)); + } + // 清理函数 + return () => { + websocket3_1.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage3-2/Center/CenterDown.tsx b/src/page/LinePage3-2/Center/CenterDown.tsx index 1386274..f9aed4a 100644 --- a/src/page/LinePage3-2/Center/CenterDown.tsx +++ b/src/page/LinePage3-2/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage3-2/Left/LeftUp.tsx b/src/page/LinePage3-2/Left/LeftUp.tsx index 21e8ec3..e01e947 100644 --- a/src/page/LinePage3-2/Left/LeftUp.tsx +++ b/src/page/LinePage3-2/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage3-2/Right/RightDown.tsx b/src/page/LinePage3-2/Right/RightDown.tsx index 4da95cc..babb2d6 100644 --- a/src/page/LinePage3-2/Right/RightDown.tsx +++ b/src/page/LinePage3-2/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage3-2/Right/RightUp.tsx b/src/page/LinePage3-2/Right/RightUp.tsx index 4e396fa..9b856a6 100644 --- a/src/page/LinePage3-2/Right/RightUp.tsx +++ b/src/page/LinePage3-2/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage3-2/index.tsx b/src/page/LinePage3-2/index.tsx index d2b2a02..d67114a 100644 --- a/src/page/LinePage3-2/index.tsx +++ b/src/page/LinePage3-2/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine3After } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket3_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-2-" + Date.now()); + // @ts-ignore + websocket3_2.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine3After(msgData)); + } + // 清理函数 + return () => { + websocket3_2.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage4-1/Center/CenterDown.tsx b/src/page/LinePage4-1/Center/CenterDown.tsx index 3b2ad1a..f3289fd 100644 --- a/src/page/LinePage4-1/Center/CenterDown.tsx +++ b/src/page/LinePage4-1/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage4-1/Left/LeftUp.tsx b/src/page/LinePage4-1/Left/LeftUp.tsx index 9af7d8a..a955462 100644 --- a/src/page/LinePage4-1/Left/LeftUp.tsx +++ b/src/page/LinePage4-1/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage4-1/Right/RightDown.tsx b/src/page/LinePage4-1/Right/RightDown.tsx index fc2edfe..92852d7 100644 --- a/src/page/LinePage4-1/Right/RightDown.tsx +++ b/src/page/LinePage4-1/Right/RightDown.tsx @@ -81,7 +81,7 @@ function RightDown() { // @ts-ignore if (data.todayProductionDets && data.todayProductionDets.length > 0) { // @ts-ignore - data.todayProductionDets.map((item,index)=>{ + data.todayProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("HH:mm"),item.inputNum,item.outputNum); arr1.push(arrInner); @@ -97,7 +97,7 @@ function RightDown() { // @ts-ignore if (data.weekProductionDets && data.weekProductionDets.length > 0) { // @ts-ignore - data.weekProductionDets.map((item,index)=>{ + data.weekProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr2.push(arrInner); @@ -113,7 +113,7 @@ function RightDown() { // @ts-ignore if (data.monthProductionDets && data.monthProductionDets.length > 0) { // @ts-ignore - data.monthProductionDets.map((item,index)=>{ + data.monthProductionDets.forEach((item,index)=>{ let arrInner = []; arrInner.push(dayjs(item.recTime).format("YYYY/MM/DD"),item.inputNum,item.outputNum); arr3.push(arrInner); diff --git a/src/page/LinePage4-1/Right/RightUp.tsx b/src/page/LinePage4-1/Right/RightUp.tsx index 49ce536..68ed2d9 100644 --- a/src/page/LinePage4-1/Right/RightUp.tsx +++ b/src/page/LinePage4-1/Right/RightUp.tsx @@ -19,7 +19,7 @@ function RightUp() { // @ts-ignore if (data.sectionDet && data.sectionDet.length > 0) { // @ts-ignore - data.sectionDet.map((item, index) => { + data.sectionDet.forEach((item, index) => { let arrInner = [] arrInner.push(index + 1, item.lineName, item.inputNum, item.outputNum) arr.push(arrInner) diff --git a/src/page/LinePage4-1/index.tsx b/src/page/LinePage4-1/index.tsx index e20e7f1..12eba4b 100644 --- a/src/page/LinePage4-1/index.tsx +++ b/src/page/LinePage4-1/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine4Before } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket4_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-1-" + Date.now()); + // @ts-ignore + websocket4_1.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine4Before(msgData)); + } + // 清理函数 + return () => { + websocket4_1.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage4-2/Center/CenterDown.tsx b/src/page/LinePage4-2/Center/CenterDown.tsx index 3cbd808..6586201 100644 --- a/src/page/LinePage4-2/Center/CenterDown.tsx +++ b/src/page/LinePage4-2/Center/CenterDown.tsx @@ -29,7 +29,7 @@ function CenterDown() { { name: "周", ename: "week" }, { name: "月", ename: "month" }, ]; - const [activeName, setActiveName] = useState(nameList[1].ename); + const [activeName] = useState(nameList[1].ename); // const handleButtonChange = (activeName: string) => { // setActiveName(activeName); // }; @@ -52,7 +52,7 @@ function CenterDown() { // @ts-ignore sumAlarm = data.alarms.length // @ts-ignore - data.alarms.map((item,index) => { + data.alarms.forEach((item,index) => { let arrInner = [] arrInner.push( index+1, @@ -70,11 +70,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.todayProductionRates) // @ts-ignore - data.todayProductionRates[keys[0]].map((item,index)=>{ + data.todayProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.day.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -85,7 +85,7 @@ function CenterDown() { // @ts-ignore obj.name = data.todayProductionRates[item][0].lineName // @ts-ignore - data.todayProductionRates[item].map((subItem,index)=>{ + data.todayProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -100,11 +100,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.weekProductionRates) // @ts-ignore - data.weekProductionRates[keys[0]].map((item,index)=>{ + data.weekProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.week.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -115,7 +115,7 @@ function CenterDown() { // @ts-ignore obj.name = data.weekProductionRates[item][0].lineName // @ts-ignore - data.weekProductionRates[item].map((subItem,index)=>{ + data.weekProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -130,11 +130,11 @@ function CenterDown() { // @ts-ignore let keys = Object.keys(data.monthProductionRates) // @ts-ignore - data.monthProductionRates[keys[0]].map((item,index)=>{ + data.monthProductionRates[keys[0]].forEach((item,index)=>{ // @ts-ignore dataSource.month.xData.push(dayjs(item.recTime).format("HH:mm")) }) - keys.map((item,index)=>{ + keys.forEach((item,index)=>{ let obj = { name: "", type: "line", @@ -145,7 +145,7 @@ function CenterDown() { // @ts-ignore obj.name = data.monthProductionRates[item][0].lineName // @ts-ignore - data.monthProductionRates[item].map((subItem,index)=>{ + data.monthProductionRates[item].forEach((subItem,index)=>{ // @ts-ignore obj.data.push(subItem.passRate) }) @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

0) { // @ts-ignore - data.todayProductionScraps.map((item,index)=>{ + data.todayProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr1.push(arrInner); @@ -90,7 +90,7 @@ function LeftDown() { // @ts-ignore if (data.weekProductionScraps && data.weekProductionScraps.length > 0) { // @ts-ignore - data.weekProductionScraps.map((item,index)=>{ + data.weekProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr2.push(arrInner); @@ -103,7 +103,7 @@ function LeftDown() { // @ts-ignore if (data.monthProductionScraps && data.monthProductionScraps.length > 0) { // @ts-ignore - data.monthProductionScraps.map((item,index)=>{ + data.monthProductionScraps.forEach((item,index)=>{ let arrInner = []; arrInner.push(index+1,item.sectionName,item.scrapNum || 0); arr3.push(arrInner); diff --git a/src/page/LinePage4-2/Left/LeftUp.tsx b/src/page/LinePage4-2/Left/LeftUp.tsx index 25f71c9..72dcc5f 100644 --- a/src/page/LinePage4-2/Left/LeftUp.tsx +++ b/src/page/LinePage4-2/Left/LeftUp.tsx @@ -37,7 +37,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -67,7 +67,7 @@ function LeftUp() { for(let i = 0;i < dataSource.day.series.length;i++){ let itemSeries = dataSource.day.series[i] // @ts-ignore - data.todayAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.todayAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -105,7 +105,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -135,7 +135,7 @@ function LeftUp() { for(let i = 0;i < dataSource.week.series.length;i++){ let itemSeries = dataSource.week.series[i] // @ts-ignore - data.weekAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.weekAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore @@ -173,7 +173,7 @@ function LeftUp() { let sum: number[] = []; // 生成obj // @ts-ignore - data.scrapBars.map((item,index) => { + data.scrapBars.forEach((item,index) => { let obj = { data: [], type: "bar", @@ -203,7 +203,7 @@ function LeftUp() { for(let i = 0;i < dataSource.month.series.length;i++){ let itemSeries = dataSource.month.series[i] // @ts-ignore - data.monthAllProductionScraps[item].map((itemInner,indexInner)=>{ + data.monthAllProductionScraps[item].forEach((itemInner,indexInner)=>{ // @ts-ignore if (itemInner.sectionName.indexOf(itemSeries.name)!==-1) { // @ts-ignore diff --git a/src/page/LinePage4-2/index.tsx b/src/page/LinePage4-2/index.tsx index 711294a..9482f2b 100644 --- a/src/page/LinePage4-2/index.tsx +++ b/src/page/LinePage4-2/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine4After } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket4_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-2-" + Date.now()); + // @ts-ignore + websocket4_2.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine4After(msgData)); + } + // 清理函数 + return () => { + websocket4_2.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage5-1/index.tsx b/src/page/LinePage5-1/index.tsx index 35689fb..e8a585e 100644 --- a/src/page/LinePage5-1/index.tsx +++ b/src/page/LinePage5-1/index.tsx @@ -5,7 +5,31 @@ import Right from "./Right"; import Center from "./Center"; import {useEffect} from 'react'; import {useNavigate} from "react-router-dom"; +import { useDispatch } from 'react-redux'; +import { UpdateLine5Before } from "../../store/LinePageSlice"; function LinePage() { + const dispatch = useDispatch(); + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; + useEffect(() => { + let websocket5_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-1-" + Date.now()); + // @ts-ignore + websocket5_1.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine5Before(msgData)); + } + // 清理函数 + return () => { + websocket5_1.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/page/LinePage5-2/Center/CenterDown.tsx b/src/page/LinePage5-2/Center/CenterDown.tsx index d235a27..1dc9d5c 100644 --- a/src/page/LinePage5-2/Center/CenterDown.tsx +++ b/src/page/LinePage5-2/Center/CenterDown.tsx @@ -192,7 +192,7 @@ function CenterDown() { {} )} - {chartData.xData.length==0 && ( + {chartData.xData.length===0 && (

{ + let websocket5_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-2-" + Date.now()); + // @ts-ignore + websocket5_2.onmessage = function (event) { + let msgData = event.data + try { + msgData = JSON.parse(event.data); + } catch (error) { + console.log("websocket: [unable to msgData] : ", event.data); + } + if (!Object.prototype.toString.call(msgData).includes('Object')) return; + dispatch(UpdateLine5After(msgData)); + } + // 清理函数 + return () => { + websocket5_2.close(); + }; + }, [dispatch]); + const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (event:any) => { diff --git a/src/store/UpdateData.tsx b/src/store/UpdateData.tsx index 93fb412..8d0d9dc 100644 --- a/src/store/UpdateData.tsx +++ b/src/store/UpdateData.tsx @@ -1,50 +1,52 @@ -import {useState} from "react"; +// import {useState} from "react"; import {useAppDispatch} from "./hooks"; -import axios from "axios"; +// import axios from "axios"; -import { - UpdateLine1Before, - UpdateLine1After, - UpdateLine2Before, - UpdateLine2After, - UpdateLine3Before, - UpdateLine3After, - UpdateLine4Before, - UpdateLine4After, - UpdateLine5Before, - UpdateLine5After -} from "./LinePageSlice" +// import { +// UpdateLine1Before, +// UpdateLine1After, +// UpdateLine2Before, +// UpdateLine2After, +// UpdateLine3Before, +// UpdateLine3After, +// UpdateLine4Before, +// UpdateLine4After, +// UpdateLine5Before, +// UpdateLine5After +// } from "./LinePageSlice" import { UpdateAllLine } from "./LeaderPageSlice" function UpdateData() { - const [myUrl, setUrl] = useState('') - axios.get('/wsconfig.json') - .then((r) => { - setUrl(r.data.url) - }) + // const [myUrl, setUrl] = useState('') + // axios.get('/wsconfig.json') + // .then((r) => { + // setUrl(r.data.url) + // }) + // const myUrl = "192.168.8.22" + const myUrl = window.location.host; let websocketAllLine = null; - let websocket1_1 = null; - let websocket1_2 = null; - let websocket2_1 = null; - let websocket2_2 = null; - let websocket3_1 = null; - let websocket3_2 = null; - let websocket4_1 = null; - let websocket4_2 = null; - let websocket5_1 = null; - let websocket5_2 = null; + // let websocket1_1 = null; + // let websocket1_2 = null; + // let websocket2_1 = null; + // let websocket2_2 = null; + // let websocket3_1 = null; + // let websocket3_2 = null; + // let websocket4_1 = null; + // let websocket4_2 = null; + // let websocket5_1 = null; + // let websocket5_2 = null; const dispatch = useAppDispatch(); if ('WebSocket' in window) { websocketAllLine = new WebSocket("ws://" + myUrl + "/websocket/message?userId=all"); - websocket1_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-1-" + Date.now()); - websocket1_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-2-" + Date.now()); - websocket2_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-1-" + Date.now()); - websocket2_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-2-" + Date.now()); - websocket3_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-1-" + Date.now()); - websocket3_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-2-" + Date.now()); - websocket4_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-1-" + Date.now()); - websocket4_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-2-" + Date.now()); - websocket5_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-1-" + Date.now()); - websocket5_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-2-" + Date.now()); + // websocket1_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-1-" + Date.now()); + // websocket1_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=1-2-" + Date.now()); + // websocket2_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-1-" + Date.now()); + // websocket2_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=2-2-" + Date.now()); + // websocket3_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-1-" + Date.now()); + // websocket3_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=3-2-" + Date.now()); + // websocket4_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-1-" + Date.now()); + // websocket4_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=4-2-" + Date.now()); + // websocket5_1 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-1-" + Date.now()); + // websocket5_2 = new WebSocket("ws://" + myUrl + "/websocket/message?userId=5-2-" + Date.now()); //连接成功建立的回调方法 } else { alert('Not support websocket'); @@ -53,46 +55,46 @@ function UpdateData() { websocketAllLine.onopen = function (event) { console.log("websocketAllLine-open"); } + // // @ts-ignore + // websocket1_1.onopen = function (event) { + // console.log("websocket1_1-open"); + // } // @ts-ignore - websocket1_1.onopen = function (event) { - console.log("websocket1_1-open"); - } - // @ts-ignore - websocket1_2.onopen = function (event) { - console.log("websocket1_2-open"); - } - // @ts-ignore - websocket2_1.onopen = function (event) { - console.log("websocket2_1-open"); - } - // @ts-ignore - websocket2_2.onopen = function (event) { - console.log("websocket2_2-open"); - } - // @ts-ignore - websocket3_1.onopen = function (event) { - console.log("websocket3_1-open"); - } - // @ts-ignore - websocket3_2.onopen = function (event) { - console.log("websocket3_2-open"); - } - // @ts-ignore - websocket4_1.onopen = function (event) { - console.log("websocket4_1-open"); - } - // @ts-ignore - websocket4_2.onopen = function (event) { - console.log("websocket4_2-open"); - } - // @ts-ignore - websocket5_1.onopen = function (event) { - console.log("websocket5_1-open"); - } - // @ts-ignore - websocket5_2.onopen = function (event) { - console.log("websocket5_2-open"); - } + // websocket1_2.onopen = function (event) { + // console.log("websocket1_2-open"); + // } + // // @ts-ignore + // websocket2_1.onopen = function (event) { + // console.log("websocket2_1-open"); + // } + // // @ts-ignore + // websocket2_2.onopen = function (event) { + // console.log("websocket2_2-open"); + // } + // // @ts-ignore + // websocket3_1.onopen = function (event) { + // console.log("websocket3_1-open"); + // } + // // @ts-ignore + // websocket3_2.onopen = function (event) { + // console.log("websocket3_2-open"); + // } + // // @ts-ignore + // websocket4_1.onopen = function (event) { + // console.log("websocket4_1-open"); + // } + // // @ts-ignore + // websocket4_2.onopen = function (event) { + // console.log("websocket4_2-open"); + // } + // // @ts-ignore + // websocket5_1.onopen = function (event) { + // console.log("websocket5_1-open"); + // } + // // @ts-ignore + // websocket5_2.onopen = function (event) { + // console.log("websocket5_2-open"); + // } //接收到消息的回调方法 // @ts-ignore websocketAllLine.onmessage = function (event) { @@ -105,116 +107,116 @@ function UpdateData() { if (!Object.prototype.toString.call(msgData).includes('Object')) return; dispatch(UpdateAllLine(msgData)); } + // // @ts-ignore + // websocket1_1.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine1Before(msgData)); + // } // @ts-ignore - websocket1_1.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine1Before(msgData)); - } - // @ts-ignore - websocket1_2.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine1After(msgData)); - } - // @ts-ignore - websocket2_1.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine2Before(msgData)); - } - // @ts-ignore - websocket2_2.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine2After(msgData)); - } - // @ts-ignore - websocket3_1.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine3Before(msgData)); - } - // @ts-ignore - websocket3_2.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine3After(msgData)); - } - // @ts-ignore - websocket4_1.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine4Before(msgData)); - } - // @ts-ignore - websocket4_2.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine4After(msgData)); - } - // @ts-ignore - websocket5_1.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine5Before(msgData)); - } - // @ts-ignore - websocket5_2.onmessage = function (event) { - let msgData = event.data - try { - msgData = JSON.parse(event.data); - } catch (error) { - console.log("websocket: [unable to msgData] : ", event.data); - } - if (!Object.prototype.toString.call(msgData).includes('Object')) return; - dispatch(UpdateLine5After(msgData)); - } + // websocket1_2.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine1After(msgData)); + // } + // // @ts-ignore + // websocket2_1.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine2Before(msgData)); + // } + // // @ts-ignore + // websocket2_2.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine2After(msgData)); + // } + // // @ts-ignore + // websocket3_1.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine3Before(msgData)); + // } + // // @ts-ignore + // websocket3_2.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine3After(msgData)); + // } + // // @ts-ignore + // websocket4_1.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine4Before(msgData)); + // } + // // @ts-ignore + // websocket4_2.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine4After(msgData)); + // } + // // @ts-ignore + // websocket5_1.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine5Before(msgData)); + // } + // // @ts-ignore + // websocket5_2.onmessage = function (event) { + // let msgData = event.data + // try { + // msgData = JSON.parse(event.data); + // } catch (error) { + // console.log("websocket: [unable to msgData] : ", event.data); + // } + // if (!Object.prototype.toString.call(msgData).includes('Object')) return; + // dispatch(UpdateLine5After(msgData)); + // } return null; }