Authored by 陈峰

merge

... ... @@ -7,6 +7,7 @@
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const utils = require('../../../utils');
const genderMap = {
boys: '1,3',
... ... @@ -33,27 +34,27 @@ let _processCateData = (list, channel) => {
// 如果有二级菜单,二级菜单跳转,否则一级菜单跳转
if (firstItem.sub && firstItem.sub.length) {
_.map(firstItem.sub, function(secondItem) {
secondItem.url = helpers.urlFormat('/', {
secondItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(secondItem, 'relation_parameter.sort'),
sort_name: secondItem.category_name,
gender: genderMap[key] || ''
}, 'list');
}), 'list');
});
firstItem.sub.unshift({
category_name: `全部${firstItem.category_name}`,
url: helpers.urlFormat('/', {
url: helpers.urlFormat('/', utils.mapSort({
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || ''
}, 'list')
}), 'list')
});
} else {
firstItem.url = helpers.urlFormat('/', {
firstItem.url = helpers.urlFormat('/', utils.mapSort({
sort: _.get(firstItem, 'relation_parameter.sort'),
sort_name: firstItem.category_name,
gender: genderMap[key] || ''
}, 'list');
}), 'list');
}
});
});
... ...
... ... @@ -103,7 +103,7 @@ const editorRedirect = (req, res, next) => {
param = '?' + param;
}
redirectUrl += `-${id}/${param}`;
res.redirect(redirectUrl);
res.redirect(301, redirectUrl);
} else {
return next();
}
... ...
... ... @@ -469,7 +469,7 @@ const indexRedirect = (req, res, next) => {
param = '?' + param;
}
redirectUrl += `${id}.html${param}`;
res.redirect(redirectUrl);
res.redirect(301, redirectUrl);
} else {
return next();
}
... ...
... ... @@ -86,7 +86,7 @@ const newDetail = {
reject();
}
}).then(skn => {
return res.redirect(`/product/${skn}.html${param}`);
return res.redirect(301, `/product/${skn}.html${param}`);
}, () => {
return next();
});
... ...
... ... @@ -130,7 +130,7 @@ router.get('/seckill/get-product-list', seckill.getProductList); // 秒杀列表
router.get('/search/index', search.index);
// 搜索落地页
router.get('/search/list', search.list);
router.get('/search/list', rewrite.sortParams, search.list);
// filter
router.get('/search/filter', search.filter);
... ... @@ -142,8 +142,8 @@ router.get('/search/fuzzyDatas', search.fuzzyDatas);
router.get('/search/search', search.search);
// 品类
router.get('/index/index', list.category);
router.get('/list/index', list.category); // 兼容 PC 的链接
router.get('/index/index', rewrite.sortParams, list.category);
router.get('/list/index', rewrite.sortParams, list.category); // 兼容 PC 的链接
// 品牌 | 店铺
router.get('/index/shopAppCookie', list.shopAppCookie);
... ...
... ... @@ -4,8 +4,8 @@
<div id="search-input" class="search-input">
<form id="search-form" action="{{url}}" method="get">
<i class="search-icon iconfont">&#xe60f;</i>
<input type="text" placeholder="{{#if defaultTerms}}{{defaultTerms}}{{else}}搜索商品、品牌{{/if}}" name="query" data-bp-id="search_page_input_1" class="buriedpoint" autocomplete="off">
<input type="hidden" name="from" value="search">
<input type="text" placeholder="{{#if defaultTerms}}{{defaultTerms}}{{else}}搜索商品、品牌{{/if}}" name="query" data-bp-id="search_page_input_1" class="buriedpoint" autocomplete="off">
<i class="clear-input iconfont hide">&#xe626;</i>
<span id="search" class="search buriedpoint" type="submit" data-bp-id="search_index_one_0">搜索</span>
</form>
... ...
... ... @@ -7,7 +7,13 @@
const typeLib = require('../../config/type-lib');
const _ = require('lodash');
const utils = require('../../utils');
const helpers = global.yoho.helpers;
/**
* 解析url规则中的参数
*/
const resolve = (req, res, next) => {
let path,
params = {
... ... @@ -44,6 +50,9 @@ const resolve = (req, res, next) => {
next();
};
/**
* 简介channel参数
*/
const channel = (req, res, next) => {
let channelName;
... ... @@ -79,7 +88,26 @@ const channel = (req, res, next) => {
next();
};
/**
* 参数排序
*/
const sortParams = (req, res, next) => {
let sorts = utils.mapSort(req.query);
let queryKeys = _.keys(req.query);
let index = 0;
let matched = _.map(sorts, (val, key) => {
return key === queryKeys[index++];
});
if (_.every(matched, match => match)) {
return next();
} else {
return res.redirect(helpers.urlFormat('/', sorts, 'list'));
}
};
module.exports = {
resolve,
channel
channel,
sortParams
};
... ...
... ... @@ -166,6 +166,22 @@ function queryString() {
return vars;
}
/**
* 对象字段排序
*/
function mapSort (obj) {
if (!obj) {
return {};
}
let data = {};
Object.keys(obj).sort().forEach(k => {
data[k] = obj[k];
});
return data;
}
// 给jQuery 扩展 queryString函数
$.extend({
queryString: queryString
... ... @@ -462,3 +478,5 @@ window.givePoint = givePoint;
window._ChannelVary = _ChannelVary;
window.downLoadApp = downLoadApp;
window.mapSort = mapSort;
... ...
... ... @@ -30,3 +30,19 @@ exports.refererLimit = (referer, blacklist) => { // eslint-disable-line
return result;
};
/**
* 对象字段排序
*/
exports.mapSort = obj => {
if (!obj) {
return {};
}
let data = {};
Object.keys(obj).sort().forEach(k => {
data[k] = obj[k];
});
return data;
};
... ...