...
|
...
|
@@ -9,7 +9,6 @@ |
|
|
const _ = require('lodash');
|
|
|
|
|
|
// const logger = global.yoho.logger;
|
|
|
const queryString = require('querystring');
|
|
|
|
|
|
const minToFullMap = {
|
|
|
ag: 'age_level',
|
...
|
...
|
@@ -48,9 +47,21 @@ const minToFullMap = { |
|
|
};
|
|
|
|
|
|
const fullToMinMap = _.transform(minToFullMap, (result, value, key) => {
|
|
|
result[value] = key;
|
|
|
if (_.indexOf(['gender', 'brand', 'category_id', 'color', 'style'], value) > -1) {
|
|
|
result[value] = key;
|
|
|
}
|
|
|
}, {});
|
|
|
|
|
|
const sringifyParam = (param) => {
|
|
|
let arr = [];
|
|
|
|
|
|
_.forEach(param, (value, key) => {
|
|
|
arr.push(`${key}=${value}`);
|
|
|
});
|
|
|
|
|
|
return arr.join('&');
|
|
|
};
|
|
|
|
|
|
const transformKey = (params, isFull) => {
|
|
|
if (_.isEmpty(params)) {
|
|
|
return params;
|
...
|
...
|
@@ -78,6 +89,12 @@ const transformKey = (params, isFull) => { |
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 筛选参数转化 min->full
|
|
|
* @param path 伪静态path
|
|
|
* @returns {Object}
|
|
|
*/
|
|
|
|
|
|
const minPathToFullParam = (path) => {
|
|
|
let obj = {};
|
|
|
|
...
|
...
|
@@ -98,9 +115,11 @@ const minPathToFullParam = (path) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 筛选参数
|
|
|
* @param originParam 当前 URL 中的参数
|
|
|
* @param newParam 要拼接的 参数
|
|
|
* 筛选参数转化 full->min
|
|
|
* @param uri 基础uri
|
|
|
* @param params 当前 URL 中的参数
|
|
|
* @param newObj 新增的参数
|
|
|
* @param delObj 删除的参数
|
|
|
* @returns {string}
|
|
|
*/
|
|
|
const fullParamToMinPath = (uri, params, newObj, delObj = {}) => {
|
...
|
...
|
@@ -123,7 +142,7 @@ const fullParamToMinPath = (uri, params, newObj, delObj = {}) => { |
|
|
});
|
|
|
|
|
|
if (!_.isEmpty(transParams.extraParams)) {
|
|
|
extraQs = '?' + queryString.stringify(transParams.extraParams);
|
|
|
extraQs = '?' + sringifyParam(transParams.extraParams);
|
|
|
}
|
|
|
|
|
|
return _.trimEnd(uri, '/') + '/' + _.sortBy(pathArr).join('-') + extraQs;
|
...
|
...
|
|