From 0b48f68078bd311eb6716a0a82e9a0e0231234b0 Mon Sep 17 00:00:00 2001 From: lb Date: Fri, 26 Jan 2024 09:24:26 +0800 Subject: [PATCH] add refresher --- .../EnergeCostRealtime/index.module.scss | 2 +- src/hooks/useRefresh.js | 41 +++++++++++++++++++ src/pages/Home/index.jsx | 7 +++- src/utils/index.ts | 4 +- 4 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 src/hooks/useRefresh.js diff --git a/src/components/Common/Energy/EnergeCostRealtime/index.module.scss b/src/components/Common/Energy/EnergeCostRealtime/index.module.scss index 9896b8c..996a37a 100644 --- a/src/components/Common/Energy/EnergeCostRealtime/index.module.scss +++ b/src/components/Common/Energy/EnergeCostRealtime/index.module.scss @@ -43,7 +43,7 @@ gap: 8px; grid-template-rows: 1fr 1fr; grid-template-columns: 1fr 1fr; - height: 168px; + height: 162px; padding: 4px 0; } diff --git a/src/hooks/useRefresh.js b/src/hooks/useRefresh.js new file mode 100644 index 0000000..d0ee454 --- /dev/null +++ b/src/hooks/useRefresh.js @@ -0,0 +1,41 @@ +import { useEffect } from "react"; +import dayjs from "dayjs"; + +export default function useRefresh(open, type = "0-clock") { + useEffect(() => { + let timer = null; + if (open) { + switch (type) { + case "0-clock": { + // 0 点 + const now = dayjs(); + const tomorrow_morning = now.add(1, "day").startOf("day"); + timer = setTimeout(() => { + localStorage.setItem('last_refresh', dayjs().format()) + document.location.reload(); + }, tomorrow_morning.valueOf() - now.valueOf()); + break; + } + case "24-hour": { + // 24小时刷新 + timer = setTimeout(() => { + const now = dayjs(); + localStorage.setItem('last_refresh', now.format()) + document.location.reload(); + }, 24 * 60 * 60 * 1000); + break; + } + } + // 开启 + } else { + if (timer) clearTimeout(timer); + timer = null; + } + + return () => { + clearTimeout(timer); + }; + }, [open, type]); + + return undefined; +} diff --git a/src/pages/Home/index.jsx b/src/pages/Home/index.jsx index 351d452..bde47b6 100644 --- a/src/pages/Home/index.jsx +++ b/src/pages/Home/index.jsx @@ -12,8 +12,11 @@ import FireCheckRight from "../../components/Modules/FireCheck/RightSide"; import QualityCheckRight from "../../components/Modules/QualityCheck/RightSide"; import { useSelector } from "react-redux"; import { useEffect, useRef } from "react"; +import useRefresh from "../../hooks/useRefresh"; export default function Home({ active }) { + useRefresh(true); + const videoUp = useRef(null); const videoDown = useRef(null); @@ -21,10 +24,10 @@ export default function Home({ active }) { const fireDir = ctx.fireDirection || null; useEffect(() => { - if (fireDir == "东火") { + if (fireDir == "东火" && videoUp.current) { videoUp.current.playbackRate = 0.3; } else { - videoDown.current.playbackRate = 0.3; + videoDown.current && (videoDown.current.playbackRate = 0.3); } }, [fireDir]); diff --git a/src/utils/index.ts b/src/utils/index.ts index e10187d..c322f7b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -123,8 +123,8 @@ new XClient( new XClient( { - url: "ws://192.168.1.20:48080/websocket/message?userId=ENERGY" + newUser, - // url: "ws://10.70.2.2:8080/websocket/message?userId=ENERGY" + newUser, + // url: "ws://192.168.1.20:48080/websocket/message?userId=ENERGY" + newUser, + url: "ws://10.70.2.2:8080/websocket/message?userId=ENERGY" + newUser, // url: "ws://192.168.1.74:48080/websocket/message?userId=ENERGY" + newUser, name: "MES_DATA", // "ws://192.168.1.74:48080/websocket/message?userId=ENERGY111",