123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- <template>
- <view v-if="showPopup" class="uni-popup" @touchmove.stop.prevent="">
- <view :class="[type, ani, animation ? 'ani' : '']" class="uni-custom uni-popup__wrapper" @click="close(true)">
- <view class="uni-popup__wrapper-box">
- <view :style="[{paddingTop: StatusBar+'px'}]">
- <view class="title">{{authList[permissionID].title}}</view>
- <view class="content">{{authList[permissionID].content}}</view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'YkAuthpup',
- props: {
- // 开启动画
- animation: {
- type: Boolean,
- default: true
- },
- //弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层,
- type: {
- type: String,
- default: 'center'
- },
- show: {
- type: Boolean,
- default: true
- },
- permissionID: {
- type: [String, Number],
- default: ''
- }
- },
- data() {
- return {
- ani: '',
- showPopup: false,
- StatusBar: '',
- authList: {
- 'WRITE_EXTERNAL_STORAGE': {
- title: "七牛联盟对存储空间/照片权限申请说明",
- content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、分享、客服沟通等场景中读取和写入相册和文件内容。"
- },
- 'ACCESS_FINE_LOCATION': {
- title: "七牛联盟对地理位置权限申请说明",
- content: "便于应用程序可以提供基于位置的服务、定位导航、附近搜索等功能。"
- },
- 'CALL_PHONE': {
- title: "七牛联盟对拨打/管理电话权限申请说明",
- content: "便于您使用该功能联系客服、业务经理与联系等场景下使用"
- },
- 'CAMERA': {
- title: "七牛联盟对拍摄照片/录制视频权限申请说明",
- content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、分享、客服沟通等场景下使用。"
- },
- 'RECORD_AUDIO': {
- title: "七牛联盟申请获取麦克风权限",
- content: "在下方弹窗中选择允许后,你可以在七牛联盟中发送语音消息的场景使用麦克风进行录音。"
- }
- }
- }
- },
- created() {
- this.getSystemInfo();
- },
- methods: {
- //获取状态栏高度
- getSystemInfo() {
- uni.getSystemInfo({
- success: function(e) {
- this.StatusBar = e.statusBarHeight;
- }
- })
- },
- open() {
- this.requestPermissions(this.permissionID);
- },
- close(type) {
- this.ani = ''
- this.$nextTick(() => {
- setTimeout(() => {
- this.showPopup = false
- }, 300)
- })
- },
- //权限检测
- requestPermissions(permissionID) {
- let _this = this;
- let _permissionID;
- _permissionID = 'android.permission.' + permissionID;
- // #ifdef APP-PLUS
- //判断安卓与ios设备
- if (plus.os.name == 'Android') {
- plus.android.checkPermission(_permissionID,
- granted => {
- if (granted.checkResult == -1) {
- //还未授权当前查询的权限,打开权限申请目的自定义弹框
- _this.showPopup = true;
- _this.$nextTick(() => {
- setTimeout(() => {
- _this.ani = 'uni-' + _this.type
- }, 30)
- })
- }
- },
- error => {
- console.log(error.message);
- }
- );
- plus.android.requestPermissions([_permissionID],
- (e) => {
- //关闭权限申请目的自定义弹框
- _this.ani = '';
- _this.$nextTick(() => {
- setTimeout(() => {
- _this.showPopup = false
- }, 300)
- })
- if (e.granted.length > 0) {
- //当前查询权限已授权,此时可以通知页面执行接下来的操作
- _this.$emit('changeAuth');
- } else if (e.deniedAlways.length > 0) {
- // console.log(e)
- let content = ''
- if(permissionID == 'WRITE_EXTERNAL_STORAGE') {
- content = '未允许七牛联盟获取存储空间权限,无法访问相册中的图片或视频。'
- }
- uni.showModal({
- title: '提示',
- content: content,
- confirmText:'去授权',
- success(res) {
- if (res.confirm) {
- uni.openAppAuthorizeSetting({
- success: (res) => {
- console.log('success')
- }
- })
- }
- }
- });
-
- }
- })
- } else {
- //IOS不需要,在配置文件的隐私信息访问的许可描述里可添加
- }
- // #endif
- }
- }
- }
- </script>
- <style lang="scss">
- .uni-popup {
- position: fixed;
- /* #ifdef H5 */
- top: 0px;
- // top: 50px;
- /* #endif */
- /* #ifndef H5 */
- top: 0px;
- /* #endif */
- bottom: 0;
- left: 0;
- right: 0;
- z-index: 99999;
- overflow: hidden;
- background-color: #fff;
- &__wrapper {
- position: absolute;
- z-index: 999;
- box-sizing: border-box;
- &.ani {
- transition: all 0.3s;
- }
- &.top {
- top: 0;
- left: 0;
- width: 100%;
- transform: translateY(-100%);
- }
- &.bottom {
- bottom: 0;
- left: 0;
- width: 100%;
- transform: translateY(100%);
- }
- &.right {
- bottom: 0;
- left: 0;
- width: 70%;
- transform: translateY(100%);
- }
- &.center {
- width: 100%;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- transform: scale(1.2);
- opacity: 0;
- }
- &-box {
- position: relative;
- box-sizing: border-box;
- }
- &.uni-custom {
- & .uni-popup__wrapper-box {
- // border-radius: 20upx 20upx 0 0;
- padding: 30upx;
- background: #fff;
- .title {
- font-size: 32rpx;
- font-weight: bold;
- }
- .content {
- margin-top: 16rpx;
- line-height: 1.6;
- }
- }
- &.center {
- & .uni-popup__wrapper-box {
- position: relative;
- max-width: 80%;
- max-height: 80%;
- overflow-y: scroll;
- }
- }
- &.top,
- &.bottom {
- & .uni-popup__wrapper-box {
- width: 100%;
- max-height: 1000upx;
- // overflow-y: scroll;
- }
- }
- }
- &.uni-top,
- &.uni-bottom {
- transform: translateY(0);
- }
- &.uni-center {
- transform: scale(1);
- opacity: 1;
- }
- }
- }
- </style>
|