一般的前端页面跳转请求地址带参 比如 http://localhost:8777/#/crowd/customer/edit?id=256&crowdNo=DDA2023101009000001 直接加在后面即可,如果遇到复杂的比如对象为了不影响数据一般JSON.stringify(paramData)被跳转页面直接JSON.Parse(paramData)即可,但是遇到带有特殊符号的,比如“#”,“?”之类的浏览器跳转就会报错404,针对这种情况使用encodeURIComponent封装了2个函数。
/**
*参数处理
*参数加密
*{"keywords":"圈选结果数据","blacklistCustomer":#123456} => keywords=%E5%9C%88%E9%80%89%E7%BB%93%E6%9E%9C%E6%95%B0%E6%8D%AE&blacklistCustomer=%23123456&
* @param {*} params 参数
*/
export function tansParams(params) {
let result = ''
for (const propName of Object.keys(params)) {
const value = params[propName];
var part = encodeURIComponent(propName) + "=";
if (value !== null && value !== "" && typeof (value) !== "undefined") {
if (typeof value === 'object') {
for (const key of Object.keys(value)) {
if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
let params = propName + '[' + key + ']';
var subPart = encodeURIComponent(params) + "=";
result += subPart + encodeURIComponent(value[key]) + "&";
}
}
} else {
result += part + encodeURIComponent(value) + "&";
}
}
}
return result
}
/**
*参数处理
*参数解密
keywords=%E5%9C%88%E9%80%89%E7%BB%93%E6%9E%9C%E6%95%B0%E6%8D%AE&blacklistCustomer=%23123456&=>{"keywords":"圈选结果数据","blacklistCustomer":#123456}
* @param {*} params 参数
*/
export function getQueryObject(url) {
url = url == null ? window.location.href : url
const search = url.substring(url.lastIndexOf('?') + 1)
const obj = {}
const reg = /([^?&=]+)=([^?&=]*)/g
search.replace(reg, (rs, $1, $2) => {
const name = decodeURIComponent($1)
let val = decodeURIComponent($2)
val = String(val)
obj[name] = val
return rs
})
return obj
}