This commit is contained in:
luke 2025-05-22 07:23:32 +08:00
commit e6655dd36c
6 changed files with 141 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/.idea/

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

15
manifest.json Normal file
View File

@ -0,0 +1,15 @@
{
"manifest_version": 3,
"name": "知识库搜索助手",
"version": "1.0",
"description": "通过关键词从企业知识库中搜索内容。",
"permissions": [],
"action": {
"default_popup": "popup.html",
"default_icon": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
}
}
}

16
popup.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>知识库搜索助手</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<input id="searchInput" type="text" placeholder="输入关键词,多个用空格分隔..." />
<button id="searchBtn">搜索</button>
<ul id="results"></ul>
</div>
<script src="popup.js"></script>
</body>
</html>

52
popup.js Normal file
View File

@ -0,0 +1,52 @@
document.getElementById("searchBtn").addEventListener("click", async () => {
const input = document.getElementById("searchInput").value.trim();
const resultBox = document.getElementById("results");
resultBox.innerHTML = "";
if (!input) return;
const keywords = input.split(/\s+/).filter(Boolean);
const keywordGroups = keywords.map(k => [k]);
try {
const response = await fetch("http://app.wisdompulse.cn/search", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
keywordGroups,
page: 1,
size: 10
})
});
const data = await response.json();
if (!data.results || data.results.length === 0) {
resultBox.innerHTML = "<li>未找到相关文档</li>";
return;
}
data.results.forEach(doc => {
const li = document.createElement("li");
const link = document.createElement("a");
link.href = `http://app.wisdompulse.cn/html/${doc.filepath}`;
link.target = "_blank";
link.textContent = doc.filename;
const snippet = document.createElement("div");
snippet.className = "summary";
snippet.innerHTML = doc.summary?.slice(0, 300) + "...";
li.appendChild(link);
li.appendChild(snippet);
resultBox.appendChild(li);
});
} catch (err) {
console.error("搜索失败", err);
resultBox.innerHTML = "<li>搜索失败,请检查网络或服务状态。</li>";
}
});

57
styles.css Normal file
View File

@ -0,0 +1,57 @@
body {
font-family: Arial, sans-serif;
width: 320px;
padding: 10px;
background-color: #f9f9f9;
}
.container {
display: flex;
flex-direction: column;
}
input {
padding: 8px;
margin-bottom: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
button {
padding: 8px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover {
background-color: #0056b3;
}
#results {
list-style: none;
padding: 0;
margin-top: 10px;
}
#results li {
margin-bottom: 12px;
}
#results a {
font-weight: bold;
color: #007bff;
text-decoration: none;
}
#results a:hover {
text-decoration: underline;
}
#results .summary {
font-size: 12px;
color: #555;
margin-top: 4px;
}