refactor(formdata): 重构导航栏标题设置逻辑
将导航栏标题设置提取为独立方法updateNavbarTitle,统一处理标题逻辑,同时将data中的title变量重命名为formTitle避免命名歧义
This commit is contained in:
@@ -42,7 +42,7 @@ export default {
|
|||||||
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
|
isFromMpWebView: false, // 是否是从微信小程序的WebView跳转过来的
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
title: '', // 查询参数传入的Title
|
formTitle: '', // 查询参数传入的Title
|
||||||
enableSetTitle: false, // 查询参数传入的是否可以强制设置Title
|
enableSetTitle: false, // 查询参数传入的是否可以强制设置Title
|
||||||
// #endif
|
// #endif
|
||||||
}
|
}
|
||||||
@@ -72,7 +72,7 @@ export default {
|
|||||||
uni.setStorageSync('skipPrivacyCheck', true);
|
uni.setStorageSync('skipPrivacyCheck', true);
|
||||||
|
|
||||||
// #ifdef H5
|
// #ifdef H5
|
||||||
this.title = options?.title ?? '';
|
this.formTitle = options?.title ?? '';
|
||||||
this.enableSetTitle = Boolean(options?.enable_set_title);
|
this.enableSetTitle = Boolean(options?.enable_set_title);
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
@@ -107,6 +107,9 @@ export default {
|
|||||||
newVal && this.getData()
|
newVal && this.getData()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
onShow() {
|
||||||
|
this.updateNavbarTitle();
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getData() {
|
getData() {
|
||||||
this.$api.sendRequest({
|
this.$api.sendRequest({
|
||||||
@@ -119,18 +122,7 @@ export default {
|
|||||||
if (res.code == 0 && res.data) {
|
if (res.code == 0 && res.data) {
|
||||||
this.detail = res.data
|
this.detail = res.data
|
||||||
console.log(`form data =>`, this.detail)
|
console.log(`form data =>`, this.detail)
|
||||||
|
this.updateNavbarTitle();
|
||||||
let formName = res.data?.form_name ?? '';
|
|
||||||
|
|
||||||
// #ifdef H5
|
|
||||||
if (this.enableSetTitle) {
|
|
||||||
formName = this.title;
|
|
||||||
}
|
|
||||||
// #endif
|
|
||||||
|
|
||||||
uni.setNavigationBarTitle({
|
|
||||||
title: formName
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
this.$refs.loadingCover && this.$refs.loadingCover.hide()
|
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() {
|
create() {
|
||||||
if (!this.$refs.form.verify()) return
|
if (!this.$refs.form.verify()) return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user