fix [FIle Not Found] bug
This commit is contained in:
parent
d691e1ce85
commit
23aa18fafe
@ -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": [
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-CN">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8"/>
|
||||||
<title>加载中...</title>
|
<title>加载中...</title>
|
||||||
<script>
|
<script>
|
||||||
chrome.storage.local.get(["token", "loginAt"], (res) => {
|
chrome.storage.local.get(["token", "loginAt"], (res) => {
|
||||||
@ -14,5 +14,7 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body></body>
|
<body>
|
||||||
|
<div style="padding: 1rem; font-size: 14px;">正在加载,请稍候...</div>
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -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 })))
|
||||||
|
.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");
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
errorBox.textContent = body.message || "登录失败";
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
errorBox.textContent = "网络错误,请稍后重试";
|
||||||
});
|
});
|
||||||
|
}
|
||||||
const data = await res.json();
|
|
||||||
if (res.ok && data.token) {
|
|
||||||
await chrome.storage.local.set({
|
|
||||||
token: data.token,
|
|
||||||
username: data.username || username,
|
|
||||||
loginAt: Date.now()
|
|
||||||
});
|
|
||||||
chrome.action.setPopup({ popup: "popup.html" });
|
|
||||||
window.location.href = "popup.html";
|
|
||||||
} else {
|
|
||||||
errorBox.textContent = data.message || "登录失败";
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
errorBox.textContent = "网络错误,请稍后重试";
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
document.addEventListener("keydown", (e) => {
|
|
||||||
if (e.key === "Enter") {
|
|
||||||
document.getElementById("loginBtn").click();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|||||||
@ -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>";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user