Browse Source

feat(search): 统一搜索逻辑

master
peijunlei 3 weeks ago
parent
commit
dda71cb663
  1. 31
      public/themes/dist_static/static/js/announce.js
  2. 4
      public/themes/dist_static/static/js/download.js
  3. 34
      public/themes/dist_static/static/js/faq.js
  4. 31
      public/themes/dist_static/static/js/video.js
  5. 4
      public/themes/website/1/zh/demo/announce.html
  6. 6
      public/themes/website/1/zh/demo/download.html
  7. 4
      public/themes/website/1/zh/demo/faq.html
  8. 4
      public/themes/website/1/zh/demo/video.html

31
public/themes/dist_static/static/js/announce.js

@ -45,8 +45,39 @@ function initFilterDropdown() {
if (!$(event.target).closest("[data-filter-trigger], [data-filter-dropdown]").length) closeDropdown(); if (!$(event.target).closest("[data-filter-trigger], [data-filter-dropdown]").length) closeDropdown();
}); });
} }
function getActiveTabId() {
return $("[data-filter-dropdown] .is-active[data-tab]").attr("data-tab") || "";
}
function activateTabById(tabId) {
if (!tabId) return;
const $item = $(`[data-filter-dropdown] [data-tab="${tabId}"]`).first();
if (!$item.length) return;
const $dropdown = $item.closest("[data-filter-dropdown]");
const $btn = $dropdown.prev("[data-filter-trigger]");
$item.addClass("is-active").siblings().removeClass("is-active");
$btn.find("span").text($item.text());
$btn.addClass("is-selected");
}
function initTabKeywordsSearch() {
$("[data-tab-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-tab-search] [name='keywords']").val(keywordsParam);
if (tabParam) activateTabById(tabParam);
}
$(function() { $(function() {
setActiveNav(); setActiveNav();
initFilterDropdown(); initFilterDropdown();
initTabKeywordsSearch();
}); });
//#endregion //#endregion

4
public/themes/dist_static/static/js/download.js

@ -65,7 +65,7 @@ $(function() {
$(document).on("click", function(event) { $(document).on("click", function(event) {
if (!$(event.target).closest(".d-tabs__group").length) closeDropdowns(); if (!$(event.target).closest(".d-tabs__group").length) closeDropdowns();
}); });
$("[data-download-search]").on("submit", function(event) {
$("[data-tab-search]").on("submit", function(event) {
event.preventDefault(); event.preventDefault();
const params = new URLSearchParams(); const params = new URLSearchParams();
const keywords = $(this).find('[name="keywords"]').val().trim(); const keywords = $(this).find('[name="keywords"]').val().trim();
@ -78,7 +78,7 @@ $(function() {
const searchParams = new URLSearchParams(window.location.search); const searchParams = new URLSearchParams(window.location.search);
const tabParam = searchParams.get("tab"); const tabParam = searchParams.get("tab");
const keywordsParam = searchParams.get("keywords"); const keywordsParam = searchParams.get("keywords");
if (keywordsParam) $("[data-download-search] [name='keywords']").val(keywordsParam);
if (keywordsParam) $("[data-tab-search] [name='keywords']").val(keywordsParam);
if (tabParam) activateTabById(tabParam); if (tabParam) activateTabById(tabParam);
}); });
//#endregion //#endregion

34
public/themes/dist_static/static/js/faq.js

@ -8,12 +8,39 @@ function setActiveNav() {
link.classList.toggle("is-active", active); link.classList.toggle("is-active", active);
}); });
} }
function activateFaqTab($btn) {
$btn.addClass("is-active").attr("aria-selected", "true");
$btn.siblings(".f-tabs__item").removeClass("is-active").attr("aria-selected", "false");
}
function getActiveTabId() {
return $(".f-tabs__item.is-active").attr("data-tab") || "";
}
function activateTabById(tabId) {
if (!tabId) return;
const $target = $(`.f-tabs__item[data-tab="${tabId}"]`).first();
if ($target.length) activateFaqTab($target);
}
function initTabKeywordsSearch() {
$("[data-tab-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-tab-search] [name='keywords']").val(keywordsParam);
if (tabParam) activateTabById(tabParam);
}
$(function() { $(function() {
setActiveNav(); setActiveNav();
$(".f-tabs__item").on("click", function() { $(".f-tabs__item").on("click", function() {
const $btn = $(this);
$btn.addClass("is-active").attr("aria-selected", "true");
$btn.siblings(".f-tabs__item").removeClass("is-active").attr("aria-selected", "false");
activateFaqTab($(this));
}); });
$(".f-item__trigger").on("click", function() { $(".f-item__trigger").on("click", function() {
const $item = $(this).closest(".f-item"); const $item = $(this).closest(".f-item");
@ -22,5 +49,6 @@ $(function() {
$item.toggleClass("is-open", willOpen); $item.toggleClass("is-open", willOpen);
$(this).attr("aria-expanded", willOpen ? "true" : "false"); $(this).attr("aria-expanded", willOpen ? "true" : "false");
}); });
initTabKeywordsSearch();
}); });
//#endregion //#endregion

31
public/themes/dist_static/static/js/video.js

@ -86,9 +86,40 @@ function initFilterDropdown() {
if (!$(event.target).closest("[data-filter-trigger], [data-filter-dropdown]").length) closeDropdown(); if (!$(event.target).closest("[data-filter-trigger], [data-filter-dropdown]").length) closeDropdown();
}); });
} }
function getActiveTabId() {
return $("[data-filter-dropdown] .is-active[data-tab]").attr("data-tab") || "";
}
function activateTabById(tabId) {
if (!tabId) return;
const $item = $(`[data-filter-dropdown] [data-tab="${tabId}"]`).first();
if (!$item.length) return;
const $dropdown = $item.closest("[data-filter-dropdown]");
const $btn = $dropdown.prev("[data-filter-trigger]");
$item.addClass("is-active").siblings().removeClass("is-active");
$btn.find("span").text($item.text());
$btn.addClass("is-selected");
}
function initTabKeywordsSearch() {
$("[data-tab-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-tab-search] [name='keywords']").val(keywordsParam);
if (tabParam) activateTabById(tabParam);
}
$(function() { $(function() {
setActiveNav(); setActiveNav();
initVideoModal(); initVideoModal();
initFilterDropdown(); initFilterDropdown();
initTabKeywordsSearch();
}); });
//#endregion //#endregion

4
public/themes/website/1/zh/demo/announce.html

@ -80,9 +80,9 @@
<button type="button" class="a-filter__dropdown-item">纺织行业专用</button> <button type="button" class="a-filter__dropdown-item">纺织行业专用</button>
</div> </div>
</div> </div>
<form class="s-search" action="#" method="get" role="search" onsubmit="return false;">
<form class="s-search" role="search" data-tab-search>
<img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" /> <img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" />
<input class="s-search__input" type="search" name="q" placeholder="请输入您想搜索公告的关键词" autocomplete="off" />
<input class="s-search__input" type="search" name="keywords" placeholder="请输入您想搜索公告的关键词" autocomplete="off" />
<button class="s-search__btn" type="submit">搜索</button> <button class="s-search__btn" type="submit">搜索</button>
</form> </form>
</div> </div>

6
public/themes/website/1/zh/demo/download.html

@ -1,8 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="zh-CN"> <html lang="zh-CN">
{php}$download_keywords = input('keywords', '');{/php}
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@ -87,9 +85,9 @@
{/if} {/if}
{/volist} {/volist}
</div> </div>
<form class="s-search" role="search" data-download-search>
<form class="s-search" role="search" data-tab-search>
<img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" /> <img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" />
<input class="s-search__input" type="search" name="keywords" value="{$download_keywords}" placeholder="请输入您想下载的文件" autocomplete="off" />
<input class="s-search__input" type="search" name="keywords" placeholder="请输入您想下载的文件" autocomplete="off" />
<button class="s-search__btn" type="submit">搜索</button> <button class="s-search__btn" type="submit">搜索</button>
</form> </form>
</div> </div>

4
public/themes/website/1/zh/demo/faq.html

@ -68,9 +68,9 @@
<button type="button" class="f-tabs__item" role="tab" aria-selected="false">服务类</button> <button type="button" class="f-tabs__item" role="tab" aria-selected="false">服务类</button>
<button type="button" class="f-tabs__item" role="tab" aria-selected="false">维护类</button> <button type="button" class="f-tabs__item" role="tab" aria-selected="false">维护类</button>
</div> </div>
<form class="s-search" action="#" method="get" role="search" onsubmit="return false;">
<form class="s-search" role="search" data-tab-search>
<img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" /> <img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" />
<input class="s-search__input" type="search" name="q" placeholder="请输入您想搜索问题的关键词" autocomplete="off" />
<input class="s-search__input" type="search" name="keywords" placeholder="请输入您想搜索问题的关键词" autocomplete="off" />
<button class="s-search__btn" type="submit">搜索</button> <button class="s-search__btn" type="submit">搜索</button>
</form> </form>
</div> </div>

4
public/themes/website/1/zh/demo/video.html

@ -80,9 +80,9 @@
<button type="button" class="v-filter__dropdown-item">纺织行业专用</button> <button type="button" class="v-filter__dropdown-item">纺织行业专用</button>
</div> </div>
</div> </div>
<form class="s-search" action="#" method="get" role="search" onsubmit="return false;">
<form class="s-search" role="search" data-tab-search>
<img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" /> <img class="s-search__icon" src="data:image/svg+xml,%3csvg%20viewBox='0%200%2024%2024'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%20width='24.000000'%20height='24.000000'%20fill='none'%3e%3crect%20id='搜索'%20width='24.000000'%20height='24.000000'%20x='0.000000'%20y='0.000000'%20fill='rgb(255,255,255)'%20fill-opacity='0'%20/%3e%3cpath%20id='矢量%203'%20d='M15.8481%2017.1208C14.4808%2018.2114%2012.7482%2018.8633%2010.8633%2018.8633C6.44506%2018.8633%202.86328%2015.2816%202.86328%2010.8633C2.86328%206.445%206.44506%202.86328%2010.8633%202.86328C15.2815%202.86328%2018.8633%206.445%2018.8633%2010.8633C18.8633%2012.7482%2018.2114%2014.4808%2017.1208%2015.8481L21.136%2019.8633L19.8633%2021.136L15.8481%2017.1208ZM17.0632%2010.8633C17.0632%207.43908%2014.2874%204.66326%2010.8633%204.66326C7.4392%204.66326%204.66332%207.43908%204.66332%2010.8633C4.66332%2014.2875%207.4392%2017.0633%2010.8633%2017.0633C14.2874%2017.0633%2017.0632%2014.2875%2017.0632%2010.8633Z'%20fill='rgb(175,181,185)'%20fill-rule='evenodd'%20/%3e%3c/svg%3e" alt="" width="24" height="24" />
<input class="s-search__input" type="search" name="q" placeholder="请输入您想搜索视频的关键词" autocomplete="off" />
<input class="s-search__input" type="search" name="keywords" placeholder="请输入您想搜索视频的关键词" autocomplete="off" />
<button class="s-search__btn" type="submit">搜索</button> <button class="s-search__btn" type="submit">搜索</button>
</form> </form>
</div> </div>

Loading…
Cancel
Save