1、进入页面默认是竖屏当手机横着的时候页面也跟着横着
<template>
<view class="monitor">
<u-no-network></u-no-network>
<web-view :src="url" v-if="url" :webview-styles="webviewStyles"></web-view>
</view>
</template>
<script>
let watchScheen;
import {
getProjectHref
}
from '@/api/api.js'
export default {
data() {
return {
url:'',
webviewStyles:{
progress:{
background:'#FF3333',
},
},
}
},
watch: {
projectInfo(newVal,oldVal) {
this.init();
}
},
computed:{
projectInfo(){
return this.$store.state.projectInfo || {}
},
},
onShow() {
plus.screen.unlockOrientation('portrait-primary');
watchScheen = setInterval(()=>{
let c = plus.navigator.getOrientation();
if(c == 0){
console.log('竖屏',c)
plus.screen.lockOrientation('portrait-primary');
plus.navigator.setStatusBarStyle('dark');
plus.screen.unlockOrientation();
uni.showTabBar()
} else if(c == 180){
console.log('反向竖屏',c)
plus.screen.lockOrientation('portrait-secondary');
plus.navigator.setStatusBarStyle('dark');
plus.screen.unlockOrientation();
uni.hideTabBar()
} else if(c == -90){
console.log('反向横屏',c)
plus.screen.lockOrientation('landscape-secondary');
plus.navigator.setStatusBarStyle('dark');
plus.screen.unlockOrientation();
uni.hideTabBar()
} else {
console.log('横屏',c)
plus.screen.lockOrientation('landscape-primary');
plus.navigator.setStatusBarStyle('dark');
plus.screen.unlockOrientation();
uni.hideTabBar()
}
},200)
uni.setNavigationBarTitle({
title:"监控"
})
this.init()
},
onHide() {
clearInterval(watchScheen)
plus.screen.lockOrientation('portrait-primary');
},
methods:{
init(){
uni.showLoading({
title:"加载中..."
})
getProjectHref({
projectId:this.projectInfo.id,
hyperLinkAddressType :2
}).then(res=>{
if(res){
this.url = this.$u.trim(res.hyperLinkAddress)
console.log(this.url);
let timer = setInterval(()=>{
uni.setNavigationBarTitle({
title:"监控"
})
},300)
setTimeout(()=>{
uni.hideLoading()
clearInterval(timer)
timer = null
var currentWebview = this.$mp.page.$getAppWebview()
var wv = currentWebview.children()[0]
wv.setStyle({
scalable:true,
})
},1000*3)
uni.hideLoading()
}else{
this.url = ''
uni.hideLoading()
this.utils.toast("此项目暂未配置超链接")
}
})
}
}
}
</script>
<style lang="scss" scoped>
iframe {
background-color: #111934;
}
</style>
2、调用重力感应相关api还要在pages.json中添加如下配置
"globalStyle": {
"backgroundColor": "#F8F8F8",
"navigationBarBackgroundColor": "#F8F8F8",
"navigationBarTextStyle": "white",
"pageOrientation": "auto"
},
"app-plus": {
"screenOrientation": [
"portrait-primary",
"portrait-secondary",
"landscape-primary",
"landscape-secondary"
],
"background":"#111934"
},

3、App端配置找到manifest.json文件找到源码视图添加如下配置
"screenOrientation" : [
"portrait-primary",
"portrait-secondary",
"landscape-primary",
"landscape-secondary"
],

效果截图如下:

