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,
"name": "渠道应用开发部知识库",
"version": "1.2.1",
"version": "1.3",
"description": "通过关键词快速搜索内部文档",
"permissions": ["storage"],
"host_permissions": [

View File

@ -14,5 +14,7 @@
});
</script>
</head>
<body></body>
<body>
<div style="padding: 1rem; font-size: 14px;">正在加载,请稍候...</div>
</body>
</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 password = document.getElementById("password").value.trim();
const errorBox = document.getElementById("errorBox");
@ -11,32 +14,26 @@ document.getElementById("loginBtn").addEventListener("click", async () => {
return;
}
try {
const res = await fetch("http://app.wisdompulse.cn/api/v1/user/login", {
fetch("http://app.wisdompulse.cn/api/v1/user/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username, password })
});
const data = await res.json();
if (res.ok && data.token) {
await chrome.storage.local.set({
token: data.token,
username: data.username || username,
})
.then(res => res.json().then(data => ({ status: res.status, body: data })))
.then(({ status, body }) => {
if (status === 200 && body.token) {
chrome.storage.local.set({
token: body.token,
username: body.username || username,
loginAt: Date.now()
}, () => {
window.location.href = chrome.runtime.getURL("pages/popup.html");
});
chrome.action.setPopup({ popup: "popup.html" });
window.location.href = "popup.html";
} else {
errorBox.textContent = data.message || "登录失败";
errorBox.textContent = body.message || "登录失败";
}
} catch (err) {
})
.catch(() => {
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() {
log("执行退出登录逻辑");
chrome.storage.local.remove(["token", "loginAt", "username"], () => {
chrome.action.setPopup({ popup: "login.html" });
window.location.href = "login.html";
window.location.href = chrome.runtime.getURL("pages/login.html");
});
}
function showLoading() {
resultBox.innerHTML = "<li>加载中...</li>";
}