From cfb4176bb7b61bab077e1f3f345b67579676a0cf Mon Sep 17 00:00:00 2001 From: jsasg <735273025@qq.com> Date: Fri, 20 Jun 2025 14:19:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mobile=E6=90=9C=E7=B4=A2=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/index/view/mobile/public/header.html | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/index/view/mobile/public/header.html b/app/index/view/mobile/public/header.html index 0abf9d9e..0153e16d 100644 --- a/app/index/view/mobile/public/header.html +++ b/app/index/view/mobile/public/header.html @@ -53,6 +53,7 @@
@@ -118,5 +119,43 @@ $('.oircoEgapp-head').css('width', newWidth + 'px'); }); + // 回显搜索历史记录 + history(); }) + + function history() { + var keywords = new URL(window.location.href).searchParams.get('keywords') + var history_keywords = localStorage.getItem('header_search_keywords'); + if (!history_keywords) { + history_keywords = []; + } else { + history_keywords = JSON.parse(history_keywords); + } + + // 记录搜索关键词 + if (keywords) { + if (history_keywords.includes(keywords)) { + history_keywords.splice(history_keywords.indexOf(keywords), 1); + } + history_keywords.unshift(keywords); + if (history_keywords.length > 3) { + history_keywords.pop(); + } + localStorage.setItem('header_search_keywords', JSON.stringify(history_keywords)); + } + + // 回显搜索历史 + history_keywords.forEach(function(item) { + $('#history').append( + $('') + .css({ + 'margin-right': '10px' + }) + .attr('href', '{:url("product/search")}?keywords=' + item) + .text(item) + ); + }); + + return history_keywords; + } \ No newline at end of file