fix: 修复所有弹窗打开后无法关闭的问题 - 重写closeModal先关闭再清理并try-catch容错 - 首页路由加no-store响应头避免浏览器缓存旧HTML

This commit is contained in:
2026-08-07 15:26:10 +08:00
parent 0fe2a2fc5f
commit b0f808fb8c
2 changed files with 22 additions and 10 deletions
+17 -8
View File
@@ -452,6 +452,11 @@ async function stopSelectedDevices(){
setTimeout(loadMonitor,500); setTimeout(loadMonitor,500);
} }
// ================== 设备画面查看 ==================
let _shotTimer=null; // 自动刷新定时器
let _shotSerial=''; // 当前查看的 serial
let _shotLoading=false; // 防止并发请求
// 打开截图弹窗 // 打开截图弹窗
function openScreenshot(serial){ function openScreenshot(serial){
_shotSerial=serial; _shotSerial=serial;
@@ -493,7 +498,8 @@ function startShotTimer(){
_shotTimer=setInterval(refreshShot,3000); _shotTimer=setInterval(refreshShot,3000);
} }
function stopShotTimer(){ 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'); document.getElementById('modal-overlay').classList.add('show');
} }
function closeModal(){ function closeModal(){
// 清理截图弹窗的自动刷新定时器(避免关闭后后台继续请求) // 先关闭弹窗(最重要的一步,确保一定执行)
stopShotTimer(); const ov=document.getElementById('modal-overlay');
_shotSerial=''; if(ov)ov.classList.remove('show');
// 还原弹窗样式(截图弹窗会加 shot-modal,关闭时移除) // 再做清理工作,任何异常都不影响弹窗关闭
const box=document.getElementById('modal-box'); try{
if(box)box.classList.remove('shot-modal'); stopShotTimer();
document.getElementById('modal-overlay').classList.remove('show'); _shotSerial='';
const box=document.getElementById('modal-box');
if(box)box.classList.remove('shot-modal');
}catch(e){console.warn('closeModal cleanup error:',e);}
} }
// ================== 行内按钮操作(停止/执行/启停等,自动 toast + 刷新)================== // ================== 行内按钮操作(停止/执行/启停等,自动 toast + 刷新)==================
+5 -2
View File
@@ -15,7 +15,7 @@
import os import os
import time 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, from flask_login import (LoginManager, login_user, logout_user,
login_required, current_user) login_required, current_user)
@@ -55,7 +55,10 @@ def load_user(user_id):
@login_required @login_required
def index(): 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"]) @app.route("/login", methods=["GET", "POST"])