切换为 Vue SPA 首页,删除旧版静态页面

- server.py: 支持 Vue SPA fallback,根路径优先 VUE_DIST
- router: createWebHistory('/psy/')
- 删除旧版 pages/css/js 目录和根目录 HTML 文件
This commit is contained in:
jackyu66git
2026-08-05 15:05:19 +08:00
parent e589af9bc0
commit b46d651892
35 changed files with 41 additions and 5357 deletions
+40
View File
@@ -5,6 +5,7 @@ from http.server import HTTPServer, SimpleHTTPRequestHandler
from urllib.parse import urlparse, parse_qs
ROOT = os.path.dirname(os.path.abspath(__file__))
VUE_DIST = os.path.join(ROOT, "apps", "user-h5", "dist")
MINDMAP_FILE = os.path.join(ROOT, "mindmap_data.json")
SCALES_FILE = os.path.join(ROOT, "scales_data.json")
RESULTS_DB = os.path.join(ROOT, "scale_results.db")
@@ -432,6 +433,45 @@ class Handler(SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=ROOT, **kwargs)
def translate_path(self, path):
"""Try ROOT first; for unmatched paths, serve Vue SPA from VUE_DIST."""
# Parse the path (strip query string / fragment — already done by parent)
parsed = urlparse(path)
clean = parsed.path
# Root path → Vue SPA index
if clean == '/' or clean == '':
spa_index = os.path.join(VUE_DIST, 'index.html')
if os.path.isfile(spa_index):
return spa_index
# Always try ROOT first (covers old pages, data files, etc.)
root_path = os.path.join(ROOT, clean.lstrip('/'))
if os.path.isfile(root_path):
return root_path
if os.path.isdir(root_path):
for idx in ('index.html', 'index.htm'):
ip = os.path.join(root_path, idx)
if os.path.isfile(ip):
return ip
# Not found in ROOT — serve from Vue dist with SPA fallback
dist_path = os.path.join(VUE_DIST, clean.lstrip('/'))
if os.path.isfile(dist_path):
return dist_path
if os.path.isdir(dist_path):
for idx in ('index.html', 'index.htm'):
ip = os.path.join(dist_path, idx)
if os.path.isfile(ip):
return ip
# SPA fallback: serve dist/index.html for client-side routes
spa_index = os.path.join(VUE_DIST, 'index.html')
if os.path.isfile(spa_index):
return spa_index
return root_path
def end_headers(self):
no_cache_paths = ['/', '/load', '/api/']
if any(self.path == p or self.path.startswith(p) for p in no_cache_paths):