add energe slice

This commit is contained in:
lb 2023-12-06 16:24:34 +08:00
parent 49ac95fbbd
commit 5f92580c7e
3 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import { createSlice } from "@reduxjs/toolkit";
export const initialState = {
info: {
// 余热发电
elecQty1: "0", // kWh
// 电消耗量
elecQty2: "0", // kWh
// 水消耗量
waterQty: "0", // Km³
// 天然气1
ngQty1: "0", // m³
// 天然气2
ngQty2: "0", // m³
},
};
const energySlice = createSlice({
name: "energy",
initialState,
reducers: {
setInfo: (state, action) => {
state.info = { ...state.info, ...action.payload };
},
},
});
export default energySlice.reducer;
export const { setInfo } = energySlice.actions;

View File

@ -7,6 +7,7 @@ import combustionAirReducer from "./features/combustionAirSlice";
import gasReducer from "./features/gasSlice"; import gasReducer from "./features/gasSlice";
import temperatureReducer from "./features/temperatureSlice"; import temperatureReducer from "./features/temperatureSlice";
import fanInfoReducer from "./features/fanInfo"; import fanInfoReducer from "./features/fanInfo";
import energySlice from "./features/EnergySlice";
export const store = configureStore({ export const store = configureStore({
reducer: { reducer: {
@ -26,5 +27,7 @@ export const store = configureStore({
combustionAir: combustionAirReducer, combustionAir: combustionAirReducer,
// 温度 // 温度
temperature: temperatureReducer, temperature: temperatureReducer,
// 能耗
energy: energySlice
}, },
}); });

View File

@ -120,6 +120,14 @@ export class WsClient {
}); });
break; break;
} }
case "energyInfo": {
// 能耗数据
store.dispatch({
type: "energy/setInfo",
payload: serializedData.data,
});
break;
}
default: { default: {
console.log("websocket message: [unknown] ---> ", e.data); console.log("websocket message: [unknown] ---> ", e.data);
} }