diff --git a/pages_tool/vr/index.vue b/pages_tool/vr/index.vue index 2dd6fe5..690b5d7 100644 --- a/pages_tool/vr/index.vue +++ b/pages_tool/vr/index.vue @@ -1,6 +1,6 @@ @@ -9,17 +9,24 @@ export default { data() { return { src: '', - title: '' + title: '', + customTitle: '', + titleTimer: null }; }, onLoad(option) { - this.title = option?.title ?? ''; + this.customTitle = option?.title || '工厂展示'; + this.title = this.customTitle; + uni.setNavigationBarTitle({ title: this.customTitle }); this.$api.sendRequest({ url: '/api/config/defaultvr', success: res => { if (res.code == 0) { + this.customTitle = res.data.title; + this.title = this.customTitle; + uni.setNavigationBarTitle({ title: this.customTitle }); this.src = res.data.url; - this.title = res.data.title; + this.startTitleGuard(); } }, fail: res => { @@ -27,19 +34,35 @@ export default { }); }, onShow() { - this.updateNavbarTitle(); - }, - watch: { - title(newVal) { - this.updateNavbarTitle(newVal); + if (this.customTitle) { + uni.setNavigationBarTitle({ title: this.customTitle }); } }, + onUnload() { + this.clearTitleGuard(); + }, methods: { - updateNavbarTitle(newTitle) { - const title = newTitle ?? this.title; - uni.setNavigationBarTitle({title}); + forceCustomTitle() { + uni.setNavigationBarTitle({ title: this.customTitle }); + }, + startTitleGuard() { + this.clearTitleGuard(); + let count = 0; + this.titleTimer = setInterval(() => { + uni.setNavigationBarTitle({ title: this.customTitle }); + count++; + if (count >= 10) { + this.clearTitleGuard(); + } + }, 100); + }, + clearTitleGuard() { + if (this.titleTimer) { + clearInterval(this.titleTimer); + this.titleTimer = null; + } } - } + } };