Authored by 郭成尧

list-params-handle

... ... @@ -16,6 +16,7 @@ const searchModel = require(`${mRoot}/search`);
const shopModel = require(`${mRoot}/shop`);
const searchProcess = require(`${utils}/search-process`);
const stringProcess = require(`${utils}/string-process`);
const listParamsProcess = require(`${utils}/list-params-process`);
/**
* 从 useragent 获取 uid
... ... @@ -212,7 +213,7 @@ const category = (req, res, next) => {
}
let params = Object.assign({}, req.query);
let seoTitle = decodeURIComponent(req.query.title || req.query.sort_name);
let seoTitle = decodeURIComponent(req.query.title || req.query.sort_name || '商品列表');
/* 勿修改,唤起 APP 使用 */
let appParams = Object.assign({}, req.query, {
... ... @@ -269,6 +270,16 @@ const category = (req, res, next) => {
};
/**
* 参数处理的前置处理,新的路由
*/
const listNew = (req, res, next) => {
req.query = listParamsProcess.getParams(req.url);
// 转发到旧的处理方法
category(req, res, next);
};
/**
* 品牌店铺的入口
* @param req
* @param res
... ... @@ -547,5 +558,6 @@ module.exports = {
shopFav,
baseShopFav,
shopCategory,
getBrandCouponsList
getBrandCouponsList,
listNew
};
... ...
... ... @@ -158,6 +158,7 @@ router.get('/search/shop/goods', search.searchShopGoods); // 搜索店铺下的
// 品类
router.get('/index/index', rewrite.sortParams, list.category);
router.get('/list/index', rewrite.sortParams, list.category); // 兼容 PC 的链接
router.get(/^\/list/, list.listNew); // 列表新的 URL
// 品牌 | 店铺
router.get('/index/shopAppCookie', list.shopAppCookie);
... ...
/**
* URL 重写(主要用于兼容原来PHP的连接)
*/
const querystring = require('querystring');
const helpers = global.yoho.helpers;
const listParamsProcess = require('../../utils/list-params-process');
module.exports = () => {
return (req, res, next) => {
... ... @@ -74,10 +73,8 @@ module.exports = () => {
}
if (/^\/list/.test(req.url)) {
req.query = listParamsProcess.getParams(req.url);
// 列表页路由重写 新路由
req.url = `/product/index/index?${querystring.stringify(req.query)}`;
// 列表页路由重写 跳转到新的列表路由,进行参数的前置处理
req.url = `/product/${req.url}`;
}
next();
... ...
... ... @@ -7,6 +7,7 @@ const PARAMMAP = {
gd: 'gender',
sn: 'sort_name',
so: 'sort',
ci: 'categoryId',
ms: 'msort',
mi: 'misort',
tp: 'type',
... ... @@ -14,7 +15,7 @@ const PARAMMAP = {
cl: 'color',
pc: 'price',
bd: 'brand',
qr: 'type'
qr: 'query'
};
/**
... ...