uniapp APP权限弹框

效果图

第一步 新建一个页面,设置透明

c 复制代码
{
	"path": "pages/permissionDisc/permissionDisc",
	"style": {
		"navigationBarTitleText": "",
		"navigationStyle": "custom",
		"app-plus": {
			"animationType": "fade-in", // 设置fade-in淡入动画,为最合理的动画类型
			"background": "transparent", // 背景透明
			"backgroundColor": "transparent", // 背景透明
			"webviewBGTransparent": true,
			"mask": "none",
			"popGesture": "none", // 关闭IOS屏幕左边滑动关闭当前页面的功能
			"bounce": "none" // 将回弹属性关掉
		}
	}
}

第二步 APP.vue内监听权限调用

需要使用uview的API监听,跳转到新建的页面

uview地址:https://uviewui.com/js/fastUse.html

c 复制代码
// #ifdef APP-PLUS
// 监听系统权限申请
if (uni.$u.sys().osName == 'android') {
	console.log('权限监听');
	this.permissionListener = uni.createRequestPermissionListener();
	this.permissionListener.onConfirm((e) => {
		console.log('弹出系统权限授权框', e);
		uni.navigateTo({
			url: '/pages/permissionDisc/permissionDisc'+'?type=' + JSON.stringify(e),
			complete(e) {
				console.log(e);
			}
		});
	});
	this.permissionListener.onComplete((e) => {
		console.log('权限申请完成', e, uni.$u.page());
		// 拒绝时也会走需要处理一下,提示拒绝手动开启
		if (uni.$u.page() == '/pages/permissionDisc/permissionDisc') {
			uni.navigateBack();
		}
	});
}
// #endif

第三步 页面内写弹框内容

c 复制代码
<template>
	<view>
		<view class="mask" :style="{ width: windowWidth + 'px', height: windowHeight + 'px' }" style="padding-top: 60rpx;">
			<view class="block" v-for="(item, index) in showList" :key="index" :style="{ width: windowWidth * 0.8 + 'px' }">
				<view class="title">
					<text class="title" style="margin-bottom: 0">{{ item.name }}</text>
				</view>
				<view class="content">
					<text class="content">{{ item.content }}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	name: 'permission',
	data() {
		return {
			show: false,
			flag: true,
			title: '',
			content: '',
			osName: '',
			isIos: false,
			pIndex: 0,
			permissionList: {
				'android.permission.ACCESS_COARSE_LOCATION':{
					name: '访问粗略地理位置',
					content: '用于将服务根据距离排序,并显示与您的距离,不授权该权限会影响app的正常使用'
				},
				'android.permission.ACCESS_FINE_LOCATION': {
					name: '访问精确地理位置',
					content: '用于将服务根据距离排序,并显示与您的距离,不授权该权限会影响app的正常使用'
				},
				'android.permission.CAMERA': {
					name: '使用摄像头权限',
					content: '用于更换、上传您的头像、图片功能,不授权该权限会影响app的正常使用'
				},
				'android.permission.READ_EXTERNAL_STORAGE': {
					name: '读照片及文件权限',
					content: '用于更换、上传您的头像、图片功能,不授权该权限会影响app的正常使用'
				},
				'android.permission.WRITE_EXTERNAL_STORAGE': {
					name: '写照片及文件权限',
					content: '用于更换、上传您的头像、图片功能,不授权该权限会影响app的正常使用'
				},
				'android.permission.READ_MEDIA_IMAGES': {
					name: '读媒体图片权限',
					content: '用于更换、上传您的头像、图片功能,不授权该权限会影响app的正常使用'
				},
				'android.permission.READ_MEDIA_VIDEO': {
					name: '读媒体视频权限',
					content: '用于更换、上传您的头像、图片功能,不授权该权限会影响app的正常使用'
				},
				'android.permission.CALL_PHONE': {
					name: '使用拨打电话权限',
					content: '用于直接拨打您点击的电话号码,不授权该权限将无法拨打'
				},
				'android.permission.RECORD_AUDIO': {
					name: '使用麦克风权限',
					content: '用于录制声音,发送语音消息,语音通话,不授权该权限会影响app的正常使用'
				}
			},
			windowWidth: 0,
			windowHeight: 0,
			showList: []
		};
	},
	computed: {},
	onLoad(e) {
		try {
			let list = e.type ? JSON.parse(e.type) : [];
			list.forEach((item) => {
				this.showList.push(this.permissionList[item]);
			});
		} catch (e) {
			//TODO handle the exception
			console.log(e);
		}
		// #ifdef APP
		this.osName = plus.os.name;
		// #endif
		// this.osName = 'Android'
		this.isIos = this.osName == 'iOS';
		if (this.isIos == true) this.show = false;
		let windowinfo = uni.getWindowInfo();
		this.windowWidth = windowinfo.windowWidth;
		this.windowHeight = windowinfo.windowHeight;
	},
	methods: {}
};
</script>

<style>
page {
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.4);
}
.mask {
	width: 100vw;
	height: 100vh;
	background-color: rgba(0, 0, 0, 0);
	position: fixed;
	top: 0;
	left: 0;
	z-index: 99999;
	/* display: flex;
	justify-content: flex-start;
	align-items: center; */
}

.block {
	width: 80%;
	background-color: #fff;
	padding: 15rpx;
	margin-top: 30rpx;
	margin-left: 60rpx;
	border-radius: 15rpx;
}

.title {
	font-size: 32rpx;
	font-weight: bold;
	margin-bottom: 5rpx;
}

.content {
	font-size: 24rpx;
}
</style>
相关推荐
是小蟹呀^1 小时前
uni-app+SpringBoot: 前端传参,后端如何接收参数
spring boot·uni-app
月白星兮7 小时前
IOS兼容 - uniapp ios固定定位失效与刘海屏的坑
ios·uni-app·cocoa
努力做大神7 小时前
uniapp vue3项目定义全局变量,切换底部babar时根据条件刷新页面
uni-app·vue3
hunzi_19 小时前
来客推商城V3多用户uni-app商城源码怎么样?
uni-app
шесай-ай-ай-ай-ай, ч9 小时前
UNI-APP uts插件 支持ANDROID 监听手机状态
android·uni-app
搬砖-无恙1 天前
vue uniapp里照片多张照片展示
前端·vue.js·uni-app
菜又爱编程1 天前
【uni-app运行错误】SassError: expected selector @import “@/uni.scss“;
前端·uni-app·scss
奔跑吧邓邓子2 天前
【商城实战(36)】UniApp性能飞升秘籍:从渲染到编译的深度优化
性能优化·uni-app·商城实战