Authored by 郭成尧

pathParams-handle

@@ -120,13 +120,22 @@ const sortParams = (req, res, next) => { @@ -120,13 +120,22 @@ const sortParams = (req, res, next) => {
120 */ 120 */
121 const resolvePathParams = (req, res, next) => { 121 const resolvePathParams = (req, res, next) => {
122 let queryParams = req.query; 122 let queryParams = req.query;
  123 + let pathParams = req.params.pathParams;
123 124
124 // 1. 取 path 的参数 125 // 1. 取 path 的参数
125 - req.query = listParamsProcess.getParams(req.path); 126 + req.query = listParamsProcess.getParams(pathParams);
126 127
127 // 2. 取查询字符串参数 128 // 2. 取查询字符串参数
128 _.assign(req.query, queryParams); 129 _.assign(req.query, queryParams);
129 130
  131 + // 3. 取 params 参数
  132 + if (req.params) {
  133 + if (req.params.pathParams) {
  134 + delete req.params.pathParams;
  135 + }
  136 + _.assign(req.query, req.params);
  137 + }
  138 +
130 if (req.query) { 139 if (req.query) {
131 _.forEach(req.query, (perParam, index) => { 140 _.forEach(req.query, (perParam, index) => {
132 req.query[index] = stringProcess.paramsFilter(perParam); 141 req.query[index] = stringProcess.paramsFilter(perParam);
@@ -139,7 +148,8 @@ const resolvePathParams = (req, res, next) => { @@ -139,7 +148,8 @@ const resolvePathParams = (req, res, next) => {
139 * 解析 Path 类型泛商品列表异步请求中 URL 的参数 148 * 解析 Path 类型泛商品列表异步请求中 URL 的参数
140 */ 149 */
141 const resolvePathParamsAjax = (req, res, next) => { 150 const resolvePathParamsAjax = (req, res, next) => {
142 - let currentUrlParams = listParamsProcess.getParams(req.query.currentUrl); 151 + let pathParams = _.last(_.split(req.query.currentUrl, '/'));
  152 + let currentUrlParams = listParamsProcess.getParams(pathParams);
143 153
144 delete req.query.currentUrl; 154 delete req.query.currentUrl;
145 155
@@ -40,14 +40,13 @@ const PARAMMAP = { @@ -40,14 +40,13 @@ const PARAMMAP = {
40 }; 40 };
41 41
42 /** 42 /**
43 - * 获取标准参数 43 + * 解析 pathParams 获取标准参数
44 */ 44 */
45 -const getParams = (url) => {  
46 - let params = [];  
47 - let paramStringRaw = _.last(_.split(url, '/')); 45 +const getParams = (pathParams) => {
  46 + let params = {};
48 47
49 - if (paramStringRaw) {  
50 - let paramsRaw = _.split(paramStringRaw, '-'); 48 + if (pathParams) {
  49 + let paramsRaw = _.split(pathParams, '-');
51 50
52 _.forEach(paramsRaw, paramRaw => { 51 _.forEach(paramsRaw, paramRaw => {
53 let keyRaw = paramRaw.substr(0, 2); 52 let keyRaw = paramRaw.substr(0, 2);