add refresher

This commit is contained in:
lb 2024-01-26 09:24:26 +08:00
parent c767a7fe2e
commit 0b48f68078
4 changed files with 49 additions and 5 deletions

View File

@ -43,7 +43,7 @@
gap: 8px; gap: 8px;
grid-template-rows: 1fr 1fr; grid-template-rows: 1fr 1fr;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
height: 168px; height: 162px;
padding: 4px 0; padding: 4px 0;
} }

41
src/hooks/useRefresh.js Normal file
View File

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

View File

@ -12,8 +12,11 @@ import FireCheckRight from "../../components/Modules/FireCheck/RightSide";
import QualityCheckRight from "../../components/Modules/QualityCheck/RightSide"; import QualityCheckRight from "../../components/Modules/QualityCheck/RightSide";
import { useSelector } from "react-redux"; import { useSelector } from "react-redux";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import useRefresh from "../../hooks/useRefresh";
export default function Home({ active }) { export default function Home({ active }) {
useRefresh(true);
const videoUp = useRef(null); const videoUp = useRef(null);
const videoDown = useRef(null); const videoDown = useRef(null);
@ -21,10 +24,10 @@ export default function Home({ active }) {
const fireDir = ctx.fireDirection || null; const fireDir = ctx.fireDirection || null;
useEffect(() => { useEffect(() => {
if (fireDir == "东火") { if (fireDir == "东火" && videoUp.current) {
videoUp.current.playbackRate = 0.3; videoUp.current.playbackRate = 0.3;
} else { } else {
videoDown.current.playbackRate = 0.3; videoDown.current && (videoDown.current.playbackRate = 0.3);
} }
}, [fireDir]); }, [fireDir]);

View File

@ -123,8 +123,8 @@ new XClient(
new XClient( new XClient(
{ {
url: "ws://192.168.1.20:48080/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://10.70.2.2:8080/websocket/message?userId=ENERGY" + newUser,
// url: "ws://192.168.1.74:48080/websocket/message?userId=ENERGY" + newUser, // url: "ws://192.168.1.74:48080/websocket/message?userId=ENERGY" + newUser,
name: "MES_DATA", name: "MES_DATA",
// "ws://192.168.1.74:48080/websocket/message?userId=ENERGY111", // "ws://192.168.1.74:48080/websocket/message?userId=ENERGY111",