Authored by OF1706

search history

... ... @@ -9,6 +9,8 @@ const mRoot = '../models';
const search = require(`${mRoot}/search`);
const _ = require('lodash');
const config = global.yoho.config;
/**
* search 首页
* @param {[type]} req [description]
... ... @@ -112,23 +114,39 @@ const serachFilterBrands = (req, res, next) => {
* @param {[type]} res [description]
* @return {[type]} [description]
*/
const searchHistory = (req, res, next) => {
search.getSearchHistory(req.query).then(result => {
if (req.query.json === '1') {
return res.send(result);
}
const searchHistory = (req, res) => {
let dest = {
code: 200,
message: 'history',
data: result || ''
};
let history = req.cookies['_History'];
let q = req.query.query || '';
res.type('text/javascript');
res.send(req.query.callback + '(' + JSON.stringify(dest) + ')');
}).catch(next);
console.log("////////////----------------------");
console.log(history);
console.log("///////////----------------------");
history = history ? history.split(',') : [];
history = _.reject(history, old => old === q ? true : false);
history.unshift(q);
res.cookie('_History', _.take(history, 9).join(','), {
domain: config.cookieDomain,
maxAge: 60 * 60 * 24 * 1000 * 30 // 一月
});
let data = [];
_.forEach(history,function(item){
let list = {};
list['keyword'] = item;
data.push(list);
});
let ResData = {};
ResData['data'] = data;
res.type('text/plain');
res.send(JSON.stringify(ResData));
};
... ... @@ -158,6 +176,8 @@ const searchRecommend = (req, res, next) => {
}).catch(next);
};
module.exports = {
index,
suggest,
... ...
... ... @@ -424,14 +424,14 @@ const getBrands4Filter = (params) => {
* 搜索 历史记录提示
* @return
*/
const getSearchHistory = (params) => {
let finalParams = {
method: 'app.search.getTerms',
keyword: params.keyword || ''
};
return api.get('', finalParams, config.apiCache);
};
// const getSearchHistory = (params) => {
// let finalParams = {
// method: 'app.search.getTerms',
// keyword: params.keyword || ''
// };
//
// return api.get('', finalParams, config.apiCache);
// };
/**
* 搜索 热门搜索和默认搜索
... ... @@ -475,6 +475,6 @@ module.exports = {
getBrands4Filter,
getProductListOrig,
getSearchCacheKey,
getSearchHistory,
// getSearchHistory,
getSearchRecommend
};
... ...
... ... @@ -93,35 +93,7 @@
{{#unless @root.pc.common.disSearchAssociation}}
<ul class="search-suggest"></ul>
{{/unless}}
{{#unless @root.pc.common.disSearchAssociation}}
<ul class="search-suggest search-suggest-history"></ul>
{{/unless}}
<ul class="search-suggest search-suggest-history">
<p class="search-suggest-title">最近搜过</p>
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
act="\{{href}}">
<span class="searchvalue">\{{keyword}}77777444444444444444444444444444444444444444444444</span>
<span class="searchDel">删除</span>
</a>
</li>
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
act="\{{href}}">
<span class="searchvalue">\{{keyword}}77777</span>
<span class="searchDel">删除</span>
</a>
</li>
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
act="\{{href}}">
<span class="searchvalue">\{{keyword}}77777</span>
<span class="searchDel">删除</span>
</a>
</li>
</ul>
<ul class="search-suggest search-suggest-history"></ul>
<div class="search-2016">
<form action="//search.yohobuy.com" method="get" id="search-form">
<input type="hidden" id="defaultsearch" value="{{defaultSearch}}">
... ... @@ -350,17 +322,16 @@
\{{/data}}
</script>
<script type="text/html" id="search-suggest-history">
<p class="search-suggest-title">最近搜过<a class="searchDel" href="#">删除</a></p>
\{{#data}}
<li>
<a style="display: block;" href="\{{href}}" class="clearfix clear search-item" title="\{{keyword}}"
act="\{{href}}">
<span class="searchvalue">\{{keyword}}77777</span>
<span class="searchDel">删除</span>
<span class="searchvalue">\{{keyword}}</span>
</a>
</li>
\{{/data}}
</script>
</div>
<input id="api-domain" type="hidden" value="{{apiDomain}}">
... ...
<div class="individual-slide">
<ul class="goods clearfix img-list">
{{#each item}}
<li class="good img-item" data-id="id" data-skn="skn">
<a href="{{href}}" target="_blank">
<img class="lazy" data-original="{{img}}"/>
</a>
<a class="name" href="{{href}}" target="_blank">{{title}}</a>
<p class="price">
<span class="sale-price {{#if marketPrice}}sale-price-new{{/if}}">{{price}}</span>
{{#if marketPrice}}
<span class="market-price">{{marketPrice}}</span>
{{/if}}
</p>
</li>
{{/each}}
</ul>
<div class="img-brand-switch">
{{#hasPrev}}
<a class="prev iconfont" href="javascript:;"></a>
{{/hasPrev}}
{{#hasNext}}
<a class="next iconfont" href="javascript:;"></a>
{{/hasNext}}
</div>
</div>
\ No newline at end of file
... ...
No preview for this file type
... ... @@ -2,7 +2,7 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>
Created by FontForge 20120731 at Thu Jan 19 16:45:25 2017
Created by FontForge 20120731 at Wed Mar 1 20:04:54 2017
By admin
</metadata>
<defs>
... ... @@ -185,6 +185,8 @@ d="M958 758q0 30 -21 51.5t-51 21.5h-749q-30 0 -51 -21.5t-21 -51.5v-748q0 -30 21
z" />
<glyph glyph-name="wujiaoxing" unicode="&#xe623;"
d="M512 63l-316 -166l60 352l-256 250l354 51l158 321l158 -321l354 -51l-256 -250l60 -352z" />
<glyph glyph-name="shanchu1" unicode="&#xe646;"
d="M1004 851l-17 17l-475 -476l-475 476l-17 -17l475 -475l-458 -459l17 -17l458 459l458 -459l17 17l-458 459z" />
<glyph glyph-name="7xiaoche" unicode="&#xe636;" horiz-adv-x="1163"
d="M295 196q67 0 114 -47t47 -113.5t-47 -114t-114 -47.5t-114 47.5t-47 114t47 113.5t114 47zM917.5 196q66.5 0 113.5 -47t47 -113.5t-47 -114t-113.5 -47.5t-114 47.5t-47.5 114t47.5 113.5t114 47zM400 894v-99h-210v0v0l-187 -294v-372h95q27 56 80 90.5t117 34.5
t117 -34.5t80 -90.5h228q27 56 80 90.5t117.5 34.5t117.5 -34.5t79 -90.5h46v765h-760v0zM400 452h-283l159 250l124 1v-251v0v0zM893 701l-131 -276l-63 31l101 206h-105v68h198v-29v0v0z" />
... ... @@ -274,7 +276,8 @@ d="M958 589q0 15 -10.5 25.5t-25.5 10.5t-26 -10l-384 -384l-384 384q-11 10 -26 10t
d="M512 -62q-91 0 -173.5 35.5t-142 95t-95 142t-35.5 173.5t35.5 173.5t95 142t142 95t173.5 35.5t173.5 -35.5t142 -95t95 -142t35.5 -173.5t-35.5 -173.5t-95 -142t-142 -95t-173.5 -35.5zM512 766q-104 0 -192 -51t-139 -139t-51 -192t51 -192t139 -139t192 -51t192 51
t139 139t51 192t-51 192t-139 139t-192 51zM464 592q0 -20 14 -34t34 -14t34 14t14 34t-14 34t-34 14t-34 -14t-14 -34zM512 128q-13 0 -22.5 9.5t-9.5 22.5v288q0 13 9.5 22.5t22.5 9.5t22.5 -9.5t9.5 -22.5v-288q0 -13 -9.5 -22.5t-22.5 -9.5z" />
<glyph glyph-name="yuanxingweixuanzhong" unicode="&#xe6c3;"
d="M512 -64q-185 0 -316.5 131.5t-131.5 316.5t131.5 316.5t316.5 131.5t316.5 -131.5t131.5 -316.5t-131.5 -316.5t-316.5 -131.5zM512 768q-159 0 -271.5 -112.5t-112.5 -271.5t112.5 -271.5t271.5 -112.5t271.5 112.5t112.5 271.5t-112.5 271.5t-271.5 112.5z" />
d="M512 -126q-104 0 -198 40.5t-162.5 109t-109 162.5t-40.5 198t40.5 198t109 162.5t162.5 109t198 40.5t198 -40.5t162.5 -109t109 -162.5t40.5 -198t-40.5 -198t-109 -162.5t-162.5 -109t-198 -40.5zM512 821q-89 0 -170 -34.5t-139.5 -93t-93 -139.5t-34.5 -170
t34.5 -170t93 -139.5t139.5 -93t170 -34.5t170 34.5t139.5 93t93 139.5t34.5 170t-34.5 170t-93 139.5t-139.5 93t-170 34.5z" />
<glyph glyph-name="Fill" unicode="&#xe6c9;"
d="M512 52q-34 0 -58.5 24.5t-24.5 59t24.5 58.5t58.5 24t58.5 -24t24.5 -58.5t-24.5 -59t-58.5 -24.5zM457 660q0 23 16 39.5t39 16.5t39 -16.5t16 -39.5v-304q0 -22 -16 -38.5t-39 -16.5t-39 16.5t-16 38.5v304zM512 896h-6q-104 0 -199 -40.5t-163.5 -109t-109 -163.5
t-40.5 -199t40.5 -199t109 -163.5t163.5 -109t199 -40.5h6h6q104 0 199 40.5t163.5 109t109 163.5t40.5 199t-40.5 199t-109 163.5t-163.5 109t-199 40.5h-6z" />
... ... @@ -327,5 +330,23 @@ t90.5 135t135 90.5t163 33.5zM237 64l595 595q102 -123 102 -275q0 -114 -55.5 -211t
<glyph glyph-name="shiliangzhinengduixiang1" unicode="&#xe6e2;"
d="M515 -128q60 0 105.5 40t52.5 98h-322q11 -58 57 -98t107 -40zM852 225q-15 31 -15 123v113q0 111 -56 200t-149 127q-7 47 -42 77.5t-81 30.5q-51 0 -87 -36q-26 -27 -35 -72q-93 -42 -149 -131t-56 -196v-113q0 -97 -16 -128q-30 -10 -46 -20q-20 -31 -20 -57
q0 -31 24 -53.5t58 -22.5h660q34 0 58 22.5t24 53.5q-4 31 -24.5 54.5t-47.5 27.5z" />
<glyph glyph-name="weibiaoti-" unicode="&#xe6ed;"
d="M512 896q-212 0 -362 -150t-150 -362t150 -362t362 -150t362 150t150 362t-150 362t-362 150zM512 -39q-114 0 -211.5 57t-154.5 154.5t-57 211.5t57 211.5t154.5 154.5t211.5 57t211.5 -57t154.5 -154.5t57 -211.5t-57 -211.5t-154.5 -154.5t-211.5 -57zM512 316
q18 0 31 13t13 31v246q0 18 -13 31t-31 13t-31 -13t-13 -31v-246q0 -18 13 -31t31 -13zM512 183zM444 182.5q0 -28.5 20 -48.5t48 -20t48 20t20 48.5t-20 48.5t-48 20t-48 -20t-20 -48.5z" />
<glyph glyph-name="weibiaoti-1" unicode="&#xe6ee;"
d="M922 883l-410 -409l-410 409l-89 -89l409 -410l-409 -410l89 -89l410 409l410 -409l89 89l-409 410l409 410z" />
<glyph glyph-name="weibiaoti-2" unicode="&#xe6ef;"
d="M230 759l367 -366l-367 -359l120 -119l367 358l119 120l-119 119l-367 367z" />
<glyph glyph-name="weibiaoti-3" unicode="&#xe6f0;"
d="M512 446l-196 -202l-39 39l196 202l39 39l39 -39l196 -202l-39 -39z" />
<glyph glyph-name="weibiaoti-4" unicode="&#xe6f1;"
d="M512 306l-196 201l-39 -45l235 -235l235 235l-39 45z" />
<glyph glyph-name="weibiaoti-5" unicode="&#xe6f2;"
d="M512 384zM32 384q0 -130 64.5 -240.5t175 -175t240.5 -64.5t240.5 64.5t175 175t64.5 240.5t-64.5 240.5t-175 175t-240.5 64.5t-240.5 -64.5t-175 -175t-64.5 -240.5z" />
<glyph glyph-name="weibiaoti-6" unicode="&#xe6f8;"
d="M498 862l-409 -362q-21 -20 -21 -41v-471q0 -30 21 -52.5t48 -22.5h232v314h280v-314h238q31 0 50 22t19 53v471q0 12 -5.5 24t-15.5 17l-409 362q-5 5 -14 5t-14 -5z" />
<glyph glyph-name="weibiaoti-7" unicode="&#xe6f9;"
d="M1017 -106l-278 278q55 58 85.5 133t30.5 158q0 115 -57 212.5t-154.5 154.5t-212 57t-212 -57t-154 -154.5t-56.5 -212.5t56.5 -212.5t154 -154t212.5 -56.5q83 0 158 30.5t133 85.5l279 -279zM432 62q-109 0 -201 54t-146 146t-54 201t54 201.5t146 146t201 53.5
t201.5 -53.5t146 -146t53.5 -201.5t-53.5 -201t-146 -146t-201.5 -54z" />
</font>
</defs></svg>
... ...
No preview for this file type
No preview for this file type
... ... @@ -4,7 +4,7 @@
* @date: 2016/5/9
*/
var $ = require('yoho-jquery'),
handlebars = require('yoho-handlebars');
handlebars = require('yoho-handlebars')
var $tool = $('.tool-wrapper'),
$yohoGroup = $tool.find('.yoho-group'),
... ... @@ -17,9 +17,9 @@ var $head = $('.head-wrapper'),
$searchSug = $head.find('.search-suggest'),
$searchHistory = $head.find('.search-suggest-history'),
$searchRecommend = $head.find('.search-hot'),
$searchHistoryHbs = $head.find('#search-suggest-history'),
$searchRecommendHbs = $head.find('#search-suggest-recommend');
$goCart = $head.find('.go-cart'),
$searchHistoryHbs = $('#search-suggest-history'),
$searchRecommendHbs = $head.find('#search-suggest-recommend'),
$goCart = $head.find('.go-cart'),
$myYohoBox = $('#myYohoBox'),
$goodsNum = $goCart.find('.goods-num-tip'),
$miniCart = $head.find('.mini-cart-wrapper');
... ... @@ -142,6 +142,7 @@ function setTopBanner(data) {
// cookie集合
function exeCookieMap() {
var cookies = document.cookie;
// console.log(cookies);
var cookiearr = cookies.split(';');
var i;
var temparr;
... ... @@ -861,23 +862,31 @@ function actionAddKeyWords() {
* 历史记录 搜索提示 api
* @return {[type]} [description]
*/
function searchSuggestHistory(key) {
var param = {
return_type: 'jsonp',
keyword: key
};
$.getJSON('//search.yohobuy.com/product/search/history?callback=?', param, function(jsonData) {
function searchSuggestHistory() {
// if ($searchKey.val() === '') {
// $searchKey.val($('#defaultsearch').val());
// }
// 保存搜索的内容
// writeSearch.setHistoryValFun($searchKey.val());
// exeCookieMap();
let $queryKey = $("#query-key");
$.getJSON('//search.yohobuy.com/product/search/history?query='+$queryKey.val(), function(jsonData) {
var searchSuggestHistoryHtml;
if (jsonData.code === 200) {
if (jsonData.data && jsonData.data.length) {
// if (jsonData.code === 200) {
// if (jsonData.data && jsonData.data.length) {
searchSuggestHistoryHtml = handlebars.compile($searchHistoryHbs.html() || '');
console.log(jsonData);
$searchHistory.html(searchSuggestHistoryHtml(jsonData)).show();
} else {
$searchHistory.hide();
}
}
// } else {
// $searchHistory.hide();
// }
// }
});
}
... ... @@ -889,8 +898,6 @@ $searchKey.keydown(function() {
}).focus(function() {
console.log(typeof ($.trim($(this).val())));
var val = $.trim($(this).val());
searchSuggestHistory();
if (val === '') {
... ...
... ... @@ -35,8 +35,6 @@ require('./detail/latest-walk');
product.init(4);
lazyLoad($('img.lazy'), {
failure_limit: 20
});
... ...
... ... @@ -482,11 +482,23 @@
}
.search-suggest-title {
width: 320px;
box-sizing: border-box;
color: #b0b0b0;
font-size: 12px;
line-height: 12px;
padding: 10px 0 12px 10px;
.searchDel {
padding: 0 10px 0 0;
color: #000;
cursor: pointer;
float: right;
line-height: 1;
height: 12px;
&:hover {
color: #d0021b;
}
}
}
.search-suggest-history {
... ... @@ -501,12 +513,6 @@
overflow: hidden;
white-space: nowrap;
}
.searchDel {
padding: 0;
color: #000;
cursor: pointer;
float: right;
}
}
.search-hot {
... ...
... ... @@ -264,6 +264,7 @@ exports.processProductList = (list, options) => {
}
pruductList.push(product);
});
return handleGoodsListData(pruductList);
};
... ...