From b0f808fb8c996c92f93aaabe161136b1862b9eaf Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Fri, 7 Aug 2026 15:26:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=89=80=E6=9C=89?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E6=89=93=E5=BC=80=E5=90=8E=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E7=9A=84=E9=97=AE=E9=A2=98=20-=20=E9=87=8D?= =?UTF-8?q?=E5=86=99closeModal=E5=85=88=E5=85=B3=E9=97=AD=E5=86=8D?= =?UTF-8?q?=E6=B8=85=E7=90=86=E5=B9=B6try-catch=E5=AE=B9=E9=94=99=20-=20?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E8=B7=AF=E7=94=B1=E5=8A=A0no-store=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E5=A4=B4=E9=81=BF=E5=85=8D=E6=B5=8F=E8=A7=88=E5=99=A8?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=97=A7HTML?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/admin/monitor.html | 25 +++++++++++++++++-------- web_server.py | 7 +++++-- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/templates/admin/monitor.html b/templates/admin/monitor.html index 388511e..6f3756c 100644 --- a/templates/admin/monitor.html +++ b/templates/admin/monitor.html @@ -452,6 +452,11 @@ async function stopSelectedDevices(){ setTimeout(loadMonitor,500); } +// ================== 设备画面查看 ================== +let _shotTimer=null; // 自动刷新定时器 +let _shotSerial=''; // 当前查看的 serial +let _shotLoading=false; // 防止并发请求 + // 打开截图弹窗 function openScreenshot(serial){ _shotSerial=serial; @@ -493,7 +498,8 @@ function startShotTimer(){ _shotTimer=setInterval(refreshShot,3000); } function stopShotTimer(){ - if(_shotTimer){clearInterval(_shotTimer);_shotTimer=null;} + // 用 typeof 容错:变量未声明时不报错(避免 closeModal 调用时抛异常导致弹窗关不掉) + if(typeof _shotTimer!=='undefined'&&_shotTimer){clearInterval(_shotTimer);_shotTimer=null;} } // 取一次截图 @@ -1311,13 +1317,16 @@ function showModal(){ document.getElementById('modal-overlay').classList.add('show'); } function closeModal(){ - // 清理截图弹窗的自动刷新定时器(避免关闭后后台继续请求) - stopShotTimer(); - _shotSerial=''; - // 还原弹窗样式(截图弹窗会加 shot-modal,关闭时移除) - const box=document.getElementById('modal-box'); - if(box)box.classList.remove('shot-modal'); - document.getElementById('modal-overlay').classList.remove('show'); + // 先关闭弹窗(最重要的一步,确保一定执行) + const ov=document.getElementById('modal-overlay'); + if(ov)ov.classList.remove('show'); + // 再做清理工作,任何异常都不影响弹窗关闭 + try{ + stopShotTimer(); + _shotSerial=''; + const box=document.getElementById('modal-box'); + if(box)box.classList.remove('shot-modal'); + }catch(e){console.warn('closeModal cleanup error:',e);} } // ================== 行内按钮操作(停止/执行/启停等,自动 toast + 刷新)================== diff --git a/web_server.py b/web_server.py index 0a9570d..069e756 100644 --- a/web_server.py +++ b/web_server.py @@ -15,7 +15,7 @@ import os import time -from flask import Flask, jsonify, request, redirect, url_for, render_template, Response +from flask import Flask, jsonify, request, redirect, url_for, render_template, Response, make_response from flask_login import (LoginManager, login_user, logout_user, login_required, current_user) @@ -55,7 +55,10 @@ def load_user(user_id): @login_required def index(): """单页应用首页。""" - return render_template("admin/monitor.html") + resp = make_response(render_template("admin/monitor.html")) + resp.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0" + resp.headers["Pragma"] = "no-cache" + return resp @app.route("/login", methods=["GET", "POST"])