From 1b2a8f83c29557eeaf1afc0ec8c58abaaa250c1f Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Sat, 30 May 2026 17:12:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96webview=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=92=8Cutil.js=E4=B8=AD=E9=93=BE=E6=8E=A5=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将链接参数拼接逻辑移至util.js中处理,统一各端链接处理方式 --- common/js/util.js | 7 +++---- pages_tool/webview/webview.vue | 28 +--------------------------- 2 files changed, 4 insertions(+), 31 deletions(-) diff --git a/common/js/util.js b/common/js/util.js index 64779a4..ef00b89 100644 --- a/common/js/util.js +++ b/common/js/util.js @@ -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 diff --git a/pages_tool/webview/webview.vue b/pages_tool/webview/webview.vue index 41717d6..bd9f928 100644 --- a/pages_tool/webview/webview.vue +++ b/pages_tool/webview/webview.vue @@ -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 - }); - } } } };