add redux

This commit is contained in:
lb
2023-11-09 16:26:00 +08:00
parent e9d003b1fa
commit 96aab1bea1
3 changed files with 87 additions and 27 deletions

View File

@@ -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 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() {
// const ctx = useContext(SocketContext);
const ctx = null;
const kilnInfo = useSelector((state) => state.kiln);
const dispatch = useDispatch();
console.log("state: ", kilnInfo, stateNameMap);
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℃" },
];
const infos = Object.keys(kilnInfo).map((key) => ({
label: stateNameMap[key],
value: kilnInfo[key],
}));
useEffect(() => {
setTimeout(() => {
dispatch({
type: "kiln/setKilnInfo",
payload: {
kilnPressure: "100Pa",
waterTemp: "100℃",
waterFlow: "100m³/h",
waterPressure: "100Pa",
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 (
<Container title="窑炉信息" icon="kiln" className={cls.leftBar__top}>