refactor(admin): remove legacy admin fallback page and routing
This commit is contained in:
@@ -6,7 +6,7 @@ import json
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from flask import Blueprint, current_app, redirect, render_template, request, session, url_for
|
||||
from flask import Blueprint, current_app, redirect, render_template, session, url_for
|
||||
from flask_login import current_user, login_required
|
||||
|
||||
from routes.decorators import admin_required
|
||||
@@ -72,13 +72,6 @@ def _get_asset_build_id(static_root: str, rel_paths: list[str]) -> Optional[str]
|
||||
return str(int(max(mtimes)))
|
||||
|
||||
|
||||
def _is_legacy_admin_user_agent(user_agent: str) -> bool:
|
||||
if not user_agent:
|
||||
return False
|
||||
ua = user_agent.lower()
|
||||
return "msie" in ua or "trident/" in ua
|
||||
|
||||
|
||||
@pages_bp.route("/")
|
||||
def index():
|
||||
"""主页 - 重定向到登录或应用"""
|
||||
@@ -125,8 +118,6 @@ def admin_login_page():
|
||||
@admin_required
|
||||
def admin_page():
|
||||
"""后台管理页面"""
|
||||
if request.args.get("legacy") == "1" or _is_legacy_admin_user_agent(request.headers.get("User-Agent", "")):
|
||||
return render_template("admin_legacy.html")
|
||||
logger = get_logger()
|
||||
manifest_path = os.path.join(current_app.root_path, "static", "admin", ".vite", "manifest.json")
|
||||
try:
|
||||
@@ -138,8 +129,8 @@ def admin_page():
|
||||
css_files = entry.get("css") or []
|
||||
|
||||
if not js_file:
|
||||
logger.warning(f"[admin_spa] manifest缺少入口文件: {manifest_path}")
|
||||
return render_template("admin_legacy.html")
|
||||
logger.error(f"[admin_spa] manifest缺少入口文件: {manifest_path}")
|
||||
return "后台前端资源缺失,请重新构建管理端", 503
|
||||
|
||||
admin_spa_js_file = f"admin/{js_file}"
|
||||
admin_spa_css_files = [f"admin/{p}" for p in css_files]
|
||||
@@ -155,8 +146,8 @@ def admin_page():
|
||||
admin_spa_build_id=admin_spa_build_id,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
logger.warning(f"[admin_spa] 未找到manifest: {manifest_path},回退旧版后台模板")
|
||||
return render_template("admin_legacy.html")
|
||||
logger.error(f"[admin_spa] 未找到manifest: {manifest_path}")
|
||||
return "后台前端资源未构建,请联系管理员", 503
|
||||
except Exception as e:
|
||||
logger.error(f"[admin_spa] 加载manifest失败: {e}")
|
||||
return render_template("admin_legacy.html")
|
||||
return "后台页面加载失败,请稍后重试", 500
|
||||
|
||||
@@ -14,34 +14,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<noscript>该页面需要启用 JavaScript 才能使用。</noscript>
|
||||
<script>
|
||||
(function () {
|
||||
var search = window.location.search || ''
|
||||
if (search.indexOf('legacy=1') !== -1) {
|
||||
return
|
||||
}
|
||||
var needsLegacy = false
|
||||
try {
|
||||
new Function('let a = 1; const b = 2;')
|
||||
} catch (e) {
|
||||
needsLegacy = true
|
||||
}
|
||||
if (!window.Promise || !window.Proxy) {
|
||||
needsLegacy = true
|
||||
}
|
||||
if (needsLegacy) {
|
||||
var href = window.location.href
|
||||
var hash = ''
|
||||
var hashIndex = href.indexOf('#')
|
||||
if (hashIndex !== -1) {
|
||||
hash = href.slice(hashIndex)
|
||||
href = href.slice(0, hashIndex)
|
||||
}
|
||||
var sep = href.indexOf('?') !== -1 ? '&' : '?'
|
||||
window.location.replace(href + sep + 'legacy=1' + hash)
|
||||
}
|
||||
})()
|
||||
</script>
|
||||
<div id="app"></div>
|
||||
{% if admin_spa_build_id %}
|
||||
<script type="module" src="{{ url_for('serve_static', filename=admin_spa_js_file, v=admin_spa_build_id) }}"></script>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user