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

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