refactor(formdata): 重构导航栏标题设置逻辑

将导航栏标题设置提取为独立方法updateNavbarTitle,统一处理标题逻辑,同时将data中的title变量重命名为formTitle避免命名歧义
This commit is contained in:
2026-05-29 10:28:17 +08:00
parent 9f40ebc09e
commit b5077b6a33

View File

@@ -42,7 +42,7 @@ export default {
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
// #ifdef H5
title: '', // 查询参数传入的Title
formTitle: '', // 查询参数传入的Title
enableSetTitle: false, // 查询参数传入的是否可以强制设置Title
// #endif
}
@@ -72,7 +72,7 @@ export default {
uni.setStorageSync('skipPrivacyCheck', true);
// #ifdef H5
this.title = options?.title ?? '';
this.formTitle = options?.title ?? '';
this.enableSetTitle = Boolean(options?.enable_set_title);
// #endif
@@ -107,6 +107,9 @@ export default {
newVal && this.getData()
}
},
onShow() {
this.updateNavbarTitle();
},
methods: {
getData() {
this.$api.sendRequest({
@@ -119,18 +122,7 @@ 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: formName
})
this.updateNavbarTitle();
}
this.$refs.loadingCover && this.$refs.loadingCover.hide()
},
@@ -139,6 +131,16 @@ export default {
}
})
},
updateNavbarTitle() {
if (!this.detail?.form_name) return;
let formName = this.detail.form_name;
// #ifdef H5
if (this.enableSetTitle && this.formTitle) {
formName = this.formTitle;
}
// #endif
uni.setNavigationBarTitle({ title: formName });
},
create() {
if (!this.$refs.form.verify()) return