初始化,印度版本7.29

This commit is contained in:
2024-07-29 14:10:07 +08:00
commit 3c8c7e497b
202 changed files with 52317 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
const initialState = {
Locale: "zh-CN",
text_1: "text_1",
text_34: "text_34"
}
export const ChangeLangAndCss = createSlice({
name: 'ChangeCss',
initialState,
reducers: {
UpdateChangeLangAndCss: (state) => {
if (state.Locale == "zh-CN") {
state.Locale = "en-US";
state.text_1 = "text_1_EN";
state.text_34 = "text_34_EN"
} else {
state.Locale = "zh-CN";
state.text_1 = "text_1";
state.text_34 = "text_34"
}
}
}
})
export const {UpdateChangeLangAndCss} = ChangeLangAndCss.actions;
export const selectChangeLangAndCss = (state: RootState) => state.ChangeCss;
export default ChangeLangAndCss.reducer;

37
src/store/ChangeLineID.ts Normal file
View File

@@ -0,0 +1,37 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
const initialState = {
LineID: 1,
}
export const ChangeLineID = createSlice({
name: 'ChangeLineID',
initialState,
reducers: {
UpdateChangeLineID: (state, action) => {
switch (action.payload) {
case '1':
state.LineID = 1;
break;
case '2':
state.LineID = 2;
break;
case '3':
state.LineID = 3;
break;
case '4':
state.LineID = 4;
break;
default:
state.LineID = 1;
break
}
},
}
})
export const {UpdateChangeLineID} = ChangeLineID.actions;
export const selectChangeLineID = (state: RootState) => state.ChangeLineID.LineID;
export default ChangeLineID.reducer;

View File

@@ -0,0 +1,25 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
const initialState = {
switchState: true,
}
export const ChangeSwitchState = createSlice({
name: 'ChangeSwitchState',
initialState,
reducers: {
ChangeSwitch: (state) => {
if (state.switchState) {
state.switchState = false;
} else {
state.switchState = true;
}
}
}
})
export const {ChangeSwitch} = ChangeSwitchState.actions;
export const selectSwitchState = (state: RootState) => state.ChangeSwitchState.switchState;
export default ChangeSwitchState.reducer;

View File

@@ -0,0 +1,191 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
export interface EquStatusInterface {
CleanAfterEdge1_1: number
CleanAfterEdge1_2: number
CleanAfterEdge2_1: number
CleanAfterEdge2_2: number
CleanAfterEdge3_1: number
CleanAfterEdge3_2: number
CleanAfterEdge4_1: number
CleanAfterEdge4_2: number
CleanAfterTemper1_1: number
CleanAfterTemper2_1: number
CleanAfterTemper3_1: number
CleanAfterTemper4_1: number
CleanBeforCoat1_1: number
CleanBeforCoat1_2: number
CleanBeforCoat4_1: number
CleanBeforCoat4_2: number
Edge1_1: number
Edge1_2: number
Edge2_1: number
Edge2_2: number
Edge3_1: number
Edge3_2: number
Edge4_1: number
Edge4_2: number
FirstCoat1_1: number
FirstCoat1_2: number
FirstCoat2_1: number
FirstCoat2_2: number
FirstCoat3_1: number
FirstCoat3_2: number
FirstCoat4_1: number
FirstCoat4_2: number
Punch1_1: number
Punch1_2: number
Punch4_1: number
Punch4_2: number
SecondCoat1_1: number
SecondCoat1_2: number
SecondCoat2_1: number
SecondCoat2_2: number
SecondCoat3_1: number
SecondCoat3_2: number
SecondCoat4_1: number
SecondCoat4_2: number
Temper1_1: number
Temper2_1: number
Temper3_1: number
Temper4_1: number
Unload1_1: number
Unload1_2: number
Unload2_1: number
Unload2_2: number
Unload3_1: number
Unload3_2: number
Unload4_1: number
Unload4_2: number
}
const initialState: EquStatusInterface = {
CleanAfterEdge1_1: 0,
CleanAfterEdge1_2: 0,
CleanAfterEdge2_1: 0,
CleanAfterEdge2_2: 0,
CleanAfterEdge3_1: 0,
CleanAfterEdge3_2: 0,
CleanAfterEdge4_1: 0,
CleanAfterEdge4_2: 0,
CleanAfterTemper1_1: 0,
CleanAfterTemper2_1: 0,
CleanAfterTemper3_1: 0,
CleanAfterTemper4_1: 0,
CleanBeforCoat1_1: 0,
CleanBeforCoat1_2: 0,
CleanBeforCoat4_1: 0,
CleanBeforCoat4_2: 0,
Edge1_1: 0,
Edge1_2: 0,
Edge2_1: 0,
Edge2_2: 0,
Edge3_1: 0,
Edge3_2: 0,
Edge4_1: 0,
Edge4_2: 0,
FirstCoat1_1: 0,
FirstCoat1_2: 0,
FirstCoat2_1: 0,
FirstCoat2_2: 0,
FirstCoat3_1: 0,
FirstCoat3_2: 0,
FirstCoat4_1: 0,
FirstCoat4_2: 0,
Punch1_1: 0,
Punch1_2: 0,
Punch4_1: 0,
Punch4_2: 0,
SecondCoat1_1: 0,
SecondCoat1_2: 0,
SecondCoat2_1: 0,
SecondCoat2_2: 0,
SecondCoat3_1: 0,
SecondCoat3_2: 0,
SecondCoat4_1: 0,
SecondCoat4_2: 0,
Temper1_1: 0,
Temper2_1: 0,
Temper3_1: 0,
Temper4_1: 0,
Unload1_1: 0,
Unload1_2: 0,
Unload2_1: 0,
Unload2_2: 0,
Unload3_1: 0,
Unload3_2: 0,
Unload4_1: 0,
Unload4_2: 0
}
export const EquStatusEntity = createSlice({
name: 'EquStatusEntity',
initialState,
reducers: {
UpdateEquStatus: (state, action) => {
const JsonData = action.payload;
state.CleanAfterEdge1_1 = JsonData['CleanAfterEdge1-1'].status;
state.CleanAfterEdge1_2 = JsonData['CleanAfterEdge1-2'].status;
state.CleanAfterEdge2_1 = JsonData['CleanAfterEdge2-1'].status;
state.CleanAfterEdge2_2 = JsonData['CleanAfterEdge2-2'].status;
state.CleanAfterEdge3_1 = JsonData['CleanAfterEdge3-1'].status;
state.CleanAfterEdge3_2 = JsonData['CleanAfterEdge3-2'].status;
state.CleanAfterEdge4_1 = JsonData['CleanAfterEdge4-1'].status;
state.CleanAfterEdge4_2 = JsonData['CleanAfterEdge4-2'].status;
state.CleanAfterTemper1_1 = JsonData['CleanAfterTemper1-1'].status;
state.CleanAfterTemper2_1 = JsonData['CleanAfterTemper2-1'].status;
state.CleanAfterTemper3_1 = JsonData['CleanAfterTemper3-1'].status;
state.CleanAfterTemper4_1 = JsonData['CleanAfterTemper4-1'].status;
state.CleanBeforCoat1_1 = JsonData['CleanBeforCoat1-1'].status;
state.CleanBeforCoat1_2 = JsonData['CleanBeforCoat1-2'].status;
state.CleanBeforCoat4_1 = JsonData['CleanBeforCoat4-1'].status;
state.CleanBeforCoat4_2 = JsonData['CleanBeforCoat4-2'].status;
state.Edge1_1 = JsonData['Edge1-1'].status;
state.Edge1_2 = JsonData['Edge1-2'].status;
state.Edge2_1 = JsonData['Edge2-1'].status;
state.Edge2_2 = JsonData['Edge2-2'].status;
state.Edge3_1 = JsonData['Edge3-1'].status;
state.Edge3_2 = JsonData['Edge3-2'].status;
state.Edge4_1 = JsonData['Edge4-1'].status;
state.Edge4_2 = JsonData['Edge4-2'].status;
state.FirstCoat1_1 = JsonData['FirstCoat1-1'].status;
state.FirstCoat1_2 = JsonData['FirstCoat1-2'].status;
state.FirstCoat2_1 = JsonData['FirstCoat2-1'].status;
state.FirstCoat2_2 = JsonData['FirstCoat2-2'].status;
state.FirstCoat3_1 = JsonData['FirstCoat3-1'].status;
state.FirstCoat3_2 = JsonData['FirstCoat3-2'].status;
state.FirstCoat4_1 = JsonData['FirstCoat4-1'].status;
state.FirstCoat4_2 = JsonData['FirstCoat4-2'].status;
state.Punch1_1 = JsonData['Punch1-1'].status;
state.Punch1_2 = JsonData['Punch1-2'].status;
state.Punch4_1 = JsonData['Punch4-1'].status;
state.Punch4_2 = JsonData['Punch4-2'].status;
state.SecondCoat1_1 = JsonData['SecondCoat1-1'].status;
state.SecondCoat1_2 = JsonData['SecondCoat1-2'].status;
state.SecondCoat2_1 = JsonData['SecondCoat2-1'].status;
state.SecondCoat2_2 = JsonData['SecondCoat2-2'].status;
state.SecondCoat3_1 = JsonData['SecondCoat3-1'].status;
state.SecondCoat3_2 = JsonData['SecondCoat3-2'].status;
state.SecondCoat4_1 = JsonData['SecondCoat4-1'].status;
state.SecondCoat4_2 = JsonData['SecondCoat4-2'].status;
state.Temper1_1 = JsonData['Temper1-1'].status;
state.Temper2_1 = JsonData['Temper2-1'].status;
state.Temper3_1 = JsonData['Temper3-1'].status;
state.Temper4_1 = JsonData['Temper4-1'].status;
state.Unload1_1 = JsonData['Unload1-1'].status;
state.Unload1_2 = JsonData['Unload1-2'].status;
state.Unload2_1 = JsonData['Unload2-1'].status;
state.Unload2_2 = JsonData['Unload2-2'].status;
state.Unload3_1 = JsonData['Unload3-1'].status;
state.Unload3_2 = JsonData['Unload3-2'].status;
state.Unload4_1 = JsonData['Unload4-1'].status;
state.Unload4_2 = JsonData['Unload4-2'].status;
}
}
})
export const {UpdateEquStatus} = EquStatusEntity.actions;
export const selectEquStatus = (state: RootState) => state.EquStatusEntity;
export default EquStatusEntity.reducer;

View File

@@ -0,0 +1,93 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
export interface Alarm {
alarmContent: string;
equName: string;
alarmCode: any;
alarmEquipmentId: number;
alarmValue: string;
alarmId: number;
alarmSource: string;
}
export interface TickCount {
equName: string;
tickCount: number;
}
export interface Product {
externalCode: number,
equipmentCode: number,
outputNum: number,
lineName: string,
equipmentId: number,
sectionName: string,
inputNum: number,
recordTime: number,
equipmentName: string
}
export interface Oee {
workRate: number;
equName: string;
downRate: number;
stopRate: number;
}
export interface EquipmentLine {
equipmentAlarm: Array<Alarm>,
equipmentTickCounts: Array<TickCount>,
equipmentOees: Array<Oee>,
equipmentProductDays: Array<Product>,
equipmentProductWeeks: Array<Product>,
equipmentProductMonths: Array<Product>,
equipmentProductAll: Array<Product>,
}
export interface EquipmentMonitorEntityInterface {
Line_1: EquipmentLine,
Line_2: EquipmentLine,
Line_3: EquipmentLine,
Line_4: EquipmentLine
}
const emptyEquipmentLine: EquipmentLine = {
equipmentAlarm: [],
equipmentTickCounts: [],
equipmentOees: [],
equipmentProductDays: [],
equipmentProductWeeks: [],
equipmentProductMonths: [],
equipmentProductAll: [],
}
const initialState: EquipmentMonitorEntityInterface = {
Line_1: emptyEquipmentLine,
Line_2: emptyEquipmentLine,
Line_3: emptyEquipmentLine,
Line_4: emptyEquipmentLine
}
export const EquipmentMonitorEntity = createSlice({
name: 'EquipmentMonitorEntity',
initialState,
reducers: {
UpdateEquipmentMonitorEntity: (state, action) => {
if (action.payload.toString().includes('客户端')) {
} else {
const BasicEquipmentMonitorEntity = JSON.parse(action.payload);
state.Line_1 = BasicEquipmentMonitorEntity.Line_1;
state.Line_2 = BasicEquipmentMonitorEntity.Line_2;
state.Line_3 = BasicEquipmentMonitorEntity.Line_3;
state.Line_4 = BasicEquipmentMonitorEntity.Line_4;
}
},
}
})
export const {UpdateEquipmentMonitorEntity} = EquipmentMonitorEntity.actions;
export const selectAllLineEquipmentData = (state: RootState) => state.EquipmentMonitorEntity;
export default EquipmentMonitorEntity.reducer;

View File

@@ -0,0 +1,214 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
export interface alarm {
alarmContent: string;
alarmTime: string;
alarmCode: string;
}
export interface ProductionDet {
lineName: string;
inputNum: number;
outputNum: number;
passRate: number;
}
export interface ProductionRate {
lineName: string;
lineId: number;
lineExCode: string;
passRate: number;
time: number;
}
export interface RateLine {
Line_1: Array<ProductionRate>,
Line_2: Array<ProductionRate>,
Line_3: Array<ProductionRate>,
Line_4: Array<ProductionRate>,
}
export interface SingleGlassStatus {
lineViewCode: string,
status: number
}
export interface GlassStatus {
LINE_1_1: number,
LINE_1_2U: number,
LINE_1_2D: number,
LINE_1_3: number,
LINE_1_4: number,
LINE_2_1: number,
LINE_2_2U: number,
LINE_2_2D: number,
LINE_2_3: number,
LINE_2_4: number,
LINE_3_1: number,
LINE_3_2U: number,
LINE_3_2D: number,
LINE_3_3: number,
LINE_3_4: number,
LINE_4_1: number,
LINE_4_2U: number,
LINE_4_2D: number,
LINE_4_3: number,
LINE_4_4: number,
}
const initLineGlassStatus: GlassStatus = {
LINE_1_1: 1,
LINE_1_2U: 1,
LINE_1_2D: 1,
LINE_1_3: 1,
LINE_1_4: 1,
LINE_2_1: 1,
LINE_2_2U: 1,
LINE_2_2D: 1,
LINE_2_3: 1,
LINE_2_4: 1,
LINE_3_1: 1,
LINE_3_2U: 1,
LINE_3_2D: 1,
LINE_3_3: 1,
LINE_3_4: 1,
LINE_4_1: 1,
LINE_4_2U: 1,
LINE_4_2D: 1,
LINE_4_3: 1,
LINE_4_4: 1,
}
export interface ProductionMonitoringEntityInterface {
sumNumber: number;
alarms: Array<alarm>;
sumProductionDets: Array<ProductionDet>;
todayProductionDets: Array<ProductionDet>;
weekProductionDets: Array<ProductionDet>;
monthProductionDets: Array<ProductionDet>;
todayProductionRates: RateLine,
weekProductionRates: RateLine,
monthProductionRates: RateLine,
lineGlassStatus: GlassStatus,
}
const emptyProductionRates: RateLine = {
Line_4: [
{
"lineId": 1,
"lineName": "产线1",
"lineExCode": "Line_1",
"passRate": 101.88,
"time": 1676840400000
},
],
Line_3: [
{
"lineId": 1619974755856867329,
"lineName": "产线3",
"lineExCode": "Line_3",
"passRate": 32.04,
"time": 1676822400000
}
],
Line_2: [
{
"lineId": 1619974755856867329,
"lineName": "产线3",
"lineExCode": "Line_3",
"passRate": 32.04,
"time": 1676822400000
}
],
Line_1: [
{
"lineId": 1619974755856867329,
"lineName": "产线3",
"lineExCode": "Line_3",
"passRate": 32.04,
"time": 1676822400000
}
]
}
const initialState: ProductionMonitoringEntityInterface = {
sumNumber: 0,
alarms: [],
sumProductionDets: [],
todayProductionDets: [],
weekProductionDets: [],
monthProductionDets: [],
todayProductionRates: emptyProductionRates,
weekProductionRates: emptyProductionRates,
monthProductionRates: emptyProductionRates,
lineGlassStatus: initLineGlassStatus,
}
export const ProductionMonitoringEntity = createSlice({
name: 'ProductionMonitoringEntity',
initialState,
reducers: {
UpdateProductionMonitoringEntity: (state, action) => {
if (action.payload.toString().includes('客户端')) {
} else {
const ProductionMonitoringEntityData = JSON.parse(action.payload);
//sumNumber
state.sumNumber = ProductionMonitoringEntityData.alarms.length;
//alarms
state.alarms = [];
for (let i = 0; i < 6; i++) {
state.alarms.push({
alarmContent: ProductionMonitoringEntityData.alarms[i].alarmContent,
alarmCode: ProductionMonitoringEntityData.alarms[i].alarmCode,
alarmTime: new Date(ProductionMonitoringEntityData.alarms[i].alarmTime).toLocaleDateString(),
}
)
}
//sumProductionDets
state.sumProductionDets = ProductionMonitoringEntityData.sumProductionDets;
//todayProductionDets
state.todayProductionDets = ProductionMonitoringEntityData.todayProductionDets;
//weekProductionDets
state.weekProductionDets = ProductionMonitoringEntityData.weekProductionDets;
//monthProductionDets
state.monthProductionDets = ProductionMonitoringEntityData.monthProductionDets;
//todayProductionRates
state.todayProductionRates = ProductionMonitoringEntityData.todayProductionRates;
//weekProductionRates
state.weekProductionRates = ProductionMonitoringEntityData.weekProductionRates;
//monthProductionRates
state.monthProductionRates = ProductionMonitoringEntityData.monthProductionRates;
}
},
UpdateGlassStatus: (state, action) => {
//lineGlassStatus
state.lineGlassStatus = action.payload;
}
}
})
export const {UpdateProductionMonitoringEntity, UpdateGlassStatus} = ProductionMonitoringEntity.actions;
export const selectAlarms = (state: RootState) => state.ProductionMonitoringEntity.alarms;
export const selectSumNumber = (state: RootState) => state.ProductionMonitoringEntity.sumNumber;
export const selectSumProductionDets = (state: RootState) => state.ProductionMonitoringEntity.sumProductionDets;
export const selectTodayProductionDets = (state: RootState) => state.ProductionMonitoringEntity.todayProductionDets;
export const selectWeekProductionDets = (state: RootState) => state.ProductionMonitoringEntity.weekProductionDets;
export const selectMonthProductionDets = (state: RootState) => state.ProductionMonitoringEntity.monthProductionDets;
export const selectTodayProductionRates = (state: RootState) => state.ProductionMonitoringEntity.todayProductionRates;
export const selectWeekProductionRates = (state: RootState) => state.ProductionMonitoringEntity.weekProductionRates;
export const selectMonthProductionRates = (state: RootState) => state.ProductionMonitoringEntity.monthProductionRates;
export const selectGlassStatus = (state: RootState) => state.ProductionMonitoringEntity.lineGlassStatus;
export default ProductionMonitoringEntity.reducer;

View File

@@ -0,0 +1,64 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
export interface Quality {
num: number;
sort: number;
content: string;
}
export interface QualityLineAll {
Line_1: Array<Quality>;
Line_2: Array<Quality>;
Line_3: Array<Quality>;
Line_4: Array<Quality>;
}
export interface QualityMonitorEntityInterface {
todayQualityAll: Array<Quality>;
weekQualityAll: Array<Quality>;
monthQualityAll: Array<Quality>;
todayQualityLineAll: QualityLineAll;
weekQualityLineAll: QualityLineAll;
monthQualityLineAll: QualityLineAll;
}
const emptyQualityLineAll: QualityLineAll = {
Line_1: [],
Line_2: [],
Line_3: [],
Line_4: []
}
const initialState: QualityMonitorEntityInterface = {
todayQualityAll: [],
weekQualityAll: [],
monthQualityAll: [],
todayQualityLineAll: emptyQualityLineAll,
weekQualityLineAll: emptyQualityLineAll,
monthQualityLineAll: emptyQualityLineAll
}
export const QualityMonitorEntity = createSlice({
name: 'QualityMonitorEntity',
initialState,
reducers: {
UpdateQualityMonitorEntity: (state, action) => {
if (action.payload.toString().includes('客户端')) {
} else {
const QualityMonitorEntityData = JSON.parse(action.payload);
state.todayQualityAll = QualityMonitorEntityData.todayQualityAll;
state.weekQualityAll = QualityMonitorEntityData.weekQualityAll;
state.monthQualityAll = QualityMonitorEntityData.monthQualityAll;
state.todayQualityLineAll = QualityMonitorEntityData.todayQualityLineAll;
state.weekQualityLineAll = QualityMonitorEntityData.weekQualityLineAll;
state.monthQualityLineAll = QualityMonitorEntityData.monthQualityLineAll;
}
}
}
})
export const {UpdateQualityMonitorEntity} = QualityMonitorEntity.actions
export const selectQualityMonitorEntity = (state: RootState) => state.QualityMonitorEntity;
export default QualityMonitorEntity.reducer;

130
src/store/UpdateData.tsx Normal file
View File

@@ -0,0 +1,130 @@
import React, {useState} from "react";
import {useAppDispatch, useAppSelector} from "./hooks";
import {
GlassStatus,
SingleGlassStatus,
UpdateGlassStatus,
UpdateProductionMonitoringEntity
} from "./ProductionMonitoringEntity";
import {UpdateEquipmentMonitorEntity} from "./EquipmentMonitorEntity";
import {UpdateQualityMonitorEntity} from "./QualityMonitorEntity";
import axios from "axios";
import {UpdateEquStatus} from "./EquStatusEntity";
//将消息显示在网页上
// @ts-ignore
function setMessageInnerHTML(innerHTML) {
console.log(innerHTML)
}
let initLineGlassStatus: Object = {
LINE_1_1: 1,
LINE_1_2U: 1,
LINE_1_2D: 1,
LINE_1_3: 1,
LINE_1_4: 1,
LINE_2_1: 1,
LINE_2_2U: 1,
LINE_2_2D: 1,
LINE_2_3: 1,
LINE_2_4: 1,
LINE_3_1: 1,
LINE_3_2U: 1,
LINE_3_2D: 1,
LINE_3_3: 1,
LINE_3_4: 1,
LINE_4_1: 1,
LINE_4_2U: 1,
LINE_4_2D: 1,
LINE_4_3: 1,
LINE_4_4: 1,
}
function PrepareGlassStatus(action: string) {
let FinalGlassStatus = initLineGlassStatus;
if (action.includes('客户端')) {
return FinalGlassStatus;
} else {
const ProductionMonitoringEntityData = JSON.parse(action);
let JsonData = ProductionMonitoringEntityData.lineGlassStatus;
// console.log(JsonData)
let keys: Array<string> = [];
let values: Array<number> = []
let newJson = new Object();
JsonData.map((item: SingleGlassStatus) => {
keys.push(item.lineViewCode);
values.push(item.status);
})
for (let i = 0; i < keys.length; i++) {
let keyName = keys[i];
// @ts-ignore
newJson[keyName] = values[i];
}
FinalGlassStatus = newJson;
// console.log(FinalGlassStatus)
return FinalGlassStatus;
}
}
function UpdateData() {
const [myUrl, setUrl] = useState('')
axios.get('/wsconfig.json')
.then((r) => {
setUrl(r.data.url)
})
let websocketP = null;
let websocketE = null;
let websocketQ = null;
if ('WebSocket' in window) {
websocketP = new WebSocket("ws://" + myUrl + "websocket/P" + Math.random() * 10000000);
websocketE = new WebSocket("ws://" + myUrl + "websocket/E" + Math.random() * 10000000);
websocketQ = new WebSocket("ws://" + myUrl + "websocket/Q" + Math.random() * 10000000);
//连接成功建立的回调方法
} else {
alert('Not support websocket');
}
// @ts-ignore
websocketP.onopen = function (event) {
setMessageInnerHTML("websocketP-open");
}
// @ts-ignore
websocketE.onopen = function (event) {
setMessageInnerHTML("websocketE-open");
}
// @ts-ignore
websocketQ.onopen = function (event) {
setMessageInnerHTML("websocketQ-open");
}
//接收到消息的回调方法
// @ts-ignore
websocketP.onmessage = function (event) {
dispatch(UpdateProductionMonitoringEntity(event.data));
dispatch(UpdateGlassStatus(PrepareGlassStatus(event.data)))
if (event.data.toString().includes('客户端')) {
} else {
const PJson = JSON.parse(event.data)
dispatch(UpdateEquStatus(PJson.equStatus))
}
}
// @ts-ignore
websocketE.onmessage = function (event) {
dispatch(UpdateEquipmentMonitorEntity(event.data));
}
// @ts-ignore
websocketQ.onmessage = function (event) {
dispatch(UpdateQualityMonitorEntity(event.data))
}
const dispatch = useAppDispatch();
return (
null
)
}
export default UpdateData;

6
src/store/hooks.ts Normal file
View File

@@ -0,0 +1,6 @@
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux';
import type { RootState, AppDispatch } from './store';
// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = () => useDispatch<AppDispatch>();
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector;

27
src/store/myDataSlice.ts Normal file
View File

@@ -0,0 +1,27 @@
import {createSlice} from "@reduxjs/toolkit";
import type {RootState} from "./store";
export interface MyDataSlice {
value: number;
}
const initialState: MyDataSlice = {
value: 0,
}
export const myDataSlice = createSlice({
name: 'myData',
initialState,
reducers: {
addMyData: (state) => {
state.value += 1
}
},
})
export const {addMyData} = myDataSlice.actions;
export const selectMyData = (state: RootState) => state.myData.value;
export default myDataSlice.reducer;

26
src/store/store.ts Normal file
View File

@@ -0,0 +1,26 @@
import {configureStore} from '@reduxjs/toolkit';
import myDataReducer from "./myDataSlice";
import ProductionMonitoringEntityReducer from "./ProductionMonitoringEntity";
import ChangeCssReducer from "./ChangeLangAndCss";
import ChangeLineIDReducer from "./ChangeLineID";
import EquipmentMonitorEntityReducer from "./EquipmentMonitorEntity";
import QualityMonitorEntityReducer from "./QualityMonitorEntity"
import ChangeSwitchStateReducer from "./ChangeSwitchState"
import EquStatusEntityReducer, {EquStatusEntity} from "./EquStatusEntity"
export const store = configureStore({
reducer: {
myData: myDataReducer,
ProductionMonitoringEntity: ProductionMonitoringEntityReducer,
ChangeCss: ChangeCssReducer,
ChangeLineID: ChangeLineIDReducer,
EquipmentMonitorEntity: EquipmentMonitorEntityReducer,
QualityMonitorEntity: QualityMonitorEntityReducer,
ChangeSwitchState: ChangeSwitchStateReducer,
EquStatusEntity: EquStatusEntityReducer
},
})
;
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof store.getState>;