diff --git a/manifest.json b/manifest.json
index c110a52..9ae8053 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "渠道应用开发部知识库",
- "version": "1.2.1",
+ "version": "1.3",
"description": "通过关键词快速搜索内部文档",
"permissions": ["storage"],
"host_permissions": [
diff --git a/pages/index.html b/pages/index.html
index ef0d014..6bf9801 100644
--- a/pages/index.html
+++ b/pages/index.html
@@ -1,7 +1,7 @@
-
+
加载中...
-
+
+ 正在加载,请稍候...
+
diff --git a/pages/login.js b/pages/login.js
index b7ff31d..5e513d6 100644
--- a/pages/login.js
+++ b/pages/login.js
@@ -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", {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify({ username, password })
+ fetch("http://app.wisdompulse.cn/api/v1/user/login", {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ 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();
- }
-});
+}
diff --git a/pages/popup.js b/pages/popup.js
index 5753a38..bffd145 100644
--- a/pages/popup.js
+++ b/pages/popup.js
@@ -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 = "加载中...";
}