From c9207622212aedc182a0cc87b77bc51f5e2d3ba7 Mon Sep 17 00:00:00 2001 From: peijunlei Date: Wed, 2 Sep 2026 13:15:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(download):=20=E6=B7=BB=E5=8A=A0=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E9=A1=B5=E6=90=9C=E7=B4=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/themes/dist_static/static/js/download.js | 43 +++++++++++++++++++++---- public/themes/website/1/zh/demo/download.html | 12 ++++--- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/public/themes/dist_static/static/js/download.js b/public/themes/dist_static/static/js/download.js index 2b56146..248e195 100644 --- a/public/themes/dist_static/static/js/download.js +++ b/public/themes/dist_static/static/js/download.js @@ -18,10 +18,31 @@ $(function() { $("[data-dropdown]").prop("hidden", true); $("[data-dropdown-trigger]").removeClass("is-open").attr("aria-expanded", "false"); }; + const getActiveTabId = () => { + const $active = $(".d-tabs__item.is-active").first(); + const $group = $active.closest(".d-tabs__group"); + if ($group.length) { + const $activeChild = $group.find(".d-tabs__dropdown-item.is-active[data-tab]").first(); + if ($activeChild.length) return $activeChild.attr("data-tab") || ""; + } + return $active.attr("data-tab") || ""; + }; + const activateTabById = (tabId) => { + if (!tabId) return; + const $dropdownItem = $(`.d-tabs__dropdown-item[data-tab="${tabId}"]`).first(); + if ($dropdownItem.length) { + $dropdownItem.addClass("is-active").siblings().removeClass("is-active"); + const $trigger = $dropdownItem.closest(".d-tabs__group").find("[data-dropdown-trigger]"); + $trigger.find("span").text($dropdownItem.text()); + activateTab($trigger); + return; + } + const $target = $(`.d-tabs__item[data-tab="${tabId}"]`).first(); + if ($target.length) activateTab($target); + }; $(".d-tabs__item:not([data-dropdown-trigger])").on("click", function() { activateTab($(this)); closeDropdowns(); - $("[data-dropdown-trigger] span").text("样本手册"); }); $("[data-dropdown-trigger]").on("click", function() { const $btn = $(this); @@ -44,10 +65,20 @@ $(function() { $(document).on("click", function(event) { if (!$(event.target).closest(".d-tabs__group").length) closeDropdowns(); }); - const tabParam = new URLSearchParams(window.location.search).get("tab"); - if (tabParam) { - const $target = $(`[data-tab="${tabParam}"]`); - if ($target.length) activateTab($target); - } + $("[data-download-search]").on("submit", function(event) { + event.preventDefault(); + const params = new URLSearchParams(); + const keywords = $(this).find('[name="keywords"]').val().trim(); + const tabId = getActiveTabId(); + if (tabId) params.set("tab", tabId); + if (keywords) params.set("keywords", keywords); + const query = params.toString(); + window.location.href = query ? `${window.location.pathname}?${query}` : window.location.pathname; + }); + const searchParams = new URLSearchParams(window.location.search); + const tabParam = searchParams.get("tab"); + const keywordsParam = searchParams.get("keywords"); + if (keywordsParam) $("[data-download-search] [name='keywords']").val(keywordsParam); + if (tabParam) activateTabById(tabParam); }); //#endregion diff --git a/public/themes/website/1/zh/demo/download.html b/public/themes/website/1/zh/demo/download.html index 8b7617e..05f6801 100644 --- a/public/themes/website/1/zh/demo/download.html +++ b/public/themes/website/1/zh/demo/download.html @@ -1,6 +1,8 @@ +{php}$download_keywords = input('keywords', '');{/php} + @@ -68,7 +70,7 @@ {/php} {if $count > 0}
- {hcTaglib:subcategory pid="$vo.id" item="child" sort=""} {/hcTaglib:subcategory}
{else} - + {/if} {/volist} -