修复中控

This commit is contained in:
dekun
2026-05-30 12:13:33 +08:00
parent acbd9576bc
commit c882a5e565
6 changed files with 94 additions and 18 deletions
+47 -14
View File
@@ -18,25 +18,55 @@
}
let instanceFrameUrl = "";
/** @type {{ exchangeId: string, nextPath: string, title: string } | null} */
let instanceFrameCtx = null;
async function fetchInstanceOpenUrl(exchangeId, nextPath) {
const next = nextPath || "/";
const q = new URLSearchParams({ exchange_id: String(exchangeId), next });
const r = await apiFetch("/api/instance/open-url?" + q.toString());
const j = await r.json();
if (!j.ok || !j.url) {
throw new Error(j.detail || "无法生成打开链接");
}
return j.url;
}
async function openInstance(exchangeId, nextPath, opts) {
const options = opts || {};
const newTab = !!options.newTab;
const next = nextPath || "/";
try {
const q = new URLSearchParams({ exchange_id: String(exchangeId), next });
const r = await apiFetch("/api/instance/open-url?" + q.toString());
const j = await r.json();
if (!j.ok || !j.url) {
showToast(j.detail || "无法生成打开链接", true);
return;
}
const url = await fetchInstanceOpenUrl(exchangeId, next);
if (newTab) {
window.open(j.url, "_blank", "noopener");
window.open(url, "_blank", "noopener");
return;
}
const row = lastMonitorRows.find((x) => String(x.id) === String(exchangeId));
openInstanceFrame(j.url, row ? row.name : exchangeId);
const title = row ? row.name : exchangeId;
instanceFrameCtx = { exchangeId: String(exchangeId), nextPath: next, title };
openInstanceFrame(url, title);
} catch (e) {
showToast(String(e), true);
}
}
async function refreshInstanceFrame() {
if (!instanceFrameCtx) {
if (instanceFrameUrl) {
const frame = document.getElementById("instance-frame");
if (frame) frame.src = instanceFrameUrl;
}
return;
}
try {
const url = await fetchInstanceOpenUrl(
instanceFrameCtx.exchangeId,
instanceFrameCtx.nextPath
);
instanceFrameUrl = url;
const frame = document.getElementById("instance-frame");
if (frame) frame.src = url;
} catch (e) {
showToast(String(e), true);
}
@@ -63,6 +93,7 @@
const shell = document.getElementById("instance-frame-shell");
const frame = document.getElementById("instance-frame");
instanceFrameUrl = "";
instanceFrameCtx = null;
if (frame) frame.src = "about:blank";
if (shell) {
shell.classList.add("hidden");
@@ -979,13 +1010,15 @@
const newTab = document.getElementById("instance-frame-newtab");
const frame = document.getElementById("instance-frame");
if (back) back.onclick = () => closeInstanceFrame();
if (refresh && frame) {
refresh.onclick = () => {
if (instanceFrameUrl) frame.src = instanceFrameUrl;
};
}
if (refresh) refresh.onclick = () => refreshInstanceFrame();
if (newTab) {
newTab.onclick = () => {
if (instanceFrameCtx) {
openInstance(instanceFrameCtx.exchangeId, instanceFrameCtx.nextPath, {
newTab: true,
});
return;
}
if (instanceFrameUrl) window.open(instanceFrameUrl, "_blank", "noopener");
};
}
+1 -1
View File
@@ -120,6 +120,6 @@
</div>
<div id="toast"></div>
<script src="/assets/app.js?v=20260530-hub-iframe"></script>
<script src="/assets/app.js?v=20260530-hub-sso-fix"></script>
</body>
</html>