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:
dekun
2026-06-24 01:13:34 +08:00
parent 157d9ada21
commit 4ad335ca84
15 changed files with 2711 additions and 31 deletions
+20 -4
View File
@@ -6702,7 +6702,7 @@ def sync_trade_records_from_exchange(conn, force=False):
# ====================== 主页面 ======================
def render_main_page(page="trade"):
def render_main_page(page="trade", embed_mode=None):
now = app_now()
trading_day = get_trading_day(now)
list_window = _list_window_from_request()
@@ -6726,7 +6726,10 @@ def render_main_page(page="trade"):
for o in raw_order_list:
order_list.append(enrich_order_item(row_to_dict(o), current_capital))
exchange_pnl_sync = {}
if exchange_private_api_configured() and not request_is_hub_soft_nav():
if exchange_private_api_configured() and not request_is_hub_soft_nav() and embed_mode not in (
"fragment",
"shell",
):
try:
exchange_pnl_sync = sync_trade_records_from_exchange(conn) or {}
except Exception as e:
@@ -6786,8 +6789,9 @@ def render_main_page(page="trade"):
trend_cfg=app.extensions.get("strategy_trend_cfg"),
)
conn.close()
return render_template(
"index.html",
from instance_embed_lib import embed_context_extras
template_ctx = dict(
page=page,
key=key_list,
key_history=key_history,
@@ -6859,7 +6863,17 @@ def render_main_page(page="trade"):
kline_timeframe=KLINE_TIMEFRAME,
exchange_pnl_sync=exchange_pnl_sync,
**strategy_extra,
**embed_context_extras("gate"),
)
if embed_mode == "fragment":
return render_template("embed_page_fragment.html", **template_ctx)
if embed_mode == "shell":
return render_template(
"embed_shell.html",
initial_tab=page,
**template_ctx,
)
return render_template("index.html", **template_ctx)
@app.route("/api/sync_exchange_pnl")
@@ -9321,6 +9335,8 @@ try:
reconcile_hub_flat_fn=reconcile_hub_external_close,
risk_status_fn=hub_account_risk_status,
user_close_fn=hub_user_initiated_close,
render_main_page_fn=render_main_page,
login_required_fn=login_required,
)
except Exception as _hub_err:
print(f"[hub_bridge] gate: {_hub_err}")