Authored by 郭成尧

ready-for-301

1 const _ = require('lodash'); 1 const _ = require('lodash');
  2 +const config = global.yoho.config;
2 3
3 /** 4 /**
4 * 参数列表 5 * 参数列表
@@ -66,12 +67,33 @@ const getParams = (url) => { @@ -66,12 +67,33 @@ const getParams = (url) => {
66 67
67 /** 68 /**
68 * 生成链接 69 * 生成链接
  70 + * @param {参数} queryParams
69 */ 71 */
70 -const generateUrl = () => {  
71 - return ''; 72 +const generatePathUrl = (queryParams) => {
  73 + let pathUrlParams = []; // 可以找到对应关系的参数
  74 + let noFindParams = []; // 没有找到对应关系的
  75 + let pathUrl = '';
  76 +
  77 + _.forEach(queryParams, (value, key) => {
  78 + let paramKey = _.findKey(PARAMMAP, o => {
  79 + return o === key;
  80 + });
  81 +
  82 + if (paramKey) {
  83 + pathUrlParams.push(paramKey + value + '');
  84 + } else {
  85 + noFindParams.push(key + '=' + value);
  86 + }
  87 + });
  88 +
  89 + pathUrl = pathUrlParams.length ? pathUrlParams.join('-') : '';
  90 + pathUrl += noFindParams.length ? '?' + noFindParams.join('&') : '';
  91 + pathUrl = (pathUrl && !_.startsWith(pathUrl, '?')) ? `/${pathUrl}` : pathUrl;
  92 +
  93 + return `//m.yohobuy.com/list${pathUrl}`;
72 }; 94 };
73 95
74 module.exports = { 96 module.exports = {
75 getParams, 97 getParams,
76 - generateUrl 98 + generatePathUrl
77 }; 99 };