urlHandler.js 807 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];
		}
	}
	try {
		var obj = {};
		if (dataString.length > 1) {
			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;
	} catch (e) {

	}

}