Przeglądaj źródła

【新增】优化应用卡片交互

- 优化应用卡片的右键菜单功能,支持启动应用和查看详细信息
- 修复左键点击应用卡片时隐藏右键菜单的问题
- 优化右键菜单的显示逻辑,避免在应用卡片区域外显示菜单
PJ568 1 rok temu
rodzic
commit
f8a7c9c4f5
1 zmienionych plików z 16 dodań i 10 usunięć
  1. 16 10
      index.html

+ 16 - 10
index.html

@@ -352,9 +352,7 @@
               return `
               <button data-href="${
                 pkg.location
-              }/metadata.json" onclick="window.open('${
-                pkg.location
-              }/metadata.json', '_blank');" class="app-card" title="${
+              }/metadata.json" class="app-card" title="${
                 pkg.description || pkg.name || pkg.id
               }" target="_blank" data-menu-options='${JSON.stringify([
                 { label: "启动应用程序", action: "execute" }, // 新标签页打开 href 指向的 metadata.json 中的 entry 指向的文件
@@ -378,7 +376,7 @@
           if (searchTimeout) {
             clearTimeout(searchTimeout);
           }
-          
+
           const query = searchInput.value.toLowerCase().trim();
           if (!query) {
             renderApps(packages);
@@ -486,8 +484,7 @@
         contextMenu.id = "custom-context-menu";
         doc.body.appendChild(contextMenu);
 
-        // 监听全局右键点击事件
-        doc.addEventListener("contextmenu", function (e) {
+        function f(e) {
           // 阻止默认右键菜单
           e.preventDefault();
 
@@ -622,12 +619,21 @@
             contextMenu.classList.remove("show");
             inScreen(contextMenu);
           }
+        }
+
+        // 监听全局右键点击事件
+        doc.addEventListener("contextmenu", function (e) {
+          f(e);
         });
 
-        // 点击其他地方隐藏菜单
-        doc.addEventListener("click", function () {
-          contextMenu.classList.remove("show");
-          inScreen(contextMenu);
+        // 监听全局左键点击事件,点击其他地方隐藏菜单
+        doc.addEventListener("click", function (e) {
+          if (e.target.closest("button.app-card")) {
+            f(e);
+          } else {
+            contextMenu.classList.remove("show");
+            inScreen(contextMenu);
+          }
         });
 
         // 阻止菜单内部的点击事件冒泡