init
This commit is contained in:
commit
e6655dd36c
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/.idea/
|
||||
15
manifest.json
Normal file
15
manifest.json
Normal 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
16
popup.html
Normal 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
52
popup.js
Normal 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
57
styles.css
Normal 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;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user