refactor: 优化webview页面和util.js中链接处理逻辑

将链接参数拼接逻辑移至util.js中处理,统一各端链接处理方式
This commit is contained in:
2026-05-30 17:12:36 +08:00
parent 81570dda30
commit 1b2a8f83c2
2 changed files with 4 additions and 31 deletions

View File

@@ -693,18 +693,17 @@ export default {
title: link?.title ?? '',
enable_set_title: link?.enable_set_title ? 1 : 0
}
let url = this.normalizeUrl(decodeEntity(link.wap_url));
url = this.appendQueryParams(url, params);
// #ifdef H5
let url = this.normalizeUrl(decodeEntity(link.wap_url));
url = this.appendQueryParams(url, params);
// console.log(`url ---->`, url, link)
window.location.href = url;
// #endif
// #ifdef MP
this.redirectTo('/pages_tool/webview/webview', {
src: encodeURIComponent(link.wap_url),
...params
src: encodeURIComponent(url)
});
// #endif

View File

@@ -14,15 +14,10 @@ import { decodeEntity } from '@/common/js/util.js';
export default {
data() {
return {
src: '',
title: '', // 标题栏标题
enableSetTitle: false, // 是否强制设置标题,用来替换Webview中的默认标题
src: ''
};
},
onLoad(option) {
this.title = option?.title ?? '';
this.enableSetTitle = option?.enable_set_title == 1;
// #ifdef H5
this.src = decodeEntity(decodeURIComponent(option.src));
// #endif
@@ -31,32 +26,11 @@ export default {
this.src = decodeEntity(decodeURIComponent(`${option.src}&from=mp-webview`));
// #endif
},
onReady() {
this.updateNavbarTitle();
},
onShow() {
this.updateNavbarTitle();
},
watch: {
title(newVal) {
this.updateNavbarTitle(newVal);
},
enableSetTitle() {
this.updateNavbarTitle();
}
},
methods: {
navigateBack() {
uni.navigateBack({
delta: 1
});
},
updateNavbarTitle(newTitle) {
if (this.enableSetTitle) {
uni.setNavigationBarTitle({
title: newTitle ?? this.title
});
}
}
}
};