Authored by 郭成尧

init

@@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel { @@ -39,7 +39,7 @@ module.exports = class extends global.yoho.BaseModel {
39 if (firstItem.sub && firstItem.sub.length) { 39 if (firstItem.sub && firstItem.sub.length) {
40 _.map(firstItem.sub, function(secondItem) { 40 _.map(firstItem.sub, function(secondItem) {
41 secondItem.url = helpers.urlFormat('/', utils.mapSort({ 41 secondItem.url = helpers.urlFormat('/', utils.mapSort({
42 - sort: _.get(secondItem, 'relation_parameter.sort'), 42 + categoryId: _.get(secondItem, 'category_id'),
43 sort_name: secondItem.category_name, 43 sort_name: secondItem.category_name,
44 gender: genderMap[key] || '' 44 gender: genderMap[key] || ''
45 }), 'list'); 45 }), 'list');
@@ -48,14 +48,14 @@ module.exports = class extends global.yoho.BaseModel { @@ -48,14 +48,14 @@ module.exports = class extends global.yoho.BaseModel {
48 firstItem.sub.unshift({ 48 firstItem.sub.unshift({
49 category_name: `全部${firstItem.category_name}`, 49 category_name: `全部${firstItem.category_name}`,
50 url: helpers.urlFormat('/', utils.mapSort({ 50 url: helpers.urlFormat('/', utils.mapSort({
51 - sort: _.get(firstItem, 'relation_parameter.sort'), 51 + categoryId: _.get(firstItem, 'category_id'),
52 sort_name: firstItem.category_name, 52 sort_name: firstItem.category_name,
53 gender: genderMap[key] || '' 53 gender: genderMap[key] || ''
54 }), 'list') 54 }), 'list')
55 }); 55 });
56 } else { 56 } else {
57 firstItem.url = helpers.urlFormat('/', utils.mapSort({ 57 firstItem.url = helpers.urlFormat('/', utils.mapSort({
58 - sort: _.get(firstItem, 'relation_parameter.sort'), 58 + categoryId: _.get(firstItem, 'category_id'),
59 sort_name: firstItem.category_name, 59 sort_name: firstItem.category_name,
60 gender: genderMap[key] || '' 60 gender: genderMap[key] || ''
61 }), 'list'); 61 }), 'list');
@@ -212,6 +212,7 @@ const category = (req, res, next) => { @@ -212,6 +212,7 @@ const category = (req, res, next) => {
212 } 212 }
213 213
214 let params = Object.assign({}, req.query); 214 let params = Object.assign({}, req.query);
  215 + let seoTitle = decodeURIComponent(req.query.title || req.query.sort_name);
215 216
216 /* 勿修改,唤起 APP 使用 */ 217 /* 勿修改,唤起 APP 使用 */
217 let appParams = Object.assign({}, req.query, { 218 let appParams = Object.assign({}, req.query, {
@@ -252,7 +253,7 @@ const category = (req, res, next) => { @@ -252,7 +253,7 @@ const category = (req, res, next) => {
252 currentHref: 'https://www.yohobuy.com/list?' // TODO 253 currentHref: 'https://www.yohobuy.com/list?' // TODO
253 }, 254 },
254 pageHeader: headerModel.setNav({ 255 pageHeader: headerModel.setNav({
255 - navTitle: req.query.title || req.query.sort_name 256 + navTitle: seoTitle
256 }), 257 }),
257 goodList: params, 258 goodList: params,
258 firstPageGoods: firstPageGoods || [], 259 firstPageGoods: firstPageGoods || [],
@@ -263,7 +264,7 @@ const category = (req, res, next) => { @@ -263,7 +264,7 @@ const category = (req, res, next) => {
263 localCss: true, 264 localCss: true,
264 appPath: appPath, 265 appPath: appPath,
265 introText: req.query.intro_text 266 introText: req.query.intro_text
266 - }, searchProcess.getListSeoData(req.query.gender, req.query.title || req.query.sort_name))); 267 + }, searchProcess.getListSeoData(req.query.gender, seoTitle)));
267 }).catch(next); 268 }).catch(next);
268 }; 269 };
269 270
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 */ 3 */
4 const querystring = require('querystring'); 4 const querystring = require('querystring');
5 const helpers = global.yoho.helpers; 5 const helpers = global.yoho.helpers;
  6 +const listParamsProcess = require('../../utils/list-params-process');
6 7
7 module.exports = () => { 8 module.exports = () => {
8 return (req, res, next) => { 9 return (req, res, next) => {
@@ -73,6 +74,8 @@ module.exports = () => { @@ -73,6 +74,8 @@ module.exports = () => {
73 } 74 }
74 75
75 if (/^\/list/.test(req.url)) { 76 if (/^\/list/.test(req.url)) {
  77 + req.query = listParamsProcess.getParams(req.url);
  78 +
76 // 列表页路由重写 新路由 79 // 列表页路由重写 新路由
77 req.url = `/product/index/index?${querystring.stringify(req.query)}`; 80 req.url = `/product/index/index?${querystring.stringify(req.query)}`;
78 } 81 }
  1 +const _ = require('lodash');
  2 +
  3 +/**
  4 + * 参数列表
  5 + */
  6 +const PARAMMAP = {
  7 + gd: 'gender',
  8 + sn: 'sort_name',
  9 + so: 'sort',
  10 + ms: 'msort',
  11 + mi: 'misort',
  12 + tp: 'type',
  13 + sz: 'size',
  14 + cl: 'color',
  15 + pc: 'price',
  16 + bd: 'brand',
  17 + qr: 'type'
  18 +};
  19 +
  20 +/**
  21 + * 获取标准参数
  22 + */
  23 +const getParams = (url) => {
  24 + let params = [];
  25 + let paramStringRaw = _.split(url, '/list/')[1];
  26 +
  27 + if (paramStringRaw) {
  28 + let paramsRaw = _.split(paramStringRaw, '-');
  29 +
  30 + _.forEach(paramsRaw, paramRaw => {
  31 + let keyRaw = paramRaw.substr(0, 2);
  32 + let valueRaw = _.replace(paramRaw, keyRaw, '');
  33 +
  34 + if (PARAMMAP[keyRaw]) {
  35 + params[PARAMMAP[keyRaw]] = valueRaw;
  36 + }
  37 + });
  38 + }
  39 +
  40 + return params;
  41 +};
  42 +
  43 +/**
  44 + * 生成链接
  45 + */
  46 +const generateUrl = () => {
  47 + return '';
  48 +};
  49 +
  50 +module.exports = {
  51 + getParams,
  52 + generateUrl
  53 +};