urlHandler.js
724 Bytes
export function urlAddParamOfType(url, type='0') {
if (!type) {
return url;
}
let strs= new Array();
let dataString = '';
if (url.indexOf('yohobuy=') !== -1) {
strs = url.split("yohobuy=");
if (strs.length == 1) {
dataString = strs[0];
} else {
dataString = strs[1];
}
} else {
strs = url.split("yohobuy=");
if (strs.length == 1) {
dataString = strs[0];
} else {
dataString = strs[1];
}
}
var obj = JSON.parse(dataString); //由JSON字符串转换为JSON对象
obj.params.type = type + ''; // params增加type参数
let totalUrlWithType = "yohobuy=" + JSON.stringify(obj);
if (strs.length > 1) {
totalUrlWithType = strs[0] + totalUrlWithType;
}
return totalUrlWithType;
}