uniapp H5+锁定和解除锁定屏幕方向及关闭应用启动界面及页面刷新

锁定屏幕方向

plus.screen.lockOrientation( String orientation );

说明:

锁定屏幕方向后屏幕只能按锁定的屏幕方向显示,关闭当前页面后仍然有效。 可再次调用此方法修改屏幕锁定方向或调用unlockOrientation()方法恢复到应用的默认值。

plus.screen.lockOrientation('landscape-primary');

锁定屏幕方向可取以下值: "portrait-primary": 竖屏正方向; "portrait-secondary": 竖屏反方向,屏幕正方向按顺时针旋转180°; "landscape-primary": 横屏正方向,屏幕正方向按顺时针旋转90°; "landscape-secondary": 横屏方向,屏幕正方向按顺时针旋转270°; "portrait": 竖屏正方向或反方向,根据设备重力感应器自动调整; "landscape": 横屏正方向或反方向,根据设备重力感应器自动调整;

uniapp配置如下

标题第一在onLaunch中写下如下代码

plus.screen.lockOrientation("portrait-primary");  

第二在manifest.json中配置

"app-plus" : {
        "distribute" : {
            "distribute" : {
                "orientation" : [ "portrait-primary"]//重力感应、横竖屏配置
            }
        },
    },

解除锁定屏幕方向


plus.screen.unlockOrientation();
     
说明:

解除锁定屏幕方向后将恢复应用默认的屏幕显示方向(通常为应用打包发布时设置的方向)

plus.screen.unlockOrientation();

关闭应用启动界面

// 	是否等待首页渲染完毕后再关闭启动界面
"alwaysShowBeforeRender" : false,
"waiting" : true,
//是否自动关闭启动界面,仅当alwaysShowBeforeRender设置为false时生效,如果需要手动关闭 (opens new window)启动界面,需将 alwaysShowBeforeRender 及 autoclose 均设置为 false。
"autoclose" : false,

以上配置 是不会自动关闭启动界面,需开发者根据业务逻辑在合适的时机调用 plus.navigator.closeSplashscreen() 关闭启动界面

// 手动关闭启动页(page.json中的第一个)
plus.navigator.closeSplashscreen();
login() //登录后再跳转
uni.switchTab({
	url: "/pages/home/home"
})


// 或者是以下需求

onLaunch: ()=> {
	// #ifdef APP-PLUS  
	let userinfo = uni.getStorageSync('userinfo');
	//判断是否存在登录信息
	if(!userinfo.role){
		//不存在则跳转登录页
		uni.reLaunch({
			url:"/pages/login/login",
			success:()=>{
				//跳转完页面后再关闭启动页
				plus.navigator.closeSplashscreen();
			}
		})
	}else{
		//存在则关闭启动页进入首页
	     plus.navigator.closeSplashscreen();
	}
	// #endif
},

uniapp页面刷新(含tabBar,页面,navigateTo的页面)

let currentRoutes = getCurrentPages(); // 获取当前打开过的页面路由数组
										let currentRoute = currentRoutes[currentRoutes.length - 1].route //获取当前页面路由
										console.log('currentRoute2',currentRoute);
										let pageList = ['pages/home/home','pages/related/index/index']
										if(pageList.includes(currentRoute)) {
											uni.reLaunch({
												url: '/' + currentRoute
											})
										}else {
											uni.redirectTo({ // 不使用navigateTo会堆栈,导致重复页面
												url: '/' + currentRoute
											})
										}

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值