list-params-process.js
1.11 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
const _ = require('lodash');
/**
* 参数列表
*/
const PARAMMAP = {
ag: 'age_level',
gd: 'gender',
sn: 'sort_name',
pa: 'phrase',
ci: 'category_id',
so: 'sort',
ms: 'msort',
mi: 'misort',
tp: 'type',
sz: 'size',
cl: 'color',
pc: 'price',
bd: 'brand',
qr: 'query',
lt: 'limit',
ld: 'limited',
od: 'order',
nw: 'new',
pg: 'page',
st: 'style',
sd: 'standard',
si: 'specialsale_id',
sf: 'specialoffer'
};
/**
* 获取标准参数
*/
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
};