Helper.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
'use strict';
function excludeParams(groupParams, needGender=true){
let newParams = {};
try{
let params = groupParams.toJS();
for(let key in params){
if(params[key]){
newParams[key] = params[key]
}
}
//gender 需要进行空处理,防止原生会添加默认值
if(needGender && !newParams["gender"]){
newParams["gender"] = "";
}
//size因为字段是关键字,使用了g_size替换
if(newParams["g_size"]){
newParams["size"] = newParams["g_size"];
delete newParams["g_size"]
}
}catch(e){
}
return newParams;
}
function joinWxProgramPath(wxPath, groupParams){
let params = excludeParams(groupParams, false);
let paramStr = "";
for(let key in params){
paramStr = paramStr + "&" + key + "=" + params[key];
}
if(wxPath.indexOf("?") != -1){
wxPath = wxPath + paramStr;
}else{
wxPath = wxPath + "?" + paramStr.substring(1);
}
return wxPath;
}
module.exports = {
excludeParams,
joinWxProgramPath
};