fix: honor auth modal refresh and submit actions
This commit is contained in:
@@ -1000,6 +1000,26 @@ async function loginWithForm() {
|
||||
});
|
||||
}
|
||||
|
||||
async function refreshFromAuthModal() {
|
||||
const modal = document.querySelector(".auth-modal-backdrop");
|
||||
const visible = modal && !modal.classList.contains("hidden");
|
||||
if (!visible) {
|
||||
await bootstrap();
|
||||
return;
|
||||
}
|
||||
const auth = readAuthForm();
|
||||
const hasAnyInlineAuth = Boolean(auth.token || auth.username || auth.password);
|
||||
const hasInlineAuth = Boolean(auth.token || (auth.username && auth.password));
|
||||
if (hasAnyInlineAuth && !hasInlineAuth) {
|
||||
throw new Error("请填写账号密码,或者直接填 Token");
|
||||
}
|
||||
if (hasInlineAuth) {
|
||||
await loginWithForm();
|
||||
closeAuthModal();
|
||||
}
|
||||
await bootstrap();
|
||||
}
|
||||
|
||||
async function logoutSession() {
|
||||
try {
|
||||
if (appState.session) {
|
||||
@@ -5352,8 +5372,19 @@ document.addEventListener("click", async (event) => {
|
||||
return;
|
||||
}
|
||||
if (name === "submit-auth") {
|
||||
// Auth form submission is handled centrally so clicking the submit
|
||||
// button and pressing Enter share the same code path.
|
||||
setBusy(true, "正在登录并加载...");
|
||||
try {
|
||||
const message = document.querySelector('[data-role="auth-message"]');
|
||||
if (message) message.textContent = "";
|
||||
await loginWithForm();
|
||||
closeAuthModal();
|
||||
await bootstrap();
|
||||
} catch (error) {
|
||||
const message = document.querySelector('[data-role="auth-message"]');
|
||||
if (message) message.textContent = error.message;
|
||||
} finally {
|
||||
setBusy(false, "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (name === "show-disabled-reason") {
|
||||
@@ -5364,7 +5395,25 @@ document.addEventListener("click", async (event) => {
|
||||
return;
|
||||
}
|
||||
if (name === "auth-refresh" || name === "refresh-data") {
|
||||
await bootstrap();
|
||||
setBusy(true, name === "auth-refresh" ? "正在连接并刷新..." : "正在刷新数据...");
|
||||
try {
|
||||
if (name === "auth-refresh") {
|
||||
const message = document.querySelector('[data-role="auth-message"]');
|
||||
if (message) message.textContent = "";
|
||||
await refreshFromAuthModal();
|
||||
} else {
|
||||
await bootstrap();
|
||||
}
|
||||
} catch (error) {
|
||||
const message = document.querySelector('[data-role="auth-message"]');
|
||||
if (name === "auth-refresh" && message) {
|
||||
message.textContent = error.message;
|
||||
} else {
|
||||
alert("刷新数据失败: " + error.message);
|
||||
}
|
||||
} finally {
|
||||
setBusy(false, "");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (name === "refresh-tracking") {
|
||||
|
||||
Reference in New Issue
Block a user