From 64dad6ed635f7b29748a3e37c893ae464bd6259a Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 28 May 2025 23:37:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A7=BB=E9=99=A4AnythingLLM=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=98=8E=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/login.html | 1 + pages/login.js | 15 ++++++++++++++- pages/popup.js | 14 +++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/pages/login.html b/pages/login.html index bdc66c4..6733d5f 100644 --- a/pages/login.html +++ b/pages/login.html @@ -51,6 +51,7 @@
+
diff --git a/pages/login.js b/pages/login.js index d8134f7..718c0d1 100644 --- a/pages/login.js +++ b/pages/login.js @@ -1,3 +1,12 @@ +// 自动回显 AnythingLLM 密码 +document.addEventListener("DOMContentLoaded", function () { + chrome.storage.local.get(["llmPassword"], function (res) { + if (res.llmPassword) { + document.getElementById("llmPassword").value = res.llmPassword; + } + }); +}); + document.getElementById("loginBtn").addEventListener("click", doLogin); document.addEventListener("keydown", (e) => { if (e.key === "Enter") doLogin(); @@ -6,6 +15,7 @@ document.addEventListener("keydown", (e) => { function doLogin() { const username = document.getElementById("username").value.trim(); const password = document.getElementById("password").value.trim(); + const llmPassword = document.getElementById("llmPassword").value; const errorBox = document.getElementById("errorBox"); errorBox.textContent = ""; @@ -14,6 +24,9 @@ function doLogin() { return; } + // 保存 llmPassword(登录不依赖LLM密码是否填写,只是单独存储) + chrome.storage.local.set({ llmPassword }); + fetch("http://app.wisdompulse.cn/api/v1/user/login", { method: "POST", headers: { "Content-Type": "application/json" }, @@ -26,7 +39,7 @@ function doLogin() { chrome.storage.local.set({ token: body.token, username: body.username || username, - loginAt: Date.now() // 毫秒时间戳 + loginAt: Date.now() }, () => { window.location.href = chrome.runtime.getURL("pages/popup.html"); }); diff --git a/pages/popup.js b/pages/popup.js index 7943793..f3bf93e 100644 --- a/pages/popup.js +++ b/pages/popup.js @@ -25,12 +25,20 @@ document.addEventListener("DOMContentLoaded", async () => { const TOKEN_EXPIRE_MS = 7 * 24 * 60 * 60 * 1000; // 7天有效期 // === AnythingLLM 配置 === - const LLM_PASSWORD = "lukeye@6"; const LLM_TOKEN_API = "http://llm.wisdompulse.cn/api/request-token"; const LLM_WORKSPACES_API = "http://llm.wisdompulse.cn/api/workspaces"; const LLM_STREAM_API_BASE = "http://llm.wisdompulse.cn/api/workspace"; const LLM_TOKEN_EXPIRE_MS = 23 * 60 * 60 * 1000; + // 动态获取 AnythingLLM 密码 + async function getLLMPassword() { + return new Promise((resolve) => { + chrome.storage.local.get(["llmPassword"], (res) => { + resolve(res.llmPassword || ""); + }); + }); + } + // 获取 LLM Token async function getLLMToken(forceRefresh = false) { return new Promise((resolve, reject) => { @@ -46,7 +54,8 @@ document.addEventListener("DOMContentLoaded", async () => { resolve(res.llmToken); } else { try { - console.log("开始请求 LLM token,POST", LLM_TOKEN_API, "参数:", { password: LLM_PASSWORD }); + const LLM_PASSWORD = await getLLMPassword(); + console.log("开始请求 LLM token,POST", LLM_TOKEN_API, "参数:", { password: "******" }); const response = await fetch(LLM_TOKEN_API, { method: "POST", headers: { "Content-Type": "application/json" }, @@ -221,7 +230,6 @@ document.addEventListener("DOMContentLoaded", async () => { } } - function log(...args) { const version = chrome?.runtime?.getManifest?.().version || "dev"; console.log("[v" + version + "]", ...args); From af4f2965ab4484cbc734539de07bac7a99e1d256 Mon Sep 17 00:00:00 2001 From: luke Date: Wed, 28 May 2025 23:46:54 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/popup.html | 82 +++++++++++++++++++++++++----------------------- pages/popup.js | 24 ++++++++++++++ pages/styles.css | 34 ++++++++++++++++++++ 3 files changed, 101 insertions(+), 39 deletions(-) diff --git a/pages/popup.html b/pages/popup.html index 5d7ff31..35b0007 100644 --- a/pages/popup.html +++ b/pages/popup.html @@ -6,49 +6,53 @@ -
- -

渠道应用开发部知识库

- 跳转OA +
+
+ +

渠道应用开发部知识库

+ 跳转OA + +
+
👤
+ +
+
+
+ -
-
👤
-
- -
- - - - - - - - -
    -
    - - diff --git a/pages/popup.js b/pages/popup.js index f3bf93e..aba9f1c 100644 --- a/pages/popup.js +++ b/pages/popup.js @@ -30,6 +30,30 @@ document.addEventListener("DOMContentLoaded", async () => { const LLM_STREAM_API_BASE = "http://llm.wisdompulse.cn/api/workspace"; const LLM_TOKEN_EXPIRE_MS = 23 * 60 * 60 * 1000; + // 新增tab切换功能 + const tabEs = document.getElementById("tabEs"); + const tabAi = document.getElementById("tabAi"); + const tabContentEs = document.getElementById("tabContentEs"); + const tabContentAi = document.getElementById("tabContentAi"); + + tabEs.onclick = function() { + tabEs.classList.add("active"); + tabAi.classList.remove("active"); + tabContentEs.classList.add("active"); + tabContentAi.classList.remove("active"); + }; + tabAi.onclick = function() { + tabEs.classList.remove("active"); + tabAi.classList.add("active"); + tabContentEs.classList.remove("active"); + tabContentAi.classList.add("active"); + // 自动滚动到最底部 + setTimeout(() => { + const llmContent = document.getElementById("llmResultContent"); + if (llmContent) llmContent.scrollTop = llmContent.scrollHeight; + }, 100); + }; + // 动态获取 AnythingLLM 密码 async function getLLMPassword() { return new Promise((resolve) => { diff --git a/pages/styles.css b/pages/styles.css index ba5fd0f..5a9ab44 100644 --- a/pages/styles.css +++ b/pages/styles.css @@ -403,4 +403,38 @@ h1 { white-space: pre-wrap; } +.tab-bar { + display: flex; + margin-bottom: 8px; + border-bottom: 1.5px solid #e2e7f4; + background: #f8fbff; +} +.tab-btn { + flex: 1; + padding: 9px 0; + border: none; + background: #f7faff; + color: #2764bb; + font-weight: bold; + cursor: pointer; + border-bottom: 2.5px solid transparent; + font-size: 15px; + transition: background 0.2s, border-color 0.2s; +} +.tab-btn.active { + background: #e7eefb; + color: #2050b0; + border-bottom: 2.5px solid #3070ed; +} +.tab-content { + display: none; +} +.tab-content.active { + display: block; +} + +/* 调整智能助手内容区边距,避免太拥挤 */ +#tabContentAi .llm-result-container { + margin-bottom: 0; +}