changeUrl () {
// 先获取到当前地址栏中的url
let currentUrl = location.href
// 找到 openid= 的位置
let openidIndex = currentUrl.indexOf('openid=')
// 找到 openid= 之后 的第一个 & 的位置
let openidLastIndex = currentUrl.indexOf('&', openidIndex)
// 定义新的链接为空
let shortURL = ''
if (openidLastIndex > -1) {
// 如果 openid= 之后还有参数
let leftStr = currentUrl.substring(0, openidIndex) // 左边截取到openid=的位置
let rightStr = currentUrl.substring(openidLastIndex + 1) // 右边从openid=之后的第一个&的位置+1 截取后面全部的参数
shortURL = leftStr + rightStr // 拼接新的链接
} else {
shortURL = currentUrl.substring(0, openidIndex - 1)
// 如果没有后续的参数,就把openid=直到最后截取掉,注意前面需要多截取一位: &或者?
}
// history.replaceState(null, null, shortURL)
window.location.href = shortURL
}