update firedir
This commit is contained in:
		@@ -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 = [
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -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)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -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);
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user