88 lines
1.9 KiB
Vue
88 lines
1.9 KiB
Vue
<template>
|
|
<view class="content">
|
|
<web-view :update-title="false" :webview-styles="webviewStyles" :src="url"></web-view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
data() {
|
|
return {
|
|
webviewStyles: {
|
|
progress: {
|
|
color: '#FF3333'
|
|
}
|
|
},
|
|
landscapeOb:null,
|
|
landscape: false,
|
|
url:'',
|
|
backStatus:true
|
|
}
|
|
},
|
|
onBackPress(e){
|
|
console.log("点击返回",e)
|
|
if (e.from === 'navigateBack') {
|
|
return false;
|
|
}
|
|
uni.$emit('closePath', {
|
|
url:encodeURIComponent(this.url),
|
|
});
|
|
let pages = getCurrentPages()
|
|
let page = pages[pages.length - 1];
|
|
console.log("page",pages.length - 1)
|
|
let currentPages = page.$getAppWebview()
|
|
let children=currentPages.children()
|
|
|
|
if(children.length===0){
|
|
uni.navigateBack()
|
|
}else{
|
|
children[0].close()
|
|
setTimeout(()=>{
|
|
uni.navigateBack()
|
|
},80)
|
|
}
|
|
|
|
return true;
|
|
},
|
|
onLoad(option) {
|
|
this.url = decodeURIComponent(option.url);
|
|
if(option.name){
|
|
uni.setNavigationBarTitle({
|
|
title: option.name
|
|
});
|
|
}
|
|
},
|
|
// 和 UI 相关的 api 在组件 mountd 后执行
|
|
mounted() {
|
|
// this.landscapeOb = uni.createMediaQueryObserver(this);
|
|
// this.landscapeObserver()
|
|
},
|
|
onNavigationBarButtonTap:function(e){
|
|
// #ifdef APP-PLUS
|
|
// const currentWebview = this.$mp.page.$getAppWebview(); //注意相关操作写在APP-PLUS条件编译下
|
|
// var wv = currentWebview.children()[0]
|
|
// wv.reload();
|
|
// #endif
|
|
},
|
|
methods: {
|
|
landscapeObserver() {
|
|
this.landscapeOb.observe({
|
|
orientation: 'landscape' //屏幕方向为纵向
|
|
}, matches => {
|
|
console.log("横竖屏变化",matches?'横屏':'竖屏');
|
|
this.landscape = matches
|
|
})
|
|
},
|
|
refresh(){
|
|
|
|
}
|
|
},
|
|
destroyed () {
|
|
// this.landscapeOb.disconnect() //组件销毁时停止监听
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
</style>
|