From ad305f0c46d401648f562f60316b574591b1e454 Mon Sep 17 00:00:00 2001 From: lb Date: Fri, 1 Dec 2023 16:05:09 +0800 Subject: [PATCH] update firedir --- src/components/Common/TimeFireDir/index.jsx | 42 +++++++++++---------- src/hooks/useTimeCounter.js | 2 +- src/utils/index.js | 11 ++++++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/components/Common/TimeFireDir/index.jsx b/src/components/Common/TimeFireDir/index.jsx index 765a0bf..2d4166f 100644 --- a/src/components/Common/TimeFireDir/index.jsx +++ b/src/components/Common/TimeFireDir/index.jsx @@ -10,11 +10,15 @@ import icon3 from "../../../assets/CenterChart2icon3.svg"; import useTimeCounter from "../../../hooks/useTimeCounter"; const FireInfo = () => { - const dispatch = useDispatch(); + // const dispatch = useDispatch(); const fireInfo = useSelector((state) => state.fireInfo); const time = fireInfo.lastFireChangeTime || "0分0秒"; - const [min, sec] = useTimeCounter(time); - + const minsec = useTimeCounter(time); + let [min, sec] = [0, 0]; + if (minsec) { + min = minsec[0]; + sec = minsec[1]; + } // useEffect(() => { // const restTime = ctx?.runState?.lastFireChangeTime; // if (restTime == null) return; @@ -76,22 +80,22 @@ const FireInfo = () => { // }; // }, [ctx?.runState?.lastFireChangeTime]); - useEffect(() => { - setInterval(() => { - dispatch({ - type: "fireInfo/setFireInfo", - payload: { - fireChangeTime: `${Math.ceil(Math.random() * 10)}:${Math.ceil( - Math.random() * 10 - )}`, - fireDirection: Math.random * 10 < 5 ? "东火" : "西火", - lastFireChangeTime: `${Math.ceil(Math.random() * 60)}分${Math.ceil( - Math.random() * 50 - )}秒`, - }, - }); - }, 10000); - }, []); + // useEffect(() => { + // setInterval(() => { + // dispatch({ + // type: "fireInfo/setFireInfo", + // payload: { + // fireChangeTime: `${Math.ceil(Math.random() * 10)}:${Math.ceil( + // Math.random() * 10 + // )}`, + // fireDirection: Math.random * 10 < 5 ? "东火" : "西火", + // lastFireChangeTime: `${Math.ceil(Math.random() * 60)}分${Math.ceil( + // Math.random() * 50 + // )}秒`, + // }, + // }); + // }, 10000); + // }, []); const data = [ { diff --git a/src/hooks/useTimeCounter.js b/src/hooks/useTimeCounter.js index 55274f4..d5e7700 100644 --- a/src/hooks/useTimeCounter.js +++ b/src/hooks/useTimeCounter.js @@ -1,11 +1,11 @@ import { useEffect, useState } from "react"; function useTimeCounter(time) { - console.log('time counter executed...') // time: 8分12秒 这种 const [timeTuple, setTimeTuple] = useState([0, 0]); useEffect(() => { + console.log("time counter executed..."); if (time == null) return; let timer = null; if (/分/.test(time) && /秒/.test(time)) { diff --git a/src/utils/index.js b/src/utils/index.js index 51074a9..353149f 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -104,6 +104,17 @@ export class WsClient { }); break; } + case "FireInfo": { + // 火向时间信息 + store.dispatch({ + type: "fireInfo/setFireInfo", + payload: serializedData.data, + }); + break; + } + case "FanInfo": { + break; + } default: { console.log("websocket message: [unknown] ---> ", e.data); }