VistarStarDataIntegration/admin.net.pro/App/utils/getUrlParam.js
2024-09-09 09:23:58 +08:00

24 lines
764 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function GetUrlParam(name) {
// var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
// var r = window.location.search.substr(1).match(reg);
// if (r != null) return unescape(r[2]);
// return null;
var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
if (reg.test(decodeURI(window.location)))
return unescape(RegExp.$2.replace(/\+/g, " ")).split('#')[0]; //去掉#后面的
return "";
}
export function getRequestParams(url) {
// 解析URL地址获取参数部分
const paramsString = url.split('?')[1];
// 解析参数字符串,获取参数对象
const params = {};
paramsString.split('&').forEach(param => {
const [key, value] = param.split('=');
params[key] = decodeURIComponent(value);
});
return params;
}