fix: ensure dynamic reloading of kueData.js to update alarm status in real-time
- Implemented conditional check before removing existing kueData.js script to avoid NotFoundError. - Added dynamic script reloading to fetch the latest alarm status without browser refresh. - Improved update mechanism for alarm status based on latest kueData.js values.
This commit is contained in:
@@ -15,6 +15,7 @@ function Kue705FO({
|
||||
tdrLocation,
|
||||
alarmStatus,
|
||||
}) {
|
||||
const [currentAlarmStatus, setCurrentAlarmStatus] = useState(false);
|
||||
const [currentModulName, setCurrentModulName] = useState(modulName);
|
||||
const [activeButton, setActiveButton] = useState("Schleife");
|
||||
const [displayText, setDisplayText] = useState("Schleifenwiderstand [kOhm]");
|
||||
@@ -200,11 +201,6 @@ function Kue705FO({
|
||||
} */
|
||||
//-------------------------------------------------
|
||||
let slot = slotIndex;
|
||||
const alarmStatus =
|
||||
(window.kueAlarm1 && window.kueAlarm1[slotIndex]) ||
|
||||
(window.kueAlarm2 && window.kueAlarm2[slotIndex]) ||
|
||||
(window.kueCableBreak && window.kueCableBreak[slotIndex]) ||
|
||||
(window.kueGroundFault && window.kueGroundFault[slotIndex]);
|
||||
|
||||
if (slot >= 32) {
|
||||
return;
|
||||
@@ -297,6 +293,23 @@ function Kue705FO({
|
||||
useEffect(() => {
|
||||
setCurrentDisplayValue(schleifenwiderstand);
|
||||
}, [schleifenwiderstand]);
|
||||
useEffect(() => {
|
||||
const updateAlarmStatus = () => {
|
||||
const alarmStatus =
|
||||
(window.kueAlarm1 && window.kueAlarm1[slotIndex]) ||
|
||||
(window.kueAlarm2 && window.kueAlarm2[slotIndex]) ||
|
||||
(window.kueCableBreak && window.kueCableBreak[slotIndex]) ||
|
||||
(window.kueGroundFault && window.kueGroundFault[slotIndex]);
|
||||
|
||||
setCurrentAlarmStatus(alarmStatus); // Aktualisiere den Alarmstatus
|
||||
};
|
||||
|
||||
// Aktualisierung sofort und alle 5 Sekunden
|
||||
updateAlarmStatus();
|
||||
const interval = setInterval(updateAlarmStatus, 5000);
|
||||
|
||||
return () => clearInterval(interval); // Bereinigung bei Entladen der Komponente
|
||||
}, [slotIndex]);
|
||||
|
||||
return (
|
||||
<div className="relative bg-gray-300 w-[116px] h-[390px] border border-gray-400 scale-110 top-3">
|
||||
|
||||
Reference in New Issue
Block a user