|
|
@@ -152,7 +152,6 @@
|
|
|
type="text"
|
|
|
class="search-box"
|
|
|
placeholder="搜索应用……"
|
|
|
- oninput="filterApps()"
|
|
|
/>
|
|
|
|
|
|
<div id="apps-container">
|
|
|
@@ -271,31 +270,37 @@
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- // 应用搜索过滤
|
|
|
- function filterApps() {
|
|
|
- const searchTerm = document
|
|
|
- .querySelector(".search-box")
|
|
|
- .value.toLowerCase();
|
|
|
-
|
|
|
+ // 应用搜索过滤 - 已添加防抖
|
|
|
+ let searchTimeout = null;
|
|
|
+ document.querySelector(".search-box").addEventListener("input", () => {
|
|
|
+ // 清除之前的定时器
|
|
|
+ if (searchTimeout) {
|
|
|
+ clearTimeout(searchTimeout);
|
|
|
+ }
|
|
|
+
|
|
|
+ const searchTerm = document.querySelector(".search-box").value.toLowerCase().trim();
|
|
|
if (!searchTerm) {
|
|
|
renderAppGroups();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const container = document.getElementById("apps-container");
|
|
|
- container.innerHTML = "";
|
|
|
-
|
|
|
- const filteredApps = apps.filter(
|
|
|
- (app) =>
|
|
|
- app.name.toLowerCase().includes(searchTerm) ||
|
|
|
- (app.pinyin && app.pinyin.includes(searchTerm)) ||
|
|
|
- app.id.toLowerCase().includes(searchTerm) ||
|
|
|
- (app.description &&
|
|
|
- app.description.toLowerCase().includes(searchTerm))
|
|
|
- );
|
|
|
-
|
|
|
- container.innerHTML = getGroupHTML("搜索结果", filteredApps);
|
|
|
- }
|
|
|
+ // 设置新的定时器,延迟执行搜索
|
|
|
+ searchTimeout = setTimeout(() => {
|
|
|
+ const container = document.getElementById("apps-container");
|
|
|
+ container.innerHTML = "";
|
|
|
+
|
|
|
+ const filteredApps = apps.filter(
|
|
|
+ (app) =>
|
|
|
+ app.name.toLowerCase().includes(searchTerm) ||
|
|
|
+ (app.pinyin && app.pinyin.includes(searchTerm)) ||
|
|
|
+ app.id.toLowerCase().includes(searchTerm) ||
|
|
|
+ (app.description &&
|
|
|
+ app.description.toLowerCase().includes(searchTerm))
|
|
|
+ );
|
|
|
+
|
|
|
+ container.innerHTML = getGroupHTML("搜索结果", filteredApps);
|
|
|
+ }, 300); // 300ms 防抖延迟
|
|
|
+ });
|
|
|
|
|
|
// 初始加载应用数据
|
|
|
document.addEventListener("DOMContentLoaded", loadApps);
|