- 拆分应用工厂、业务服务与路由,保留原有 HTTP/SSE 和存储入口 - 分离页面资源,重排客服工作台并完善响应式导航、草稿和附件交互 - 整理维护脚本、请求示例和贡献指南,移除启动脚本中的密钥配置 - 上传文件改为仅本地保留,补充隔离的后端与前端回归验证 验证:46 项 Python 测试通过,含 14 个已有子测试;12 个 Node 前端场景通过。
59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
const loginForm = document.getElementById("loginForm");
|
|
const loginButton = document.getElementById("loginButton");
|
|
const userInput = document.getElementById("user");
|
|
const passwordInput = document.getElementById("pwd");
|
|
const loginError = document.getElementById("err");
|
|
let loginPending = false;
|
|
|
|
function showLoginError(message){
|
|
loginError.textContent = message;
|
|
loginError.hidden = false;
|
|
}
|
|
|
|
async function login(){
|
|
if(loginPending) return;
|
|
const username = userInput.value.trim();
|
|
const password = passwordInput.value;
|
|
userInput.setAttribute("aria-invalid", String(!username));
|
|
passwordInput.setAttribute("aria-invalid", String(!password));
|
|
if(!username || !password){
|
|
showLoginError("请输入客服账号和登录密码");
|
|
(!username ? userInput : passwordInput).focus();
|
|
return;
|
|
}
|
|
loginPending = true;
|
|
loginError.hidden = true;
|
|
loginButton.disabled = true;
|
|
loginButton.textContent = "正在登录…";
|
|
loginForm.setAttribute("aria-busy", "true");
|
|
try{
|
|
const response = await fetch("/admin/login", {
|
|
method: "POST", headers: {"Content-Type": "application/json"},
|
|
body: JSON.stringify({username: username, password: password})
|
|
});
|
|
if(response.ok){
|
|
location.href = "/admin/dashboard";
|
|
return;
|
|
}
|
|
showLoginError(response.status === 401 ? "账号或密码不正确,请重新输入" : "暂时无法登录,请稍后重试");
|
|
}catch(error){
|
|
showLoginError("网络连接失败,请检查网络后重试");
|
|
}finally{
|
|
loginPending = false;
|
|
loginButton.disabled = false;
|
|
loginButton.textContent = "登录工作台 →";
|
|
loginForm.removeAttribute("aria-busy");
|
|
}
|
|
}
|
|
|
|
loginForm.addEventListener("submit", function(event){
|
|
event.preventDefault();
|
|
login();
|
|
});
|
|
[userInput, passwordInput].forEach(function(input){
|
|
input.addEventListener("input", function(){
|
|
loginError.hidden = true;
|
|
input.removeAttribute("aria-invalid");
|
|
});
|
|
});
|