feat(app): scaffold Vue3 frontend (stage 1)

This commit is contained in:
2025-12-13 22:42:31 +08:00
parent 39153cc946
commit 34f44eed3e
35 changed files with 2910 additions and 0 deletions

31
app.py
View File

@@ -1241,6 +1241,37 @@ def admin_page():
except Exception as e:
logger.error(f"[admin_spa] 加载manifest失败: {e}")
return render_template('admin_legacy.html')
def render_app_spa_or_legacy(legacy_template_name: str):
"""渲染前台 Vue SPA构建产物位于 static/app失败则回退旧模板。
说明:该函数仅负责“资源注入/回退逻辑”,不改变任何接口与业务流程。
"""
manifest_path = os.path.join(app.root_path, 'static', 'app', '.vite', 'manifest.json')
try:
with open(manifest_path, 'r', encoding='utf-8') as f:
manifest = json.load(f)
entry = manifest.get('index.html') or {}
js_file = entry.get('file')
css_files = entry.get('css') or []
if not js_file:
logger.warning(f"[app_spa] manifest缺少入口文件: {manifest_path}")
return render_template(legacy_template_name)
return render_template(
'app.html',
app_spa_js_file=f'app/{js_file}',
app_spa_css_files=[f'app/{p}' for p in css_files],
)
except FileNotFoundError:
logger.info(f"[app_spa] 未找到manifest: {manifest_path},回退旧模板: {legacy_template_name}")
return render_template(legacy_template_name)
except Exception as e:
logger.error(f"[app_spa] 加载manifest失败: {e}")
return render_template(legacy_template_name)
# ==================== 用户认证API ====================
@app.route('/api/register', methods=['POST'])