fix: mobile搜索历史问题
This commit is contained in:
@@ -53,6 +53,7 @@
|
||||
</form>
|
||||
<div class="title-text">
|
||||
<p><a href="#">{:lang_i18n('搜索历史')}</a></p>
|
||||
<div id="history"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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(
|
||||
$('<a>')
|
||||
.css({
|
||||
'margin-right': '10px'
|
||||
})
|
||||
.attr('href', '{:url("product/search")}?keywords=' + item)
|
||||
.text(item)
|
||||
);
|
||||
});
|
||||
|
||||
return history_keywords;
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user