fix [FIle Not Found] bug

This commit is contained in:
luke 2025-05-27 14:14:20 +08:00
parent d691e1ce85
commit 23aa18fafe
4 changed files with 34 additions and 36 deletions

View File

@ -1,7 +1,7 @@
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "渠道应用开发部知识库", "name": "渠道应用开发部知识库",
"version": "1.2.1", "version": "1.3",
"description": "通过关键词快速搜索内部文档", "description": "通过关键词快速搜索内部文档",
"permissions": ["storage"], "permissions": ["storage"],
"host_permissions": [ "host_permissions": [

View File

@ -14,5 +14,7 @@
}); });
</script> </script>
</head> </head>
<body></body> <body>
<div style="padding: 1rem; font-size: 14px;">正在加载,请稍候...</div>
</body>
</html> </html>

View File

@ -1,6 +1,9 @@
const TOKEN_EXPIRE_MS = 24 * 60 * 60 * 1000; // 默认保留 1天 document.getElementById("loginBtn").addEventListener("click", doLogin);
document.addEventListener("keydown", (e) => {
if (e.key === "Enter") doLogin();
});
document.getElementById("loginBtn").addEventListener("click", async () => { function doLogin() {
const username = document.getElementById("username").value.trim(); const username = document.getElementById("username").value.trim();
const password = document.getElementById("password").value.trim(); const password = document.getElementById("password").value.trim();
const errorBox = document.getElementById("errorBox"); const errorBox = document.getElementById("errorBox");
@ -11,32 +14,26 @@ document.getElementById("loginBtn").addEventListener("click", async () => {
return; return;
} }
try { fetch("http://app.wisdompulse.cn/api/v1/user/login", {
const res = await fetch("http://app.wisdompulse.cn/api/v1/user/login", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password }) body: JSON.stringify({ username, password })
}); })
.then(res => res.json().then(data => ({ status: res.status, body: data })))
const data = await res.json(); .then(({ status, body }) => {
if (res.ok && data.token) { if (status === 200 && body.token) {
await chrome.storage.local.set({ chrome.storage.local.set({
token: data.token, token: body.token,
username: data.username || username, username: body.username || username,
loginAt: Date.now() loginAt: Date.now()
}, () => {
window.location.href = chrome.runtime.getURL("pages/popup.html");
}); });
chrome.action.setPopup({ popup: "popup.html" });
window.location.href = "popup.html";
} else { } else {
errorBox.textContent = data.message || "登录失败"; errorBox.textContent = body.message || "登录失败";
} }
} catch (err) { })
.catch(() => {
errorBox.textContent = "网络错误,请稍后重试"; errorBox.textContent = "网络错误,请稍后重试";
}
}); });
document.addEventListener("keydown", (e) => {
if (e.key === "Enter") {
document.getElementById("loginBtn").click();
} }
});

View File

@ -43,13 +43,12 @@ document.addEventListener("DOMContentLoaded", async () => {
} }
function handleLogout() { function handleLogout() {
log("执行退出登录逻辑");
chrome.storage.local.remove(["token", "loginAt", "username"], () => { chrome.storage.local.remove(["token", "loginAt", "username"], () => {
chrome.action.setPopup({ popup: "login.html" }); window.location.href = chrome.runtime.getURL("pages/login.html");
window.location.href = "login.html";
}); });
} }
function showLoading() { function showLoading() {
resultBox.innerHTML = "<li>加载中...</li>"; resultBox.innerHTML = "<li>加载中...</li>";
} }