list-params-process.js
900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const _ = require('lodash');
/**
* 参数列表
*/
const PARAMMAP = {
gd: 'gender',
sn: 'sort_name',
so: 'sort',
ms: 'msort',
mi: 'misort',
tp: 'type',
sz: 'size',
cl: 'color',
pc: 'price',
bd: 'brand',
qr: 'type'
};
/**
* 获取标准参数
*/
const getParams = (url) => {
let params = [];
let paramStringRaw = _.split(url, '/list/')[1];
if (paramStringRaw) {
let paramsRaw = _.split(paramStringRaw, '-');
_.forEach(paramsRaw, paramRaw => {
let keyRaw = paramRaw.substr(0, 2);
let valueRaw = _.replace(paramRaw, keyRaw, '');
if (PARAMMAP[keyRaw]) {
params[PARAMMAP[keyRaw]] = valueRaw;
}
});
}
return params;
};
/**
* 生成链接
*/
const generateUrl = () => {
return '';
};
module.exports = {
getParams,
generateUrl
};