feat: add dynamic navigation bar title support for webview and form pages

1. add title and enableSetTitle data fields for webview and form pages
2. implement auto set navigation bar title when enabled
3. add URL normalize and query params append utilities
4. pass title and enable_set_title params across pages and external links
This commit is contained in:
2026-05-29 09:56:05 +08:00
parent dfbcd0c9a5
commit 9f40ebc09e
3 changed files with 212 additions and 4 deletions

View File

@@ -40,6 +40,11 @@ export default {
scroll: true,
uniacid: 0,
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
// #ifdef H5
title: '', // 查询参数传入的Title
enableSetTitle: false, // 查询参数传入的是否可以强制设置Title
// #endif
}
},
computed: {
@@ -66,6 +71,11 @@ export default {
uni.setStorageSync('skipPrivacyCheck', true);
// #ifdef H5
this.title = options?.title ?? '';
this.enableSetTitle = Boolean(options?.enable_set_title);
// #endif
this.uniacid = options.uniacid
this.id = options.id || 0
this.isFromMpWebView = options.from === 'mp-webview';
@@ -109,8 +119,17 @@ export default {
if (res.code == 0 && res.data) {
this.detail = res.data
console.log(`form data =>`, this.detail)
let formName = res.data?.form_name ?? '';
// #ifdef H5
if (this.enableSetTitle) {
formName = this.title;
}
// #endif
uni.setNavigationBarTitle({
title: res.data.form_name
title: formName
})
}
this.$refs.loadingCover && this.$refs.loadingCover.hide()

View File

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