Authored by 郭成尧

pathParams-handle

... ... @@ -120,13 +120,22 @@ const sortParams = (req, res, next) => {
*/
const resolvePathParams = (req, res, next) => {
let queryParams = req.query;
let pathParams = req.params.pathParams;
// 1. 取 path 的参数
req.query = listParamsProcess.getParams(req.path);
req.query = listParamsProcess.getParams(pathParams);
// 2. 取查询字符串参数
_.assign(req.query, queryParams);
// 3. 取 params 参数
if (req.params) {
if (req.params.pathParams) {
delete req.params.pathParams;
}
_.assign(req.query, req.params);
}
if (req.query) {
_.forEach(req.query, (perParam, index) => {
req.query[index] = stringProcess.paramsFilter(perParam);
... ... @@ -139,7 +148,8 @@ const resolvePathParams = (req, res, next) => {
* 解析 Path 类型泛商品列表异步请求中 URL 的参数
*/
const resolvePathParamsAjax = (req, res, next) => {
let currentUrlParams = listParamsProcess.getParams(req.query.currentUrl);
let pathParams = _.last(_.split(req.query.currentUrl, '/'));
let currentUrlParams = listParamsProcess.getParams(pathParams);
delete req.query.currentUrl;
... ...
... ... @@ -40,14 +40,13 @@ const PARAMMAP = {
};
/**
* 获取标准参数
* 解析 pathParams 获取标准参数
*/
const getParams = (url) => {
let params = [];
let paramStringRaw = _.last(_.split(url, '/'));
const getParams = (pathParams) => {
let params = {};
if (paramStringRaw) {
let paramsRaw = _.split(paramStringRaw, '-');
if (pathParams) {
let paramsRaw = _.split(pathParams, '-');
_.forEach(paramsRaw, paramRaw => {
let keyRaw = paramRaw.substr(0, 2);
... ...