|
106 | 106 | flex-wrap: wrap; |
107 | 107 | } |
108 | 108 |
|
| 109 | + .auth-status { |
| 110 | + max-width: 260px; |
| 111 | + overflow: hidden; |
| 112 | + text-overflow: ellipsis; |
| 113 | + } |
| 114 | + |
109 | 115 | .shell { |
110 | 116 | width: min(1160px, calc(100vw - 36px)); |
111 | 117 | margin: 0 auto; |
@@ -526,7 +532,9 @@ <h1 data-i18n="appTitle">策略切换</h1> |
526 | 532 | <p data-i18n="appSubtitle">选平台、目标账号和策略,一次执行完成切换。</p> |
527 | 533 | </div> |
528 | 534 | <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> |
530 | 538 | </div> |
531 | 539 | </header> |
532 | 540 |
|
@@ -659,7 +667,9 @@ <h2 data-i18n="summary">切换摘要</h2> |
659 | 667 | zh: { |
660 | 668 | appTitle: "策略切换", |
661 | 669 | appSubtitle: "选平台、目标账号和策略,一次执行完成切换。", |
662 | | - loginManage: "登录管理", |
| 670 | + login: "登录", |
| 671 | + logout: "退出", |
| 672 | + signedInAs: "已登录 {login}", |
663 | 673 | activePlatform: "当前平台", |
664 | 674 | account: "目标账号", |
665 | 675 | strategy: "策略", |
@@ -694,7 +704,9 @@ <h2 data-i18n="summary">切换摘要</h2> |
694 | 704 | en: { |
695 | 705 | appTitle: "Strategy Switch", |
696 | 706 | 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}", |
698 | 710 | activePlatform: "Active Platform", |
699 | 711 | account: "Target account", |
700 | 712 | strategy: "Strategy", |
@@ -903,24 +915,18 @@ <h2 data-i18n="summary">切换摘要</h2> |
903 | 915 | } |
904 | 916 |
|
905 | 917 | 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"); |
924 | 930 |
|
925 | 931 | const dispatch = el("dispatch-button"); |
926 | 932 | const hasPrivateAccounts = state.configSource === "private"; |
@@ -1016,9 +1022,7 @@ <h2 data-i18n="summary">切换摘要</h2> |
1016 | 1022 | } |
1017 | 1023 | } |
1018 | 1024 |
|
1019 | | - async function handleAccountLink(event) { |
1020 | | - if (el("account-link").dataset.action !== "logout") return; |
1021 | | - event.preventDefault(); |
| 1025 | + async function handleLogout() { |
1022 | 1026 | await fetch("/api/logout", { method: "POST" }); |
1023 | 1027 | window.location.reload(); |
1024 | 1028 | } |
@@ -1074,7 +1078,7 @@ <h2 data-i18n="summary">切换摘要</h2> |
1074 | 1078 | }); |
1075 | 1079 |
|
1076 | 1080 | el("dispatch-button").addEventListener("click", dispatchSwitch); |
1077 | | - el("account-link").addEventListener("click", handleAccountLink); |
| 1081 | + el("logout-button").addEventListener("click", handleLogout); |
1078 | 1082 |
|
1079 | 1083 | render(); |
1080 | 1084 | refreshSession(); |
|
0 commit comments