Authored by zhangxiaoru

猜你想找接口

@@ -132,13 +132,14 @@ const list = (req, res, next) => { @@ -132,13 +132,14 @@ const list = (req, res, next) => {
132 * 搜索主页 132 * 搜索主页
133 */ 133 */
134 const index = (req, res, next) => { 134 const index = (req, res, next) => {
135 - let title = '搜索'; 135 + let title = '搜索',
  136 + uid = req.user.uid || 0;
136 137
137 ((render) => { 138 ((render) => {
138 if (_.get(req, 'app.locals.wap.search.removeHotSearch', false)) { 139 if (_.get(req, 'app.locals.wap.search.removeHotSearch', false)) {
139 render([]); 140 render([]);
140 } else { 141 } else {
141 - searchModel.getSearchIndex().then((result) => { 142 + searchModel.getSearchIndex(uid).then((result) => {
142 render(result); 143 render(result);
143 }).catch(next); 144 }).catch(next);
144 } 145 }
@@ -152,9 +153,10 @@ const index = (req, res, next) => { @@ -152,9 +153,10 @@ const index = (req, res, next) => {
152 }), 153 }),
153 pageFooter: true, 154 pageFooter: true,
154 search: { 155 search: {
155 - defaultTerms: (result && result.defaultTerms && result.defaultTerms.length !== 0) ? result.defaultTerms[0].content : '', 156 + defaultTerms: (result && result.hotTerms && result.hotTerms.defaultTerms && result.hotTerms.defaultTerms.length !== 0) ? result.hotTerms.defaultTerms[0].content : '',
156 url: helpers.urlFormat('', null, 'search'), 157 url: helpers.urlFormat('', null, 'search'),
157 - hotTerms: result.hotTerms 158 + hotTerms: result.hotTerms.hotTerms,
  159 + wantTerms: result.wantTerms.guessTerms
158 } 160 }
159 161
160 }); 162 });
@@ -163,7 +163,7 @@ const getSearchData = (params) => { @@ -163,7 +163,7 @@ const getSearchData = (params) => {
163 gender: _coverChannel[params.coverChannel] 163 gender: _coverChannel[params.coverChannel]
164 }); 164 });
165 165
166 - if (parseInt(params.page) === 1) { 166 + if (parseInt(params.page, 10) === 1) {
167 newList.total = result.data.total; 167 newList.total = result.data.total;
168 } 168 }
169 169
@@ -244,15 +244,37 @@ const getAllBrandNames = () => { @@ -244,15 +244,37 @@ const getAllBrandNames = () => {
244 }; 244 };
245 245
246 /** 246 /**
  247 + * 获取猜你想找
  248 + **/
  249 +const getWantSearch = (uid) => {
  250 + return api.get('', {
  251 + method: 'app.search.getSomeTerms',
  252 + uid: uid
  253 + }, {
  254 + cache: true
  255 + }).then((result) => {
  256 + if (result && result.code === 200) {
  257 + return result.data;
  258 + } else {
  259 + logger.error('Hot Search return code is not 200');
  260 + return {};
  261 + }
  262 + });
  263 +};
  264 +
  265 +/**
247 * 获取热门搜索 266 * 获取热门搜索
248 **/ 267 **/
249 -const getSearchIndex = () => { 268 +const getHotSearch = () => {
250 return api.get('', { 269 return api.get('', {
251 method: 'app.search.getTerms' 270 method: 'app.search.getTerms'
252 }, { 271 }, {
253 cache: true 272 cache: true
254 }).then((result) => { 273 }).then((result) => {
255 if (result && result.code === 200) { 274 if (result && result.code === 200) {
  275 + if (result.data.hotTerms && result.data.hotTerms.length > 10) {
  276 + result.data.hotTerms = result.data.hotTerms.slice(0, 10);
  277 + }
256 return result.data; 278 return result.data;
257 } else { 279 } else {
258 logger.error('Hot Search return code is not 200'); 280 logger.error('Hot Search return code is not 200');
@@ -262,6 +284,18 @@ const getSearchIndex = () => { @@ -262,6 +284,18 @@ const getSearchIndex = () => {
262 }; 284 };
263 285
264 /** 286 /**
  287 + * 搜索主页
  288 + */
  289 +const getSearchIndex = (uid) => {
  290 + return Promise.all([getHotSearch(), getWantSearch(uid)]).then((result) => {
  291 + return {
  292 + hotTerms: result[0],
  293 + wantTerms: result[1]
  294 + };
  295 + });
  296 +};
  297 +
  298 +/**
265 * 获取联想词 299 * 获取联想词
266 * @param params 300 * @param params
267 * @returns {*|Promise.<TResult>} 301 * @returns {*|Promise.<TResult>}
@@ -13,7 +13,8 @@ @@ -13,7 +13,8 @@
13 <ul class="search-associate"></ul> 13 <ul class="search-associate"></ul>
14 14
15 <div class="search-items"> 15 <div class="search-items">
16 - <div class="hot-search-new"> 16 + {{#if hotTerms}}
  17 + <div class="hot-search-new search-group">
17 18
18 <div class="search-content new-hot"> 19 <div class="search-content new-hot">
19 <ul class="clearfix swiper-wrapper"> 20 <ul class="clearfix swiper-wrapper">
@@ -26,6 +27,7 @@ @@ -26,6 +27,7 @@
26 </ul> 27 </ul>
27 </div> 28 </div>
28 </div> 29 </div>
  30 + {{/if}}
29 <div class="search-group history-search"> 31 <div class="search-group history-search">
30 <div class="search-content-title"> 32 <div class="search-content-title">
31 <h3 class="left">最近搜索</h3> 33 <h3 class="left">最近搜索</h3>
@@ -35,16 +37,16 @@ @@ -35,16 +37,16 @@
35 <ul class="history clearfix"></ul> 37 <ul class="history clearfix"></ul>
36 </div> 38 </div>
37 </div> 39 </div>
38 - {{#if hotTerms}}  
39 - <div class="search-group hot-search"> 40 + {{#if wantTerms}}
  41 + <div class="search-group want-search">
40 <h3>猜你想找</h3> 42 <h3>猜你想找</h3>
41 <div class="search-content"> 43 <div class="search-content">
42 - <ul class="hot clearfix">  
43 - {{# hotTerms}} 44 + <ul class="want clearfix">
  45 + {{# wantTerms}}
44 <li> 46 <li>
45 - <a href='javascript:void(0);'>{{content}}</a> 47 + <a href='javascript:void(0);'>{{.}}</a>
46 </li> 48 </li>
47 - {{/ hotTerms}} 49 + {{/ wantTerms}}
48 </ul> 50 </ul>
49 </div> 51 </div>
50 </div> 52 </div>
@@ -16,15 +16,15 @@ module.exports = { @@ -16,15 +16,15 @@ module.exports = {
16 siteUrl: '//m.yohobuy.com', 16 siteUrl: '//m.yohobuy.com',
17 assetUrl: '//localhost:5001', 17 assetUrl: '//localhost:5001',
18 domains: { 18 domains: {
19 - api: 'http://api.yoho.cn/',  
20 - service: 'http://service.yoho.cn/',  
21 - liveApi: 'http://api.live.yoho.cn/',  
22 - singleApi: 'http://single.yoho.cn/' 19 + // api: 'http://api.yoho.cn/',
  20 + // service: 'http://service.yoho.cn/',
  21 + // liveApi: 'http://api.live.yoho.cn/',
  22 + // singleApi: 'http://single.yoho.cn/'
23 23
24 - // api: 'http://api-test3.yohops.com:9999/',  
25 - // service: 'http://service-test3.yohops.com:9999/',  
26 - // liveApi: 'http://testapi.live.yohops.com:9999/',  
27 - // singleApi: 'http://api-test3.yohops.com:9999/' 24 + api: 'http://api-test3.yohops.com:9999/',
  25 + service: 'http://service-test3.yohops.com:9999/',
  26 + liveApi: 'http://testapi.live.yohops.com:9999/',
  27 + singleApi: 'http://api-test3.yohops.com:9999/'
28 28
29 // favApi: 'http://192.168.102.31:8092/brower', 29 // favApi: 'http://192.168.102.31:8092/brower',
30 // api: 'http://192.168.102.205:8080/gateway/', 30 // api: 'http://192.168.102.205:8080/gateway/',
@@ -125,13 +125,17 @@ function rePosFooter() { @@ -125,13 +125,17 @@ function rePosFooter() {
125 return; 125 return;
126 } 126 }
127 127
  128 + $footer.addClass('bottom');
  129 +
128 winH = Math.min($(window).height(), window.screen.availHeight); 130 winH = Math.min($(window).height(), window.screen.availHeight);
129 131
130 - if ($('body').height() <= winH) {  
131 - $footer.addClass('bottom');  
132 - } else { 132 + if ($('body').height() >= winH - parseInt($footer.css('height'), 0)) {
133 $footer.removeClass('bottom'); 133 $footer.removeClass('bottom');
134 } 134 }
  135 +
  136 + // else {
  137 + // $footer.removeClass('bottom');
  138 + // }
135 } 139 }
136 140
137 /** 141 /**
@@ -249,4 +249,6 @@ navSwiper = new Swiper('.new-hot', { @@ -249,4 +249,6 @@ navSwiper = new Swiper('.new-hot', {
249 $historySearch.hide(); 249 $historySearch.hide();
250 $clearHistory.hide(); 250 $clearHistory.hide();
251 } 251 }
  252 +
  253 + window.rePosFooter();
252 }()); 254 }());
@@ -108,7 +108,6 @@ @@ -108,7 +108,6 @@
108 108
109 .search-group { 109 .search-group {
110 background: #fff; 110 background: #fff;
111 - padding: 30px;  
112 111
113 .ico-hot { 112 .ico-hot {
114 width: 22px; 113 width: 22px;
@@ -171,7 +170,16 @@ @@ -171,7 +170,16 @@
171 } 170 }
172 171
173 .history-search { 172 .history-search {
174 - padding-top: 30px; 173 + padding: 30px;
  174 + }
  175 +
  176 + .want-search {
  177 + padding: 30px;
  178 + }
  179 +
  180 + .want {
  181 + max-height: 264px;
  182 + overflow: hidden;
175 } 183 }
176 } 184 }
177 185
@@ -317,7 +325,7 @@ @@ -317,7 +325,7 @@
317 border-bottom: 1px solid #f3f3f3; 325 border-bottom: 1px solid #f3f3f3;
318 } 326 }
319 327
320 - .hot-search { 328 + .want-search {
321 margin-top: 20px; 329 margin-top: 20px;
322 } 330 }
323 331