diff --git a/manual_trading_hub/static/app.js b/manual_trading_hub/static/app.js index a5127ae..943c418 100644 --- a/manual_trading_hub/static/app.js +++ b/manual_trading_hub/static/app.js @@ -21,6 +21,32 @@ /** @type {{ exchangeId: string, nextPath: string, title: string } | null} */ let instanceFrameCtx = null; + function isHubEmbedded() { + try { + return window.self !== window.top; + } catch (_) { + return true; + } + } + + function delegateInstanceToParent(url, title, exchangeId, nextPath) { + try { + window.parent.postMessage( + { + type: "hub:open-instance", + url, + title: title || "实例", + exchangeId: String(exchangeId), + nextPath: nextPath || "/", + }, + "*" + ); + return true; + } catch (_) { + return false; + } + } + async function fetchInstanceOpenUrl(exchangeId, nextPath) { const next = nextPath || "/"; const q = new URLSearchParams({ exchange_id: String(exchangeId), next }); @@ -45,6 +71,9 @@ const row = lastMonitorRows.find((x) => String(x.id) === String(exchangeId)); const title = row ? row.name : exchangeId; instanceFrameCtx = { exchangeId: String(exchangeId), nextPath: next, title }; + if (isHubEmbedded() && delegateInstanceToParent(url, title, exchangeId, next)) { + return; + } openInstanceFrame(url, title); } catch (e) { showToast(String(e), true); diff --git a/manual_trading_hub/static/index.html b/manual_trading_hub/static/index.html index bd46314..dbbf05b 100644 --- a/manual_trading_hub/static/index.html +++ b/manual_trading_hub/static/index.html @@ -120,6 +120,6 @@
- +