Skip to content

Commit 069983c

Browse files
authored
Simplify strategy switch auth controls (#12)
1 parent 80e6863 commit 069983c

2 files changed

Lines changed: 30 additions & 26 deletions

File tree

docs/index.html

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@
106106
flex-wrap: wrap;
107107
}
108108

109+
.auth-status {
110+
max-width: 260px;
111+
overflow: hidden;
112+
text-overflow: ellipsis;
113+
}
114+
109115
.shell {
110116
width: min(1160px, calc(100vw - 36px));
111117
margin: 0 auto;
@@ -526,7 +532,9 @@ <h1 data-i18n="appTitle">策略切换</h1>
526532
<p data-i18n="appSubtitle">选平台、目标账号和策略,一次执行完成切换。</p>
527533
</div>
528534
<div class="top-actions">
529-
<a class="btn" id="account-link" href="https://github.com/QuantStrategyLab/QuantRuntimeSettings/tree/main/web/strategy-switch-console" data-i18n="loginManage">登录管理</a>
535+
<span class="pill ready auth-status" id="auth-status" hidden></span>
536+
<a class="btn" id="login-link" href="/login" hidden data-i18n="login">登录</a>
537+
<button class="btn" id="logout-button" type="button" hidden data-i18n="logout">退出</button>
530538
</div>
531539
</header>
532540

@@ -659,7 +667,9 @@ <h2 data-i18n="summary">切换摘要</h2>
659667
zh: {
660668
appTitle: "策略切换",
661669
appSubtitle: "选平台、目标账号和策略,一次执行完成切换。",
662-
loginManage: "登录管理",
670+
login: "登录",
671+
logout: "退出",
672+
signedInAs: "已登录 {login}",
663673
activePlatform: "当前平台",
664674
account: "目标账号",
665675
strategy: "策略",
@@ -694,7 +704,9 @@ <h2 data-i18n="summary">切换摘要</h2>
694704
en: {
695705
appTitle: "Strategy Switch",
696706
appSubtitle: "Pick platform, target account, and strategy. One action switches everything.",
697-
loginManage: "Login Management",
707+
login: "Sign in",
708+
logout: "Sign out",
709+
signedInAs: "Signed in as {login}",
698710
activePlatform: "Active Platform",
699711
account: "Target account",
700712
strategy: "Strategy",
@@ -903,24 +915,18 @@ <h2 data-i18n="summary">切换摘要</h2>
903915
}
904916

905917
function renderAuth() {
906-
const accountLink = el("account-link");
907-
if (!state.auth.available) {
908-
accountLink.href = "https://github.com/QuantStrategyLab/QuantRuntimeSettings/tree/main/web/strategy-switch-console";
909-
accountLink.dataset.action = "setup";
910-
accountLink.textContent = t("loginManage");
911-
} else if (state.auth.admin) {
912-
accountLink.href = "/admin";
913-
accountLink.dataset.action = "admin";
914-
accountLink.textContent = t("loginManage");
915-
} else if (state.auth.allowed) {
916-
accountLink.href = "#logout";
917-
accountLink.dataset.action = "logout";
918-
accountLink.textContent = t("loginManage");
919-
} else {
920-
accountLink.href = "/login";
921-
accountLink.dataset.action = "login";
922-
accountLink.textContent = t("loginManage");
923-
}
918+
const status = el("auth-status");
919+
const loginLink = el("login-link");
920+
const logoutButton = el("logout-button");
921+
const signedIn = Boolean(state.auth.allowed && state.auth.login);
922+
923+
status.hidden = !signedIn;
924+
status.textContent = signedIn ? t("signedInAs").replace("{login}", state.auth.login) : "";
925+
loginLink.hidden = !state.auth.available || signedIn;
926+
loginLink.href = "/login";
927+
loginLink.textContent = t("login");
928+
logoutButton.hidden = !signedIn;
929+
logoutButton.textContent = t("logout");
924930

925931
const dispatch = el("dispatch-button");
926932
const hasPrivateAccounts = state.configSource === "private";
@@ -1016,9 +1022,7 @@ <h2 data-i18n="summary">切换摘要</h2>
10161022
}
10171023
}
10181024

1019-
async function handleAccountLink(event) {
1020-
if (el("account-link").dataset.action !== "logout") return;
1021-
event.preventDefault();
1025+
async function handleLogout() {
10221026
await fetch("/api/logout", { method: "POST" });
10231027
window.location.reload();
10241028
}
@@ -1074,7 +1078,7 @@ <h2 data-i18n="summary">切换摘要</h2>
10741078
});
10751079

10761080
el("dispatch-button").addEventListener("click", dispatchSwitch);
1077-
el("account-link").addEventListener("click", handleAccountLink);
1081+
el("logout-button").addEventListener("click", handleLogout);
10781082

10791083
render();
10801084
refreshSession();

0 commit comments

Comments
 (0)