Commit 314ac48f by 侯体倬

webView URL多余参数删除处理

parent b220d8b5
...@@ -109,7 +109,7 @@ export default { ...@@ -109,7 +109,7 @@ export default {
if(!this.withoutScene) { if(!this.withoutScene) {
return; return;
} }
this.newPageUrl = this.pageUrl; this.newPageUrl = this.removeEmptyQueryParams(this.pageUrl);
console.log('------------------index----2') console.log('------------------index----2')
// 进入直播页面调用不息屏api // 进入直播页面调用不息屏api
console.log(this.pageUrl,this.pageUrl.includes('/liveBroadcast/lived'),"this.pageUrl.includes('/liveBroadcast/lived')") console.log(this.pageUrl,this.pageUrl.includes('/liveBroadcast/lived'),"this.pageUrl.includes('/liveBroadcast/lived')")
...@@ -498,7 +498,7 @@ export default { ...@@ -498,7 +498,7 @@ export default {
} }
} }
this.newPageUrl = this.pageUrl; this.newPageUrl = this.removeEmptyQueryParams(this.pageUrl);
console.log('this.newPageUrl', this.newPageUrl) console.log('this.newPageUrl', this.newPageUrl)
// 商品分享进入 (卡片分享、扫码、点击小程序链接) // 商品分享进入 (卡片分享、扫码、点击小程序链接)
if (this.newPageUrl.includes('/goods/') && (options.share || options.share_copy)) { if (this.newPageUrl.includes('/goods/') && (options.share || options.share_copy)) {
...@@ -712,6 +712,31 @@ export default { ...@@ -712,6 +712,31 @@ export default {
} }
return ''; return '';
},
// 将多余的参数删除: ?abc=&cba=1 => ?cba=1
removeEmptyQueryParams(url) {
try {
// 分割URL,分离基础URL和查询字符串
const [baseUrl, queryPart] = url.split('?');
// 若没有查询字符串,直接返回基础URL
if (!queryPart) return baseUrl;
// 分割查询字符串为参数数组
const queryParams = queryPart.split('&');
// 过滤掉空值参数
const filteredParams = queryParams.filter(param => {
const [key, value] = param.split('=');
return value;
});
// 重新组合查询字符串并附加到基础URL上
const cleanedQuery = filteredParams.join('&');
return baseUrl + (cleanedQuery ? `?${cleanedQuery}` : '');
} catch (err) {
console.log('parseUrlError:', err);
return url;
}
} }
}, },
onUnload() { onUnload() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment