Add hub iframe embed shell with tab fragment API.
Replace full-page soft nav with a persistent shell and /api/embed/page loads so tab switches in the hub iframe avoid document.write flicker. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+33
-16
@@ -59,6 +59,9 @@ def install_instance_theme_static(app) -> None:
|
||||
"form_submit_guard.js": "application/javascript; charset=utf-8",
|
||||
"key_monitor_form.js": "application/javascript; charset=utf-8",
|
||||
"time_close_ui.js": "application/javascript; charset=utf-8",
|
||||
"manual_order_rr_preview.js": "application/javascript; charset=utf-8",
|
||||
"instance_page.css": "text/css; charset=utf-8",
|
||||
"instance_embed.js": "application/javascript; charset=utf-8",
|
||||
"focus_chart_page.js": "application/javascript; charset=utf-8",
|
||||
"focus_chart_page.css": "text/css; charset=utf-8",
|
||||
}
|
||||
@@ -201,6 +204,19 @@ def _hub_json(view_name: str, path: str, form=None):
|
||||
return jsonify({"ok": False, "messages": [str(e)]})
|
||||
|
||||
|
||||
def _embed_login_dest(next_path: str) -> str:
|
||||
"""embed=1 时把 /trade 等映射到 /embed?tab=…"""
|
||||
ht = (request.args.get("hub_theme") or "").strip().lower()
|
||||
hub_theme = ht if ht in ("light", "dark") else None
|
||||
if request.args.get("embed", "").strip().lower() in ("1", "true", "yes", "on"):
|
||||
from instance_embed_lib import rewrite_embed_dest
|
||||
|
||||
return rewrite_embed_dest(next_path, hub_theme=hub_theme)
|
||||
if hub_theme:
|
||||
return _merge_query_into_path(next_path, hub_theme=hub_theme)
|
||||
return next_path
|
||||
|
||||
|
||||
def install_on_app(
|
||||
app,
|
||||
*,
|
||||
@@ -218,6 +234,8 @@ def install_on_app(
|
||||
reconcile_hub_flat_fn=None,
|
||||
risk_status_fn=None,
|
||||
user_close_fn=None,
|
||||
render_main_page_fn=None,
|
||||
login_required_fn=None,
|
||||
):
|
||||
app.config["HUB_CTX"] = {
|
||||
"exchange": exchange,
|
||||
@@ -239,6 +257,14 @@ def install_on_app(
|
||||
configure_hub_embed_session(app)
|
||||
install_instance_theme_static(app)
|
||||
register_hub_routes(app)
|
||||
if render_main_page_fn and login_required_fn:
|
||||
import os
|
||||
|
||||
from instance_embed_lib import attach_embed_templates, register_embed_routes
|
||||
|
||||
repo_root = os.path.dirname(os.path.abspath(__file__))
|
||||
attach_embed_templates(app, repo_root)
|
||||
register_embed_routes(app, login_required_fn, render_main_page_fn)
|
||||
|
||||
|
||||
def configure_hub_embed_session(app):
|
||||
@@ -797,25 +823,22 @@ def register_hub_routes(app):
|
||||
token = (request.args.get("token") or "").strip()
|
||||
ok, next_path, err = verify_hub_sso_token(token, ex)
|
||||
if ok:
|
||||
dest_next = _embed_login_dest(next_path) if request.args.get(
|
||||
"embed", ""
|
||||
).strip().lower() in ("1", "true", "yes", "on") else next_path
|
||||
if _sso_wants_embed_auth() and request.is_secure:
|
||||
boot = mint_hub_embed_bootstrap(ex, next_path)
|
||||
boot = mint_hub_embed_bootstrap(ex, dest_next)
|
||||
if boot:
|
||||
from urllib.parse import urlencode as _ue
|
||||
|
||||
qdict = {"t": boot, "next": next_path, "embed": "1"}
|
||||
qdict = {"t": boot, "next": dest_next, "embed": "1"}
|
||||
ht0 = (request.args.get("hub_theme") or "").strip().lower()
|
||||
if ht0 in ("light", "dark"):
|
||||
qdict["hub_theme"] = ht0
|
||||
return redirect(f"/hub-embed-auth?{_ue(qdict)}")
|
||||
session["logged_in"] = True
|
||||
session.modified = True
|
||||
dest = next_path
|
||||
if request.args.get("embed", "").strip().lower() in ("1", "true", "yes", "on"):
|
||||
dest = _merge_query_into_path(dest, embed="1")
|
||||
ht = (request.args.get("hub_theme") or "").strip().lower()
|
||||
if ht in ("light", "dark"):
|
||||
dest = _merge_query_into_path(dest, hub_theme=ht)
|
||||
return redirect(dest)
|
||||
return redirect(_embed_login_dest(next_path))
|
||||
hint = err or "校验失败"
|
||||
flash(
|
||||
f"中控 SSO 未生效({hint})。"
|
||||
@@ -839,13 +862,7 @@ def register_hub_routes(app):
|
||||
if ok:
|
||||
session["logged_in"] = True
|
||||
session.modified = True
|
||||
dest = next_path
|
||||
if request.args.get("embed", "").strip().lower() in ("1", "true", "yes", "on"):
|
||||
dest = _merge_query_into_path(dest, embed="1")
|
||||
ht = (request.args.get("hub_theme") or "").strip().lower()
|
||||
if ht in ("light", "dark"):
|
||||
dest = _merge_query_into_path(dest, hub_theme=ht)
|
||||
return redirect(dest)
|
||||
return redirect(_embed_login_dest(next_path))
|
||||
hint = err or "校验失败"
|
||||
flash(f"iframe 登录未生效({hint})。可点本地导航工具栏「实例免密」重试。")
|
||||
return redirect("/login")
|
||||
|
||||
Reference in New Issue
Block a user