因为华为上架需要添加申请权限时的使用说明,否则就无法通过审核,就封装了申请权限时弹出权限说明窗口,利用了本地存储如果权限已经通过就不弹权限说明窗口直接调用回调,如果没有通过或没有就弹出申请权限弹窗。
1.页面组件
<template>
<view>
<view v-if="showTips" class="fixed bgFF radio30 absolute tips fs28 color02">
<view class="lh50">
{
{actionPermission.title}}使用说明:
</view>
<view class="lh50">
{
{actionPermission.tips}}
</view>
</view>
<u-popup :show="show" @close="close" mode="center" round="30rpx">
<view class="padding50 bgFF content text-center radio20 fs32 color">
<view class="wh100">
<view class="lh50 marginB40">
您已禁止{
{actionPermission.title}},如需要使用请设置!
</view>
<view @click="handelAllow" class="fw600 paddingT40 borderT1">
去设置
</view>
</view>
</view>
</u-popup>
</view>
</template>
<script>
import {
tipsConfig
} from './index.js'
import permision from './permission.js'
export default {
data() {
return {
show: false,
key: 'CAMERA',
// isSetting: false,
showTips: false
}
},
computed: {
actionPermission() {
return tipsConfig[this.key]
}
},
methods: {
async showView(key = 'CAMERA', callback) {
// #ifdef APP-PLUS
// 获取系统信息
const systemInfo = uni.getSystemInfoSync();
// 判断是否为ios
const isIos = systemInfo?.platform === 'ios';
if (isIos) {
return callback && callback()
}
this.key = key
// 如果返回1 则是允许权限 直接调用回调就行 如果是0则询问 -1则永久拒绝
const permission = uni.getStorageSync('permission') || {}
const keyStatus = permission[this.actionPermission?.key] || null
if (keyStatus == 1) {
return callback && callback()
}
// else if (keyStatus == -1) {
// this.show = true
// return
// }
const result = await this.requestAndroidPermission()
permission[this.actionPermission?.key] = result
uni.setStorageSync('permission', permission)
if (result == 1) {
callback && callback()
} else {
this.show = true
}
//#endif
// #ifndef APP-PLUS
callback && callback()
//#endif
},
close() {
this.show = false
this.showTips = false
},
/**
* 禁止
*/
handelProhibited(status) {