Authored by zhangxiaoru

猜你想找接口

... ... @@ -132,13 +132,14 @@ const list = (req, res, next) => {
* 搜索主页
*/
const index = (req, res, next) => {
let title = '搜索';
let title = '搜索',
uid = req.user.uid || 0;
((render) => {
if (_.get(req, 'app.locals.wap.search.removeHotSearch', false)) {
render([]);
} else {
searchModel.getSearchIndex().then((result) => {
searchModel.getSearchIndex(uid).then((result) => {
render(result);
}).catch(next);
}
... ... @@ -152,9 +153,10 @@ const index = (req, res, next) => {
}),
pageFooter: true,
search: {
defaultTerms: (result && result.defaultTerms && result.defaultTerms.length !== 0) ? result.defaultTerms[0].content : '',
defaultTerms: (result && result.hotTerms && result.hotTerms.defaultTerms && result.hotTerms.defaultTerms.length !== 0) ? result.hotTerms.defaultTerms[0].content : '',
url: helpers.urlFormat('', null, 'search'),
hotTerms: result.hotTerms
hotTerms: result.hotTerms.hotTerms,
wantTerms: result.wantTerms.guessTerms
}
});
... ...
... ... @@ -163,7 +163,7 @@ const getSearchData = (params) => {
gender: _coverChannel[params.coverChannel]
});
if (parseInt(params.page) === 1) {
if (parseInt(params.page, 10) === 1) {
newList.total = result.data.total;
}
... ... @@ -244,15 +244,37 @@ const getAllBrandNames = () => {
};
/**
* 获取猜你想找
**/
const getWantSearch = (uid) => {
return api.get('', {
method: 'app.search.getSomeTerms',
uid: uid
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error('Hot Search return code is not 200');
return {};
}
});
};
/**
* 获取热门搜索
**/
const getSearchIndex = () => {
const getHotSearch = () => {
return api.get('', {
method: 'app.search.getTerms'
}, {
cache: true
}).then((result) => {
if (result && result.code === 200) {
if (result.data.hotTerms && result.data.hotTerms.length > 10) {
result.data.hotTerms = result.data.hotTerms.slice(0, 10);
}
return result.data;
} else {
logger.error('Hot Search return code is not 200');
... ... @@ -262,6 +284,18 @@ const getSearchIndex = () => {
};
/**
* 搜索主页
*/
const getSearchIndex = (uid) => {
return Promise.all([getHotSearch(), getWantSearch(uid)]).then((result) => {
return {
hotTerms: result[0],
wantTerms: result[1]
};
});
};
/**
* 获取联想词
* @param params
* @returns {*|Promise.<TResult>}
... ...
... ... @@ -13,7 +13,8 @@
<ul class="search-associate"></ul>
<div class="search-items">
<div class="hot-search-new">
{{#if hotTerms}}
<div class="hot-search-new search-group">
<div class="search-content new-hot">
<ul class="clearfix swiper-wrapper">
... ... @@ -21,11 +22,12 @@
{{# hotTerms}}
<li class="swiper-slide hot-term">
<a href='javascript:void(0);'>{{content}}</a>
</li>
</li>
{{/ hotTerms}}
</ul>
</div>
</div>
{{/if}}
<div class="search-group history-search">
<div class="search-content-title">
<h3 class="left">最近搜索</h3>
... ... @@ -35,16 +37,16 @@
<ul class="history clearfix"></ul>
</div>
</div>
{{#if hotTerms}}
<div class="search-group hot-search">
{{#if wantTerms}}
<div class="search-group want-search">
<h3>猜你想找</h3>
<div class="search-content">
<ul class="hot clearfix">
{{# hotTerms}}
<ul class="want clearfix">
{{# wantTerms}}
<li>
<a href='javascript:void(0);'>{{content}}</a>
<a href='javascript:void(0);'>{{.}}</a>
</li>
{{/ hotTerms}}
{{/ wantTerms}}
</ul>
</div>
</div>
... ...
... ... @@ -16,15 +16,15 @@ module.exports = {
siteUrl: '//m.yohobuy.com',
assetUrl: '//localhost:5001',
domains: {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/'
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/'
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/'
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/'
// favApi: 'http://192.168.102.31:8092/brower',
// api: 'http://192.168.102.205:8080/gateway/',
... ...
... ... @@ -125,13 +125,17 @@ function rePosFooter() {
return;
}
$footer.addClass('bottom');
winH = Math.min($(window).height(), window.screen.availHeight);
if ($('body').height() <= winH) {
$footer.addClass('bottom');
} else {
if ($('body').height() >= winH - parseInt($footer.css('height'), 0)) {
$footer.removeClass('bottom');
}
// else {
// $footer.removeClass('bottom');
// }
}
/**
... ...
... ... @@ -249,4 +249,6 @@ navSwiper = new Swiper('.new-hot', {
$historySearch.hide();
$clearHistory.hide();
}
window.rePosFooter();
}());
... ...
... ... @@ -108,7 +108,6 @@
.search-group {
background: #fff;
padding: 30px;
.ico-hot {
width: 22px;
... ... @@ -171,7 +170,16 @@
}
.history-search {
padding-top: 30px;
padding: 30px;
}
.want-search {
padding: 30px;
}
.want {
max-height: 264px;
overflow: hidden;
}
}
... ... @@ -222,7 +230,7 @@
position: relative;
padding: 14px 22px;
background: #f8f8f8;
form {
width: 100%;
}
... ... @@ -317,7 +325,7 @@
border-bottom: 1px solid #f3f3f3;
}
.hot-search {
.want-search {
margin-top: 20px;
}
... ...