This commit is contained in:
2026-07-25 17:53:39 +08:00
parent a70a29eda1
commit 7c51841dba

View File

@@ -1,6 +1,6 @@
<template>
<view :style="themeColor" class="vr-page">
<web-view :src="src" class="vr-webview"></web-view>
<web-view :src="src" class="vr-webview" @titleUpdate="forceCustomTitle"></web-view>
</view>
</template>
@@ -10,52 +10,60 @@ export default {
return {
src: '',
title: '',
customTitle: '',
titleTimer: null
};
},
onLoad(option) {
this.title = option?.title || '工厂展示';
uni.setNavigationBarTitle({ title: this.title });
this.$api.sendRequest({
url: '/api/config/defaultvr',
success: res => {
if (res.code == 0) {
this.title = res.data.title;
uni.setNavigationBarTitle({ title: this.title });
this.src = res.data.url;
this.startTitleGuard();
}
},
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.startTitleGuard();
}
},
fail: res => {
}
});
},
onShow() {
if (this.title) {
uni.setNavigationBarTitle({ title: this.title });
}
},
if (this.customTitle) {
uni.setNavigationBarTitle({ title: this.customTitle });
}
},
onUnload() {
this.clearTitleGuard();
},
methods: {
startTitleGuard() {
this.clearTitleGuard();
let count = 0;
this.titleTimer = setInterval(() => {
uni.setNavigationBarTitle({ title: this.title });
count++;
if (count >= 10) {
this.clearTitleGuard();
}
}, 100);
},
clearTitleGuard() {
if (this.titleTimer) {
clearInterval(this.titleTimer);
this.titleTimer = null;
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;
}
}
};
}
};
</script>
<style lang="scss">