Authored by yyq

change url

... ... @@ -402,13 +402,14 @@ class FilterTools {
let {baseUrl, params} = this;
const href = handleFilterUrl(baseUrl, params, {gender: '${gender}'});
// 伪静态化路由参数转化时将gender做了转化 '1,3'=>'1', '2,3'=>'2', 业务中直接生成路由需做调整
return [{
name: 'BOYS',
href: href.replace('${gender}', '1,3'),
href: href.replace('${gender}', '1'),
checked: params.gender === '1,3'
}, {
name: 'GIRLS',
href: href.replace('${gender}', '2,3'),
href: href.replace('${gender}', '2'),
checked: params.gender === '2,3'
}];
}
... ...
'use strict';
const _ = require('lodash');
const parameter = require(`${global.utils}/parameter`);
module.exports = (req, res, next) => {
let param = req.params.pathQs;
param = _.trimEnd(param, '.html');
if (param) {
Object.assign(req.query, parameter.minPathToFullParam(param));
}
... ...
... ... @@ -52,11 +52,25 @@ const fullToMinMap = _.transform(minToFullMap, (result, value, key) => {
}
}, {});
const genderMap = {
minToFull: {
1: '1,3',
2: '2,3'
},
fullToMin: {
'1,3': 1,
'2,3': 2,
'1,2,3': ''
}
};
const sringifyParam = (param) => {
let arr = [];
_.forEach(param, (value, key) => {
arr.push(`${key}=${value}`);
if (value) {
arr.push(`${key}=${value}`);
}
});
return arr.join('&');
... ... @@ -74,7 +88,8 @@ const transformKey = (params, isFull) => {
_.forEach(params, (value, key) => {
let name = map[key];
if (name) {
// 包含',' & 等于{seat} 表示为多选,不需要伪静态
if (name && _.indexOf(value, ',') === -1 && value !== '{seat}') {
matchParams[name] = value;
} else {
extraParams[key] = value;
... ... @@ -111,6 +126,8 @@ const minPathToFullParam = (path) => {
}
});
obj.gender = genderMap.minToFull[obj.gender] || obj.gender || '1,2,3';
return obj;
};
... ... @@ -133,6 +150,10 @@ const fullParamToMinPath = (uri, params, newObj, delObj = {}) => {
_.has(obj, key) && _.unset(obj, key);
});
if (obj.gender) {
obj.gender = _.has(genderMap.fullToMin, obj.gender) ? genderMap.fullToMin[obj.gender] : obj.gender;
}
let transParams = transformKey(obj, true);
_.forEach(transParams.matchParams, (value, key) => {
... ... @@ -145,7 +166,9 @@ const fullParamToMinPath = (uri, params, newObj, delObj = {}) => {
extraQs = '?' + sringifyParam(transParams.extraParams);
}
return _.trimEnd(uri, '/') + '/' + _.sortBy(pathArr).join('-') + extraQs;
let minPath = _.sortBy(pathArr).join('-') + (pathArr.length ? '.html' : '');
return `${_.trimEnd(uri, '/')}/${minPath}${extraQs}`;
};
... ...