优化UI
This commit is contained in:
commit
95f9fc86fe
@ -51,6 +51,7 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input id="username" placeholder="用户名" />
|
<input id="username" placeholder="用户名" />
|
||||||
<input id="password" type="password" placeholder="密码" />
|
<input id="password" type="password" placeholder="密码" />
|
||||||
|
<input type="password" id="llmPassword" placeholder="请输入AnythingLLM的密码" autocomplete="off" />
|
||||||
<button id="loginBtn">登录</button>
|
<button id="loginBtn">登录</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="error" id="errorBox"></div>
|
<div class="error" id="errorBox"></div>
|
||||||
|
|||||||
@ -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.getElementById("loginBtn").addEventListener("click", doLogin);
|
||||||
document.addEventListener("keydown", (e) => {
|
document.addEventListener("keydown", (e) => {
|
||||||
if (e.key === "Enter") doLogin();
|
if (e.key === "Enter") doLogin();
|
||||||
@ -6,6 +15,7 @@ document.addEventListener("keydown", (e) => {
|
|||||||
function doLogin() {
|
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 llmPassword = document.getElementById("llmPassword").value;
|
||||||
const errorBox = document.getElementById("errorBox");
|
const errorBox = document.getElementById("errorBox");
|
||||||
errorBox.textContent = "";
|
errorBox.textContent = "";
|
||||||
|
|
||||||
@ -14,6 +24,9 @@ function doLogin() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存 llmPassword(登录不依赖LLM密码是否填写,只是单独存储)
|
||||||
|
chrome.storage.local.set({ llmPassword });
|
||||||
|
|
||||||
fetch("http://app.wisdompulse.cn/api/v1/user/login", {
|
fetch("http://app.wisdompulse.cn/api/v1/user/login", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@ -26,7 +39,7 @@ function doLogin() {
|
|||||||
chrome.storage.local.set({
|
chrome.storage.local.set({
|
||||||
token: body.token,
|
token: body.token,
|
||||||
username: body.username || username,
|
username: body.username || username,
|
||||||
loginAt: Date.now() // 毫秒时间戳
|
loginAt: Date.now()
|
||||||
}, () => {
|
}, () => {
|
||||||
window.location.href = chrome.runtime.getURL("pages/popup.html");
|
window.location.href = chrome.runtime.getURL("pages/popup.html");
|
||||||
});
|
});
|
||||||
|
|||||||
@ -25,25 +25,36 @@
|
|||||||
<input id="searchInput" type="text" autocomplete="off" placeholder="请输入关键词(空格分隔)..." />
|
<input id="searchInput" type="text" autocomplete="off" placeholder="请输入关键词(空格分隔)..." />
|
||||||
<button id="searchBtn">搜索</button>
|
<button id="searchBtn">搜索</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="history-wrapper hidden" id="historyWrapper">
|
|
||||||
<div class="history-header">
|
<div class="tab-bar">
|
||||||
<span>历史搜索:</span>
|
<button class="tab-btn active" id="tabEs">知识库文档</button>
|
||||||
<img id="clearHistoryBtn" src="../assets/delete.png" title="清空历史记录" class="delete-icon" />
|
<button class="tab-btn" id="tabAi">智能助手</button>
|
||||||
</div>
|
|
||||||
<div id="historyTags" class="tag-history"></div>
|
|
||||||
</div>
|
</div>
|
||||||
<!-- AnythingLLM结果区域 -->
|
|
||||||
<div id="llmResultContainer" class="llm-result-container hidden">
|
<div id="tabContentEs" class="tab-content active">
|
||||||
<div class="llm-title">智能助手答案</div>
|
<div class="history-wrapper hidden" id="historyWrapper">
|
||||||
<div class="llm-result-content" id="llmResultContent"></div>
|
<div class="history-header">
|
||||||
<div class="llm-input-bar">
|
<span>历史搜索:</span>
|
||||||
<input id="llmInput" type="text" placeholder="请输入您的问题..." />
|
<img id="clearHistoryBtn" src="../assets/delete.png" title="清空历史记录" class="delete-icon" />
|
||||||
<button id="llmSendBtn">发送</button>
|
</div>
|
||||||
|
<div id="historyTags" class="tag-history"></div>
|
||||||
|
</div>
|
||||||
|
<ul id="results"></ul>
|
||||||
|
</div>
|
||||||
|
<div id="tabContentAi" class="tab-content">
|
||||||
|
<div id="llmResultContainer" class="llm-result-container">
|
||||||
|
<div class="llm-title">智能助手答案</div>
|
||||||
|
<div class="llm-result-content" id="llmResultContent"></div>
|
||||||
|
<div class="llm-input-bar">
|
||||||
|
<input id="llmInput" type="text" placeholder="请输入您的问题..." />
|
||||||
|
<button id="llmSendBtn">发送</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<ul id="results"></ul>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@ -80,12 +80,44 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
const TOKEN_EXPIRE_MS = 7 * 24 * 60 * 60 * 1000; // 7天有效期
|
const TOKEN_EXPIRE_MS = 7 * 24 * 60 * 60 * 1000; // 7天有效期
|
||||||
|
|
||||||
// === AnythingLLM 配置 ===
|
// === AnythingLLM 配置 ===
|
||||||
const LLM_PASSWORD = "lukeye@6";
|
|
||||||
const LLM_TOKEN_API = "http://llm.wisdompulse.cn/api/request-token";
|
const LLM_TOKEN_API = "http://llm.wisdompulse.cn/api/request-token";
|
||||||
const LLM_WORKSPACES_API = "http://llm.wisdompulse.cn/api/workspaces";
|
const LLM_WORKSPACES_API = "http://llm.wisdompulse.cn/api/workspaces";
|
||||||
const LLM_STREAM_API_BASE = "http://llm.wisdompulse.cn/api/workspace";
|
const LLM_STREAM_API_BASE = "http://llm.wisdompulse.cn/api/workspace";
|
||||||
const LLM_TOKEN_EXPIRE_MS = 23 * 60 * 60 * 1000;
|
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) => {
|
||||||
|
chrome.storage.local.get(["llmPassword"], (res) => {
|
||||||
|
resolve(res.llmPassword || "");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 获取 LLM Token
|
// 获取 LLM Token
|
||||||
async function getLLMToken(forceRefresh = false) {
|
async function getLLMToken(forceRefresh = false) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@ -101,7 +133,8 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
resolve(res.llmToken);
|
resolve(res.llmToken);
|
||||||
} else {
|
} else {
|
||||||
try {
|
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, {
|
const response = await fetch(LLM_TOKEN_API, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
@ -276,7 +309,6 @@ document.addEventListener("DOMContentLoaded", async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function log(...args) {
|
function log(...args) {
|
||||||
const version = chrome?.runtime?.getManifest?.().version || "dev";
|
const version = chrome?.runtime?.getManifest?.().version || "dev";
|
||||||
console.log("[v" + version + "]", ...args);
|
console.log("[v" + version + "]", ...args);
|
||||||
|
|||||||
@ -436,4 +436,45 @@ h1 {
|
|||||||
background: #eaf1fb;
|
background: #eaf1fb;
|
||||||
color: #1e40af;
|
color: #1e40af;
|
||||||
}
|
}
|
||||||
|
.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;
|
||||||
|
}
|
||||||
|
|
||||||
|
body.fullscreen #tabContentAi .llm-result-container {
|
||||||
|
resize: vertical;
|
||||||
|
overflow: auto;
|
||||||
|
min-height: 160px;
|
||||||
|
max-height: 80vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user