1. 将enable_set_title的布尔判断改为数字1/0的格式,统一前后端参数传递规则 2. 重构导航栏标题更新逻辑,抽离为公共方法并监听title和enableSetTitle变化 3. 新增onShow钩子触发标题更新,修复页面重新显示时标题不刷新的问题 4. 补充控制台日志用于调试跳转链接参数
74 lines
1.4 KiB
Vue
74 lines
1.4 KiB
Vue
<template>
|
||
<view :style="themeColor">
|
||
<view class="iconfont iconshang navigate-back" @click="navigateBack"></view>
|
||
<web-view :src="src"></web-view>
|
||
|
||
<!-- 隐私弹窗 -->
|
||
<privacy-popup ref="privacyPopup"></privacy-popup>
|
||
</view>
|
||
</template>
|
||
|
||
<script>
|
||
import { decodeEntity } from '@/common/js/util.js';
|
||
|
||
export default {
|
||
data() {
|
||
return {
|
||
src: '',
|
||
title: '', // 标题栏标题
|
||
enableSetTitle: false, // 是否强制设置标题,用来替换Webview中的默认标题
|
||
};
|
||
},
|
||
onLoad(option) {
|
||
this.title = option?.title ?? '';
|
||
this.enableSetTitle = option?.enable_set_title == 1;
|
||
|
||
// #ifdef H5
|
||
this.src = decodeEntity(decodeURIComponent(option.src));
|
||
// #endif
|
||
|
||
// #ifndef H5
|
||
this.src = decodeEntity(decodeURIComponent(`${option.src}&from=mp-webview`));
|
||
// #endif
|
||
},
|
||
onReady() {
|
||
this.updateNavbarTitle();
|
||
},
|
||
onShow() {
|
||
this.updateNavbarTitle();
|
||
},
|
||
watch: {
|
||
title(newVal) {
|
||
this.updateNavbarTitle(newVal);
|
||
},
|
||
enableSetTitle() {
|
||
this.updateNavbarTitle();
|
||
}
|
||
},
|
||
methods: {
|
||
navigateBack() {
|
||
uni.navigateBack({
|
||
delta: 1
|
||
});
|
||
},
|
||
updateNavbarTitle(newTitle) {
|
||
if (this.enableSetTitle) {
|
||
uni.setNavigationBarTitle({
|
||
title: newTitle ?? this.title
|
||
});
|
||
}
|
||
}
|
||
}
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.navigate-back {
|
||
position: absolute;
|
||
top: 34rpx;
|
||
left: 34rpx;
|
||
z-index: 5;
|
||
font-size: $font-size-toolbar;
|
||
}
|
||
</style>
|