This commit is contained in:
2026-07-30 10:35:04 +08:00

View File

@@ -1,6 +1,6 @@
<template> <template>
<view :style="themeColor" class="vr-page"> <view :style="themeColor" class="vr-page">
<web-view :src="src" class="vr-webview" @titleUpdate="updateNavbarTitle"></web-view> <web-view :src="src" class="vr-webview" @titleUpdate="forceCustomTitle"></web-view>
</view> </view>
</template> </template>
@@ -9,17 +9,24 @@ export default {
data() { data() {
return { return {
src: '', src: '',
title: '' title: '',
customTitle: '',
titleTimer: null
}; };
}, },
onLoad(option) { onLoad(option) {
this.title = option?.title ?? ''; this.customTitle = option?.title || '工厂展示';
this.title = this.customTitle;
uni.setNavigationBarTitle({ title: this.customTitle });
this.$api.sendRequest({ this.$api.sendRequest({
url: '/api/config/defaultvr', url: '/api/config/defaultvr',
success: res => { success: res => {
if (res.code == 0) { if (res.code == 0) {
this.customTitle = res.data.title;
this.title = this.customTitle;
uni.setNavigationBarTitle({ title: this.customTitle });
this.src = res.data.url; this.src = res.data.url;
this.title = res.data.title; this.startTitleGuard();
} }
}, },
fail: res => { fail: res => {
@@ -27,19 +34,35 @@ export default {
}); });
}, },
onShow() { onShow() {
this.updateNavbarTitle(); if (this.customTitle) {
}, uni.setNavigationBarTitle({ title: this.customTitle });
watch: {
title(newVal) {
this.updateNavbarTitle(newVal);
} }
}, },
onUnload() {
this.clearTitleGuard();
},
methods: { methods: {
updateNavbarTitle(newTitle) { forceCustomTitle() {
const title = newTitle ?? this.title; uni.setNavigationBarTitle({ title: this.customTitle });
uni.setNavigationBarTitle({title}); },
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;
}
} }
} }
}; };
</script> </script>