Browse Source

【新增】添加应用搜索防抖功能

- 在应用搜索中添加了防抖功能,提高搜索性能
- 优化了搜索逻辑,使用 trim() 去除前后空格
- 更新了 metadata.json 版本号至 0.3.0
PJ568 1 year ago
parent
commit
9a97ad7b42
2 changed files with 29 additions and 24 deletions
  1. 26 21
      index.html
  2. 3 3
      metadata.json

+ 26 - 21
index.html

@@ -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);

+ 3 - 3
metadata.json

@@ -1,7 +1,7 @@
 {
   "name": "应用程序启动器",
   "id": "pageos-app-launcher",
-  "version": "0.2.1",
+  "version": "0.3.0",
   "description": "PageOS 的默认应用程序启动器",
   "icon": "assets/icon.svg",
   "author": "PJ568",
@@ -11,8 +11,8 @@
   "entry": "index.html",
   "all_files": {
     "lib/pinyinjs/pinyinUtil.js": "8b71ceebda777d1cc7b1afdcc9096f59676ce0fbe151d21db06f35d7e2ad7986",
+    "lib/pinyinjs/pinyin_dict_withtone.js": "e822cf20885ae7d6adcb35a3cbd94c3372e8dc6dbf04b1407f240c8c8da7d437",
     "assets/icon.svg": "4a60a778bbbcc370e9f593d2260d3bac003750f5ba73d9a33f2b31303687f7b5",
-    "index.html": "65f93f5ff5447bce5962802e7963e4790e3d41c7276e3c9fb22f8a653ae320c9",
-    "lib/pinyinjs/pinyin_dict_withtone.js": "e822cf20885ae7d6adcb35a3cbd94c3372e8dc6dbf04b1407f240c8c8da7d437"
+    "index.html": "806a957e1ef81b56272d243a4599e3c31e5ec723aa66d29b0a0eaf264e71ee06"
   }
 }