You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

58 lines
2.1 KiB

let loginToastTimer = null;
function showLoginToast(msg, isSuccess = false) {
let toast = document.getElementById("login-toast");
if (!toast) {
toast = document.createElement("div");
toast.id = "login-toast";
toast.style.position = "fixed";
toast.style.top = "20px";
toast.style.right = "20px";
toast.style.left = "auto";
toast.style.transform = "none";
toast.style.minWidth = "220px";
toast.style.maxWidth = "80vw";
toast.style.background = isSuccess ? "linear-gradient(90deg,#7ec6f7,#b2f7ef)" : "#fff";
toast.style.color = isSuccess ? "#1976d2" : "#ff4d4f";
toast.style.fontSize = "1.08rem";
toast.style.fontWeight = "600";
toast.style.padding = "1.1em 2.2em";
toast.style.borderRadius = "18px";
toast.style.boxShadow = "0 4px 24px rgba(30,136,229,0.13),0 1.5px 8px rgba(79,209,255,0.08)";
toast.style.zIndex = 9999;
toast.style.textAlign = "center";
toast.style.opacity = "0";
toast.style.transition = "opacity 0.2s";
document.body.appendChild(toast);
}
toast.textContent = msg;
toast.style.opacity = "1";
if (loginToastTimer) clearTimeout(loginToastTimer);
loginToastTimer = setTimeout(() => {
toast.style.opacity = "0";
setTimeout(() => {
toast.remove();
}, 300);
loginToastTimer = null;
}, 2000);
}
const loginForm = document.getElementById("login-form")
loginForm.onsubmit = async function (e) {
e.preventDefault()
const form = e.target
const data = Object.fromEntries(new FormData(form))
const res = await fetch(form.action, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
})
const result = await res.json()
if (result.success) {
showLoginToast("登录成功,2秒后跳转到首页", true)
setTimeout(() => {
window.location.href = "/"
}, 2000)
} else {
showLoginToast(result.message || "登录失败")
}
}