add energe slice
This commit is contained in:
parent
49ac95fbbd
commit
5f92580c7e
29
src/store/features/EnergySlice.js
Normal file
29
src/store/features/EnergySlice.js
Normal 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;
|
@ -7,6 +7,7 @@ import combustionAirReducer from "./features/combustionAirSlice";
|
||||
import gasReducer from "./features/gasSlice";
|
||||
import temperatureReducer from "./features/temperatureSlice";
|
||||
import fanInfoReducer from "./features/fanInfo";
|
||||
import energySlice from "./features/EnergySlice";
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
@ -26,5 +27,7 @@ export const store = configureStore({
|
||||
combustionAir: combustionAirReducer,
|
||||
// 温度
|
||||
temperature: temperatureReducer,
|
||||
// 能耗
|
||||
energy: energySlice
|
||||
},
|
||||
});
|
||||
|
@ -120,6 +120,14 @@ export class WsClient {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "energyInfo": {
|
||||
// 能耗数据
|
||||
store.dispatch({
|
||||
type: "energy/setInfo",
|
||||
payload: serializedData.data,
|
||||
});
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
console.log("websocket message: [unknown] ---> ", e.data);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user