update firedir

This commit is contained in:
lb 2023-12-01 16:05:09 +08:00
parent 4a882104c8
commit ad305f0c46
3 changed files with 35 additions and 20 deletions

View File

@ -10,11 +10,15 @@ import icon3 from "../../../assets/CenterChart2icon3.svg";
import useTimeCounter from "../../../hooks/useTimeCounter"; import useTimeCounter from "../../../hooks/useTimeCounter";
const FireInfo = () => { const FireInfo = () => {
const dispatch = useDispatch(); // const dispatch = useDispatch();
const fireInfo = useSelector((state) => state.fireInfo); const fireInfo = useSelector((state) => state.fireInfo);
const time = fireInfo.lastFireChangeTime || "0分0秒"; 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(() => { // useEffect(() => {
// const restTime = ctx?.runState?.lastFireChangeTime; // const restTime = ctx?.runState?.lastFireChangeTime;
// if (restTime == null) return; // if (restTime == null) return;
@ -76,22 +80,22 @@ const FireInfo = () => {
// }; // };
// }, [ctx?.runState?.lastFireChangeTime]); // }, [ctx?.runState?.lastFireChangeTime]);
useEffect(() => { // useEffect(() => {
setInterval(() => { // setInterval(() => {
dispatch({ // dispatch({
type: "fireInfo/setFireInfo", // type: "fireInfo/setFireInfo",
payload: { // payload: {
fireChangeTime: `${Math.ceil(Math.random() * 10)}:${Math.ceil( // fireChangeTime: `${Math.ceil(Math.random() * 10)}:${Math.ceil(
Math.random() * 10 // Math.random() * 10
)}`, // )}`,
fireDirection: Math.random * 10 < 5 ? "东火" : "西火", // fireDirection: Math.random * 10 < 5 ? "" : "西",
lastFireChangeTime: `${Math.ceil(Math.random() * 60)}${Math.ceil( // lastFireChangeTime: `${Math.ceil(Math.random() * 60)}${Math.ceil(
Math.random() * 50 // Math.random() * 50
)}`, // )}`,
}, // },
}); // });
}, 10000); // }, 10000);
}, []); // }, []);
const data = [ const data = [
{ {

View File

@ -1,11 +1,11 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
function useTimeCounter(time) { function useTimeCounter(time) {
console.log('time counter executed...')
// time: 8分12秒 这种 // time: 8分12秒 这种
const [timeTuple, setTimeTuple] = useState([0, 0]); const [timeTuple, setTimeTuple] = useState([0, 0]);
useEffect(() => { useEffect(() => {
console.log("time counter executed...");
if (time == null) return; if (time == null) return;
let timer = null; let timer = null;
if (/分/.test(time) && /秒/.test(time)) { if (/分/.test(time) && /秒/.test(time)) {

View File

@ -104,6 +104,17 @@ export class WsClient {
}); });
break; break;
} }
case "FireInfo": {
// 火向时间信息
store.dispatch({
type: "fireInfo/setFireInfo",
payload: serializedData.data,
});
break;
}
case "FanInfo": {
break;
}
default: { default: {
console.log("websocket message: [unknown] ---> ", e.data); console.log("websocket message: [unknown] ---> ", e.data);
} }