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";
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 = [
{

View File

@ -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)) {

View File

@ -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);
}