Authored by 陈峰

merge

@@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
7 const _ = require('lodash'); 7 const _ = require('lodash');
8 const api = global.yoho.API; 8 const api = global.yoho.API;
9 const helpers = global.yoho.helpers; 9 const helpers = global.yoho.helpers;
  10 +const utils = require('../../../utils');
10 11
11 const genderMap = { 12 const genderMap = {
12 boys: '1,3', 13 boys: '1,3',
@@ -33,27 +34,27 @@ let _processCateData = (list, channel) => { @@ -33,27 +34,27 @@ let _processCateData = (list, channel) => {
33 // 如果有二级菜单,二级菜单跳转,否则一级菜单跳转 34 // 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
34 if (firstItem.sub && firstItem.sub.length) { 35 if (firstItem.sub && firstItem.sub.length) {
35 _.map(firstItem.sub, function(secondItem) { 36 _.map(firstItem.sub, function(secondItem) {
36 - secondItem.url = helpers.urlFormat('/', { 37 + secondItem.url = helpers.urlFormat('/', utils.mapSort({
37 sort: _.get(secondItem, 'relation_parameter.sort'), 38 sort: _.get(secondItem, 'relation_parameter.sort'),
38 sort_name: secondItem.category_name, 39 sort_name: secondItem.category_name,
39 gender: genderMap[key] || '' 40 gender: genderMap[key] || ''
40 - }, 'list'); 41 + }), 'list');
41 }); 42 });
42 43
43 firstItem.sub.unshift({ 44 firstItem.sub.unshift({
44 category_name: `全部${firstItem.category_name}`, 45 category_name: `全部${firstItem.category_name}`,
45 - url: helpers.urlFormat('/', { 46 + url: helpers.urlFormat('/', utils.mapSort({
46 sort: _.get(firstItem, 'relation_parameter.sort'), 47 sort: _.get(firstItem, 'relation_parameter.sort'),
47 sort_name: firstItem.category_name, 48 sort_name: firstItem.category_name,
48 gender: genderMap[key] || '' 49 gender: genderMap[key] || ''
49 - }, 'list') 50 + }), 'list')
50 }); 51 });
51 } else { 52 } else {
52 - firstItem.url = helpers.urlFormat('/', { 53 + firstItem.url = helpers.urlFormat('/', utils.mapSort({
53 sort: _.get(firstItem, 'relation_parameter.sort'), 54 sort: _.get(firstItem, 'relation_parameter.sort'),
54 sort_name: firstItem.category_name, 55 sort_name: firstItem.category_name,
55 gender: genderMap[key] || '' 56 gender: genderMap[key] || ''
56 - }, 'list'); 57 + }), 'list');
57 } 58 }
58 }); 59 });
59 }); 60 });
@@ -103,7 +103,7 @@ const editorRedirect = (req, res, next) => { @@ -103,7 +103,7 @@ const editorRedirect = (req, res, next) => {
103 param = '?' + param; 103 param = '?' + param;
104 } 104 }
105 redirectUrl += `-${id}/${param}`; 105 redirectUrl += `-${id}/${param}`;
106 - res.redirect(redirectUrl); 106 + res.redirect(301, redirectUrl);
107 } else { 107 } else {
108 return next(); 108 return next();
109 } 109 }
@@ -469,7 +469,7 @@ const indexRedirect = (req, res, next) => { @@ -469,7 +469,7 @@ const indexRedirect = (req, res, next) => {
469 param = '?' + param; 469 param = '?' + param;
470 } 470 }
471 redirectUrl += `${id}.html${param}`; 471 redirectUrl += `${id}.html${param}`;
472 - res.redirect(redirectUrl); 472 + res.redirect(301, redirectUrl);
473 } else { 473 } else {
474 return next(); 474 return next();
475 } 475 }
@@ -86,7 +86,7 @@ const newDetail = { @@ -86,7 +86,7 @@ const newDetail = {
86 reject(); 86 reject();
87 } 87 }
88 }).then(skn => { 88 }).then(skn => {
89 - return res.redirect(`/product/${skn}.html${param}`); 89 + return res.redirect(301, `/product/${skn}.html${param}`);
90 }, () => { 90 }, () => {
91 return next(); 91 return next();
92 }); 92 });
@@ -130,7 +130,7 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表 @@ -130,7 +130,7 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
130 router.get('/search/index', search.index); 130 router.get('/search/index', search.index);
131 131
132 // 搜索落地页 132 // 搜索落地页
133 -router.get('/search/list', search.list); 133 +router.get('/search/list', rewrite.sortParams, search.list);
134 134
135 // filter 135 // filter
136 router.get('/search/filter', search.filter); 136 router.get('/search/filter', search.filter);
@@ -142,8 +142,8 @@ router.get('/search/fuzzyDatas', search.fuzzyDatas); @@ -142,8 +142,8 @@ router.get('/search/fuzzyDatas', search.fuzzyDatas);
142 router.get('/search/search', search.search); 142 router.get('/search/search', search.search);
143 143
144 // 品类 144 // 品类
145 -router.get('/index/index', list.category);  
146 -router.get('/list/index', list.category); // 兼容 PC 的链接 145 +router.get('/index/index', rewrite.sortParams, list.category);
  146 +router.get('/list/index', rewrite.sortParams, list.category); // 兼容 PC 的链接
147 147
148 // 品牌 | 店铺 148 // 品牌 | 店铺
149 router.get('/index/shopAppCookie', list.shopAppCookie); 149 router.get('/index/shopAppCookie', list.shopAppCookie);
@@ -4,8 +4,8 @@ @@ -4,8 +4,8 @@
4 <div id="search-input" class="search-input"> 4 <div id="search-input" class="search-input">
5 <form id="search-form" action="{{url}}" method="get"> 5 <form id="search-form" action="{{url}}" method="get">
6 <i class="search-icon iconfont">&#xe60f;</i> 6 <i class="search-icon iconfont">&#xe60f;</i>
7 - <input type="text" placeholder="{{#if defaultTerms}}{{defaultTerms}}{{else}}搜索商品、品牌{{/if}}" name="query" data-bp-id="search_page_input_1" class="buriedpoint" autocomplete="off">  
8 <input type="hidden" name="from" value="search"> 7 <input type="hidden" name="from" value="search">
  8 + <input type="text" placeholder="{{#if defaultTerms}}{{defaultTerms}}{{else}}搜索商品、品牌{{/if}}" name="query" data-bp-id="search_page_input_1" class="buriedpoint" autocomplete="off">
9 <i class="clear-input iconfont hide">&#xe626;</i> 9 <i class="clear-input iconfont hide">&#xe626;</i>
10 <span id="search" class="search buriedpoint" type="submit" data-bp-id="search_index_one_0">搜索</span> 10 <span id="search" class="search buriedpoint" type="submit" data-bp-id="search_index_one_0">搜索</span>
11 </form> 11 </form>
@@ -7,7 +7,13 @@ @@ -7,7 +7,13 @@
7 7
8 const typeLib = require('../../config/type-lib'); 8 const typeLib = require('../../config/type-lib');
9 const _ = require('lodash'); 9 const _ = require('lodash');
  10 +const utils = require('../../utils');
  11 +const helpers = global.yoho.helpers;
10 12
  13 +
  14 +/**
  15 + * 解析url规则中的参数
  16 + */
11 const resolve = (req, res, next) => { 17 const resolve = (req, res, next) => {
12 let path, 18 let path,
13 params = { 19 params = {
@@ -44,6 +50,9 @@ const resolve = (req, res, next) => { @@ -44,6 +50,9 @@ const resolve = (req, res, next) => {
44 next(); 50 next();
45 }; 51 };
46 52
  53 +/**
  54 + * 简介channel参数
  55 + */
47 const channel = (req, res, next) => { 56 const channel = (req, res, next) => {
48 let channelName; 57 let channelName;
49 58
@@ -79,7 +88,26 @@ const channel = (req, res, next) => { @@ -79,7 +88,26 @@ const channel = (req, res, next) => {
79 next(); 88 next();
80 }; 89 };
81 90
  91 +/**
  92 + * 参数排序
  93 + */
  94 +const sortParams = (req, res, next) => {
  95 + let sorts = utils.mapSort(req.query);
  96 + let queryKeys = _.keys(req.query);
  97 + let index = 0;
  98 + let matched = _.map(sorts, (val, key) => {
  99 + return key === queryKeys[index++];
  100 + });
  101 +
  102 + if (_.every(matched, match => match)) {
  103 + return next();
  104 + } else {
  105 + return res.redirect(helpers.urlFormat('/', sorts, 'list'));
  106 + }
  107 +};
  108 +
82 module.exports = { 109 module.exports = {
83 resolve, 110 resolve,
84 - channel 111 + channel,
  112 + sortParams
85 }; 113 };
@@ -166,6 +166,22 @@ function queryString() { @@ -166,6 +166,22 @@ function queryString() {
166 return vars; 166 return vars;
167 } 167 }
168 168
  169 +/**
  170 + * 对象字段排序
  171 + */
  172 +function mapSort (obj) {
  173 + if (!obj) {
  174 + return {};
  175 + }
  176 + let data = {};
  177 +
  178 + Object.keys(obj).sort().forEach(k => {
  179 + data[k] = obj[k];
  180 + });
  181 +
  182 + return data;
  183 +}
  184 +
169 // 给jQuery 扩展 queryString函数 185 // 给jQuery 扩展 queryString函数
170 $.extend({ 186 $.extend({
171 queryString: queryString 187 queryString: queryString
@@ -462,3 +478,5 @@ window.givePoint = givePoint; @@ -462,3 +478,5 @@ window.givePoint = givePoint;
462 window._ChannelVary = _ChannelVary; 478 window._ChannelVary = _ChannelVary;
463 479
464 window.downLoadApp = downLoadApp; 480 window.downLoadApp = downLoadApp;
  481 +
  482 +window.mapSort = mapSort;
@@ -30,3 +30,19 @@ exports.refererLimit = (referer, blacklist) => { // eslint-disable-line @@ -30,3 +30,19 @@ exports.refererLimit = (referer, blacklist) => { // eslint-disable-line
30 30
31 return result; 31 return result;
32 }; 32 };
  33 +
  34 +/**
  35 + * 对象字段排序
  36 + */
  37 +exports.mapSort = obj => {
  38 + if (!obj) {
  39 + return {};
  40 + }
  41 + let data = {};
  42 +
  43 + Object.keys(obj).sort().forEach(k => {
  44 + data[k] = obj[k];
  45 + });
  46 +
  47 + return data;
  48 +};