template-project/pagesB/permission/permission.vue

183 lines
7.0 KiB
Vue
Raw Normal View History

<template>
<view class="rootview">
<button @click="gotoAppPermissionSetting">App</button>
<uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" style-type="button" active-color="#4cd964"></uni-segmented-control>
<view>
<view v-show="current === 0">
<view class="uni-divider">
<view class="uni-divider__content">iOS应用权限检查</view>
<view class="uni-divider__line"></view>
</view>
<button :disabled="!isIos" @click="judgeIosPermission('location')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('camera')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('photoLibrary')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('record')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('push')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('contact')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('calendar')"></button>
<button :disabled="!isIos" @click="judgeIosPermission('memo')"></button>
<view class="uni-divider">
<view class="uni-divider__content">iOS的设备状态监测</view>
<view class="uni-divider__line"></view>
</view>
<view class="commontitle">与手机相关与应用无关</view>
<button :disabled="!isIos" @click="checkSystemLocationStatus"></button>
</view>
<view v-show="current === 1">
<view class="uni-divider">
<view class="uni-divider__content">Android应用权限检查</view>
<view class="uni-divider__line"></view>
</view>
<view class="commontitle">除非同意或永久拒绝否则会弹框</view>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.ACCESS_COARSE_LOCATION')">(\ble)</button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.CAMERA')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_EXTERNAL_STORAGE')">()</button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.WRITE_EXTERNAL_STORAGE')">()</button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.RECORD_AUDIO')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_CONTACTS')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.WRITE_CONTACTS')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_CALENDAR')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.WRITE_CALENDAR')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_SMS')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.SEND_SMS')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.RECEIVE_SMS')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_PHONE_STATE')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.CALL_PHONE')"></button>
<button :disabled="isIos" @click="requestAndroidPermission('android.permission.READ_CALL_LOG')"></button>
<view class="uni-divider">
<view class="uni-divider__content">Android的设备状态监测</view>
<view class="uni-divider__line"></view>
</view>
<view class="commontitle">与手机相关与应用无关</view>
<button :disabled="isIos" @click="checkSystemLocationStatus"></button>
<button :disabled="isIos" @click="gotoAndroidPermissionSetting">Android</button>
</view>
</view>
</view>
</template>
<script>
import permision from "@/js_sdk/wa-permission/permission.js"
import uniSegmentedControl from "@/components/uni-segmented-control/uni-segmented-control.vue"
export default {
components: {
uniSegmentedControl
},
data() {
return {
isIos: true,
items: ['iOS', 'Android'],
current: 0
}
},
onLoad() {
// #ifdef APP-PLUS
this.isIos = (plus.os.name == "iOS")
// #endif
},
methods: {
onClickItem(index) {
if (this.current !== index) {
this.current = index;
}
},
judgeIosPermission: function(permisionID) {
var result = permision.judgeIosPermission(permisionID)
console.log(result);
var strStatus = (result) ? "已" : "未"
uni.showModal({
content: permisionID + '权限' + strStatus + "获得授权",
showCancel: false
});
},
async requestAndroidPermission(permisionID) {
var result = await permision.requestAndroidPermission(permisionID)
var strStatus
if (result == 1) {
strStatus = "已获得授权"
} else if (result == 0) {
strStatus = "未获得授权"
} else {
strStatus = "被永久拒绝权限"
}
uni.showModal({
content: permisionID + strStatus,
showCancel: false
});
},
gotoAppPermissionSetting: function() {
permision.gotoAppPermissionSetting()
},
checkSystemLocationStatus: function() {
uni.showModal({
content: '本机的位置服务开启状态:' + permision.checkSystemEnableLocation(),
showCancel: false
});
},
gotoAndroidPermissionSetting: function() {
var main = plus.android.runtimeMainActivity(); //获取activity
var Intent = plus.android.importClass('android.content.Intent');
var Settings = plus.android.importClass('android.provider.Settings');
var intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); //可设置http://ask.dcloud.net.cn/question/14732这里所有Action字段
main.startActivity(intent);
}
}
}
</script>
<style>
page {
background-color: #F4F5F6;
line-height: 1.5;
}
button {
margin: 15px;
color: #007AFF;
}
.rootview {
padding: 0 15px 20px;
}
/* 分界线 */
.uni-divider {
height: 50px;
display: flex;
align-items: center;
justify-content: center;
position: relative;
}
.uni-divider__content {
font-size: 16px;
color: #999999;
padding: 0 10px;
position: relative;
z-index: 101;
background: #F4F5F6;
}
.uni-divider__line {
background-color: #CCCCCC;
height: 1px;
width: 99%;
position: absolute;
z-index: 100;
top: 50%;
left: 0;
transform: translateY(50%);
}
.commontitle {
font-size: 14px;
color: #999999;
text-align: center;
}
</style>