From 5f92580c7e2f00cc97d58efc7e3701f6df88b359 Mon Sep 17 00:00:00 2001 From: lb Date: Wed, 6 Dec 2023 16:24:34 +0800 Subject: [PATCH] add energe slice --- src/store/features/EnergySlice.js | 29 +++++++++++++++++++++++++++++ src/store/index.js | 3 +++ src/utils/index.js | 8 ++++++++ 3 files changed, 40 insertions(+) create mode 100644 src/store/features/EnergySlice.js diff --git a/src/store/features/EnergySlice.js b/src/store/features/EnergySlice.js new file mode 100644 index 0000000..6a4f157 --- /dev/null +++ b/src/store/features/EnergySlice.js @@ -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; diff --git a/src/store/index.js b/src/store/index.js index b87590c..8f65dff 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -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 }, }); diff --git a/src/utils/index.js b/src/utils/index.js index 252ffa3..dd4fbd2 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -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); }