add redux
This commit is contained in:
parent
e9d003b1fa
commit
96aab1bea1
@ -1,31 +1,53 @@
|
|||||||
import React from "react";
|
|
||||||
import { useContext } from "react";
|
|
||||||
import Container from "../../Container";
|
|
||||||
// import SocketContext from '../../../store/socket-data-provider';
|
|
||||||
|
|
||||||
|
|
||||||
import cls from "./kiln.module.scss";
|
import cls from "./kiln.module.scss";
|
||||||
|
import Container from "../../Container";
|
||||||
|
import { useSelector } from "react-redux";
|
||||||
|
import { stateNameMap } from "../../../store/features/kilnSlice";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import { useDispatch } from "react-redux";
|
||||||
export default function Kiln() {
|
export default function Kiln() {
|
||||||
// const ctx = useContext(SocketContext);
|
const kilnInfo = useSelector((state) => state.kiln);
|
||||||
const ctx = null;
|
const dispatch = useDispatch();
|
||||||
|
console.log("state: ", kilnInfo, stateNameMap);
|
||||||
|
|
||||||
const infos = [
|
const infos = Object.keys(kilnInfo).map((key) => ({
|
||||||
{ label: "窑炉压力", value: ctx?.runState?.kilnPressure || "0Pa" },
|
label: stateNameMap[key],
|
||||||
{ label: "循环水温度", value: ctx?.runState?.waterTemp || "0℃" },
|
value: kilnInfo[key],
|
||||||
{ label: "循环水流量", value: ctx?.runState?.waterFlow || "0㎡/h" },
|
}));
|
||||||
{ label: "循环水压力", value: ctx?.runState?.waterPressure || "0Pa" },
|
|
||||||
{
|
useEffect(() => {
|
||||||
label: "助燃风压力",
|
setTimeout(() => {
|
||||||
value: ctx?.runState?.combustionAirPressure || "0℃",
|
dispatch({
|
||||||
},
|
type: "kiln/setKilnInfo",
|
||||||
{ label: "碹顶加权温度", value: ctx?.runState?.topTemp || "0℃" },
|
payload: {
|
||||||
{
|
kilnPressure: "100Pa",
|
||||||
label: "压缩气压力",
|
waterTemp: "100℃",
|
||||||
value: ctx?.runState?.compressedAirPressure || "0Pa",
|
waterFlow: "100m³/h",
|
||||||
},
|
waterPressure: "100Pa",
|
||||||
{ label: "融化加权温度", value: ctx?.runState?.meltTemp || "0℃" },
|
combustionAirPressure: "100Pa",
|
||||||
];
|
topTemp: "100℃",
|
||||||
|
compressedAirPressure: "100Pa",
|
||||||
|
meltTemp: "100℃",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// const infos = [
|
||||||
|
// { label: "窑炉压力", value: ctx?.runState?.kilnPressure || "0Pa" },
|
||||||
|
// { label: "循环水温度", value: ctx?.runState?.waterTemp || "0℃" },
|
||||||
|
// { label: "循环水流量", value: ctx?.runState?.waterFlow || "0㎡/h" },
|
||||||
|
// { label: "循环水压力", value: ctx?.runState?.waterPressure || "0Pa" },
|
||||||
|
// {
|
||||||
|
// label: "助燃风压力",
|
||||||
|
// value: ctx?.runState?.combustionAirPressure || "0℃",
|
||||||
|
// },
|
||||||
|
// { label: "碹顶加权温度", value: ctx?.runState?.topTemp || "0℃" },
|
||||||
|
// {
|
||||||
|
// label: "压缩气压力",
|
||||||
|
// value: ctx?.runState?.compressedAirPressure || "0Pa",
|
||||||
|
// },
|
||||||
|
// { label: "融化加权温度", value: ctx?.runState?.meltTemp || "0℃" },
|
||||||
|
// ];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container title="窑炉信息" icon="kiln" className={cls.leftBar__top}>
|
<Container title="窑炉信息" icon="kiln" className={cls.leftBar__top}>
|
||||||
|
38
src/store/features/kilnSlice.js
Normal file
38
src/store/features/kilnSlice.js
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import { createSlice } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
|
export const initialState = {
|
||||||
|
kilnPressure: "0Pa",
|
||||||
|
waterTemp: "0℃",
|
||||||
|
waterFlow: "0m³/h",
|
||||||
|
waterPressure: "0Pa",
|
||||||
|
combustionAirPressure: "0Pa",
|
||||||
|
topTemp: "0℃",
|
||||||
|
compressedAirPressure: "0Pa",
|
||||||
|
meltTemp: "0℃",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const stateNameMap = {
|
||||||
|
kilnPressure: "窑炉压力",
|
||||||
|
waterTemp: "循环水温度",
|
||||||
|
waterFlow: "循环水流量",
|
||||||
|
waterPressure: "循环水压力",
|
||||||
|
combustionAirPressure: "助燃风压力",
|
||||||
|
topTemp: "碹顶加权温度",
|
||||||
|
compressedAirPressure: "压缩气压力",
|
||||||
|
meltTemp: "融化加权温度",
|
||||||
|
};
|
||||||
|
|
||||||
|
const kilnSlice = createSlice({
|
||||||
|
name: "kiln",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
setKilnInfo: (state, action) => {
|
||||||
|
Object.keys(action.payload).forEach((key) => {
|
||||||
|
state[key] = action.payload[key];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default kilnSlice.reducer;
|
||||||
|
export const { setKilnInfo } = kilnSlice.actions;
|
@ -1,8 +1,8 @@
|
|||||||
import { configureStore } from "@reduxjs/toolkit";
|
import { configureStore } from "@reduxjs/toolkit";
|
||||||
// import counterReducer from '../features/kiln/KilnSlice'
|
import kilnReducer from "./features/kilnSlice";
|
||||||
|
|
||||||
export const store = configureStore({
|
export const store = configureStore({
|
||||||
reducer: {
|
reducer: {
|
||||||
// counter: counterReducer,
|
kiln: kilnReducer,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user