fix: 修复所有弹窗打开后无法关闭的问题 - 重写closeModal先关闭再清理并try-catch容错 - 首页路由加no-store响应头避免浏览器缓存旧HTML
This commit is contained in:
@@ -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 + 刷新)==================
|
||||
|
||||
+5
-2
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user