Commit ac820aa5 authored by 刘文虎's avatar 刘文虎

权限弹框

parent 9da1cb75
Pipeline #7945 canceled with stages
......@@ -10,6 +10,9 @@
</template>
<script>
import {
appName
} from "@/utils/config.js"
export default {
name: 'auth-popup',
props: {
......@@ -38,6 +41,7 @@
},
data() {
return {
systemInfo: null,
ani: '',
showPopup: false,
StatusBar: '',
......@@ -45,37 +49,42 @@
authList: {
'WRITE_EXTERNAL_STORAGE': {
scopeText: "存储空间/照片",
title: "扳手记账对存储空间/照片权限申请说明",
title: appName + "对存储空间/照片权限申请说明",
content: "便于您使用该功能上传您的照片/图片/视频/文件及用于更换头像、意见反馈、保存相册、上传资料/分享、下载、与客服沟通等场景中读取和写入相册和文件内容。"
},
'READ_EXTERNAL_STORAGE': {
scopeText: "读取设备上的照片及文件",
title: "扳手记账对读取设备上的照片及文件权限申请说明",
title: appName + "对读取设备上的照片及文件权限申请说明",
content: "便于您使用该功能上传您的照片/图片/视频/文件及用于更换头像、意见反馈、保存相册、上传资料/分享、下载、与客服沟通等场景中读取相册和文件内容。"
},
'READ_MEDIA_IMAGES': {
scopeText: "读取设备上的照片",
title: appName + "对读取设备上的照片权限申请说明",
content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、上传图片、与客服沟通等场景中读取相册内容。"
},
'ACCESS_FINE_LOCATION': {
scopeText: "地理位置",
title: "扳手记账对地理位置权限申请说明",
title: appName + "对地理位置权限申请说明",
content: "便于应用程序可以提供基于位置的服务、定位导航、附近搜索等功能。"
},
'CAMERA': {
scopeText: "相机/摄像头",
title: "扳手记账对相机/摄像头权限申请说明",
content: "便于您使用该功能拍照上传您的照片/视频及用于更换头像、意见反馈、保存相册、上传资料/动态、下载与客服沟通等场景中使用"
title: appName + "对相机/摄像头权限申请说明",
content: "便于您使用该功能拍照上传您的照片/视频及用于更换头像、意见反馈、保存相册、上传资料/动态、量角尺、下载与客服沟通等场景中使用"
},
'RECORD_AUDIO': {
scopeText: "麦克风",
title: "扳手记账对麦克风权限申请说明",
content: "便于您使用该功能进行录音、语音通话、发布语音、与客服语音沟通等场景中使用"
title: appName + "对麦克风权限申请说明",
content: "便于您使用该功能进行录音、录相、语音通话、发布语音、量角尺、与客服语音沟通等场景中使用"
},
'CALL_PHONE': {
scopeText: "拨打/管理电话",
title: "扳手记账对拨打/管理电话权限申请说明",
content: "便于您使用该功能联系客服、讲师等场景下使用"
title: appName + "对拨打/管理电话权限申请说明",
content: "便于您使用该功能联系讲师、客户、客服等场景下使用"
},
'WRITE_CONTACTS':{
'WRITE_CONTACTS': {
scopeText: "通讯录",
title: "扳手记账对通讯录权限申请说明",
title: appName + "对通讯录权限申请说明",
content: "便于您使用该功能保存到通讯录、使用通讯录等场景下使用"
}
}
......@@ -92,8 +101,9 @@
let _this = this;
uni.getSystemInfo({
success: function(e) {
_this.systemInfo = e
_this.StatusBar = 44 + e.statusBarHeight +
'px'; //用于自定义头部时,给手机状态栏留出位置,可通过isNativeHead这个参数控制
'px'; //用于自定义头部时,给手机状态栏留出位置,可通过isNativeHead这个参数控制
}
})
},
......@@ -112,9 +122,28 @@
requestPermissions(permissionID) {
let _this = this;
// #ifdef APP-PLUS
//判断安卓与ios设备
if (plus.os.name == 'Android') {
let {
osAndroidAPILevel
} = _this.systemInfo
// 安卓13之后 内部存储(应用内存储)不再需要权限 直接保存
if (osAndroidAPILevel >= 33) {
if (permissionID === 'WRITE_EXTERNAL_STORAGE') {
_this.$emit('changeAuth');
_this.$nextTick(() => {
setTimeout(() => {
_this.ani = 'uni-' + _this.type
}, 30)
})
return false;
}
}
// "<uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" android:maxSdkVersion=\"32\" />",
// "<uses-permission android:name=\"android.permission.MANAGE_EXTERNAL_STORAGE\" android:minSdkVersion=\"33\" />",
let _permissionID = 'android.permission.' + permissionID;
plus.android.checkPermission(_permissionID,
granted => {
if (granted.checkResult == -1) {
......@@ -145,7 +174,12 @@
//当前查询权限已授权,此时可以通知页面执行接下来的操作
_this.$emit('changeAuth');
}
if (e.deniedPresent.length > 0) {
//当前拒绝权限,此时可以通知页面执行接下来的操作
_this.$emit('reject');
}
if (e.deniedAlways.length > 0) {
uni.hideLoading()
//当前查询权限已被永久禁用,此时需要引导用户跳转手机系统设置去开启
uni.showModal({
title: '温馨提示',
......@@ -158,6 +192,9 @@
success: (res) => {
if (res.confirm) {
_this.goSetting();
} else {
//当前拒绝权限,此时可以通知页面执行接下来的操作
_this.$emit('reject');
}
}
})
......@@ -224,6 +261,7 @@
//当前查询权限已授权,此时可以通知页面执行接下来的操作
that.$emit('changeAuth')
} else {
uni.hideLoading()
//当前查询的权限已禁用,引导用户跳转手机系统设置去开启
uni.showModal({
title: '温馨提示',
......
<template>
<UploadImages ref="upload-images" :max-count="maxCount" :width="width" :height="height" custom-btn
:file-list="fileList" :auto-upload="autoUpload" :show-progress="false" :show-add="showAdd"
:isNativeHead="isNativeHead" :show-upload-list="showUploadList" :sourceType="sourceType"
@openSource="openSource" @on-list-change="handleListChange" @on-choose-fail="onChooseFail">
<view slot="addBtn">
<view v-if="$slots.addBtn" class="slot-view" hover-class="slot-btn__hover">
<slot name="addBtn" />
</view>
<view v-else class="slot-btn" hover-class="slot-btn__hover" :style="slotStyle" hover-stay-time="150">
<u-icon name="plus" :size="addSize" color="#D8D8D8"></u-icon>
</view>
<BottomChoose ref="bottom-choose" @change="sourceTypeChange" />
</view>
<PopInput title="提醒" type="text" sureText="前往设置" cancelText="返回" :showCancel="true" :content="uploadConent"
:visible.sync="showConfirm" @cancel="handleCancel" @click="handleConfirm" />
</UploadImages>
</template>
<script>
import PopInput from '@/components/pop-input-view';
import BottomChoose from '@/components/bottom-choose'
import UploadImages from '@/components/upload/u-upload';
import permision from '@/js_sdk/wa-permission/permission.js';
import {
mapGetters
} from 'vuex';
import {
showModal
} from '@/utils/auth.js';
export default {
components: {
UploadImages,
PopInput,
BottomChoose
},
props: {
// 给fileList赋初始值用
list: {
type: Array,
default () {
return [];
}
},
// 最大上传数量
maxCount: {
type: [String, Number],
default: 9
},
// 是否自动上传
autoUpload: {
type: Boolean,
default: false
},
// 内部预览图片区域和选择图片按钮的区域宽度
width: {
type: [String, Number],
default: 160
},
// 内部预览图片区域和选择图片按钮的区域高度
height: {
type: [String, Number],
default: 160
},
addSize: {
type: [String, Number],
default: 48
},
uploading: {
type: Boolean,
default: false
},
showAdd: {
type: Boolean,
default: true
},
isNativeHead: {
type: Boolean,
default: true
}
},
data() {
return {
fileList: [],
qiniuToken: '',
showUploadList: false,
uploadConent: '需要使用相机权限,请前往设置。',
showConfirm: false,
sourceType: ['album', 'camera']
};
},
computed: {
...mapGetters(['platform', 'isIOS']),
slotStyle() {
return ` width:${this.width}rpx;height:${this.height}rpx;`;
}
},
methods: {
openSource() {
this.$refs['bottom-choose'].open()
},
sourceTypeChange(source) {
this.sourceType = [source]
this.$nextTick(()=>{ this.$refs['upload-images'].appStratChoose(this.sourceType) })
},
handleListChange(lists, name) {
if (!lists || !lists.length) {
return false;
}
this.$emit('update:uploading', true);
this.$emit('on-list-change', lists);
this.$refs['upload-images'].clear();
},
selectFile() {
// 触发选择图片;不能改文件名,外部要调
this.$refs['upload-images'].selectFile();
},
onChooseFail(error) {
console.log("onChooseFail:", error);
this.$emit('on-choose-fail');
},
handleConfirm() {
permision.gotoAppPermissionSetting();
},
handleCancel() {}
}
};
</script>
<style lang="scss" scoped>
/deep/.u-add-tips {
height: 0 !important;
margin-top: 0 !important;
overflow: hidden;
}
.slot-btn {
width: 160rpx;
height: 160rpx;
display: flex;
justify-content: center;
align-items: center;
background: #f6f7fa;
border-radius: 10rpx;
// margin: 10rpx;
}
.slot-btn__hover {
background-color: rgb(235, 236, 238);
}
</style>
\ No newline at end of file
<template>
<UploadImages ref="upload-images" :max-count="maxCount" :width="width" :height="height" custom-btn
:file-list="fileList" :auto-upload="autoUpload" :isNativeHead="isNativeHead" :show-progress="false" :show-add="showAdd" :sourceType="sourceType" @openSource="openSource"
@on-list-change="handleListChange">
<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" :style="slotStyle" hover-stay-time="150">
<u-icon name="plus" :size="addSize" color="#D8D8D8"></u-icon>
<BottomChoose ref="bottom-choose" @change="sourceTypeChange" />
</view>
</UploadImages>
</template>
<script>
import BottomChoose from '@/components/bottom-choose'
import upload from '@/utils/upload'
import UploadImages from '@/components/upload/u-upload'
import {
getQiNiuToken
} from '@/api/common/index.js';
import {
UPLOAD_FILE_HOST
} from '@/utils/config.js';
export default {
components: {
UploadImages,
BottomChoose
},
props: {
// 给fileList赋初始值用
list: {
type: Array,
default () {
return []
},
},
// 最大上传数量
maxCount: {
type: [String, Number],
default: 9,
},
// 是否自动上传
autoUpload: {
type: Boolean,
default: false,
},
// 内部预览图片区域和选择图片按钮的区域宽度
width: {
type: [String, Number],
default: 160,
},
// 内部预览图片区域和选择图片按钮的区域高度
height: {
type: [String, Number],
default: 160,
},
addSize: {
type: [String, Number],
default: 48,
},
uploading: {
type: Boolean,
default: false
},
showAdd: {
type: Boolean,
default: true
},
isNativeHead:{
type: Boolean,
default: true
}
},
data() {
return {
fileList: [],
qiniuToken: '',
sourceType: ['album', 'camera']
}
},
computed: {
keyList() {
let list = []
if (this.fileList.length) {
for (var item of this.fileList) {
if (item.key) {
list.push(item.key)
}
}
}
return list
},
slotStyle() {
return ` width:${this.width}rpx;height:${this.height}rpx;`
}
},
watch: {
list(val) {
if (val && !this.fileList.length) {
this.fileList = []
for (var item of val) {
this.fileList.push({
key: item,
url: item,
})
}
}
},
},
created() {
this.getQiniuToken()
},
methods: {
openSource() {
this.$refs['bottom-choose'].open()
},
sourceTypeChange(source) {
this.sourceType = [source]
this.$refs['upload-images'].appStratChoose(this.sourceType)
},
filterList(listA, listB) {
listA = listA || []
listB = listB || []
let list = []
for (var item of listA) {
for (var obj of listB) {
if (obj.url == item.url) {
item.key = obj.key
}
}
list.push(item)
}
return list
},
handleListChange(lists, name) {
this.fileList = this.filterList(lists, this.fileList)
let newImages = this.fileList.filter((item) => {
return item.key == undefined
})
if (newImages && newImages.length > 0) {
this.$emit('update:uploading', true)
upload
.uploads(newImages, this.qiniuToken)
.then((res) => {
let list = []
if (res) {
for (var item of res) {
list.push({
url: item.url,
key: UPLOAD_FILE_HOST + item.key
})
}
}
this.fileList = this.filterList(this.fileList, list)
this.$emit('on-list-change', this.keyList)
console.log('upload:', this.fileList.length, this.keyList.length)
this.$emit('update:uploading', this.fileList.length != this.keyList.length)
})
.catch((msg) => {
console.log(msg)
})
} else {
this.$emit('on-list-change', this.keyList)
}
},
getQiniuToken() {
getQiNiuToken().then((res) => {
if (res.data) {
this.qiniuToken = res.data
}
})
},
selectFile() { // 触发选择图片;不能改文件名,外部要调
this.$refs['upload-images'].selectFile()
}
},
}
</script>
<style lang="scss" scoped>
/deep/.u-add-tips {
height: 0 !important;
margin-top: 0 !important;
overflow: hidden;
}
.slot-btn {
width: 160rpx;
height: 160rpx;
display: flex;
justify-content: center;
align-items: center;
background: #F6F7FA;
border-radius: 10rpx;
margin: 10rpx;
}
.slot-btn__hover {
background-color: rgb(235, 236, 238);
}
<template>
<UploadImages ref="upload-images" :max-count="maxCount" :width="width" :height="height" custom-btn
:file-list="fileList" :auto-upload="autoUpload" :isNativeHead="isNativeHead" :show-progress="false" :show-add="showAdd" :sourceType="sourceType" @openSource="openSource"
@on-list-change="handleListChange" @on-choose-fail="onChooseFail">
<view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" :style="slotStyle" hover-stay-time="150">
<u-icon name="plus" :size="addSize" color="#D8D8D8"></u-icon>
<BottomChoose ref="bottom-choose" @change="sourceTypeChange" />
</view>
</UploadImages>
</template>
<script>
import BottomChoose from '@/components/bottom-choose'
import upload from '@/utils/upload'
import UploadImages from '@/components/upload/u-upload'
import {
getQiNiuToken
} from '@/api/common/index.js';
import {
UPLOAD_FILE_HOST
} from '@/utils/config.js';
export default {
components: {
UploadImages,
BottomChoose
},
props: {
// 给fileList赋初始值用
list: {
type: Array,
default () {
return []
},
},
// 最大上传数量
maxCount: {
type: [String, Number],
default: 9,
},
// 是否自动上传
autoUpload: {
type: Boolean,
default: false,
},
// 内部预览图片区域和选择图片按钮的区域宽度
width: {
type: [String, Number],
default: 160,
},
// 内部预览图片区域和选择图片按钮的区域高度
height: {
type: [String, Number],
default: 160,
},
addSize: {
type: [String, Number],
default: 48,
},
uploading: {
type: Boolean,
default: false
},
showAdd: {
type: Boolean,
default: true
},
isNativeHead:{
type: Boolean,
default: true
}
},
data() {
return {
fileList: [],
qiniuToken: '',
sourceType: ['album', 'camera']
}
},
computed: {
keyList() {
let list = []
if (this.fileList.length) {
for (var item of this.fileList) {
if (item.key) {
list.push(item.key)
}
}
}
return list
},
slotStyle() {
return ` width:${this.width}rpx;height:${this.height}rpx;`
}
},
watch: {
list(val) {
if (val && !this.fileList.length) {
this.fileList = []
for (var item of val) {
this.fileList.push({
key: item,
url: item,
})
}
}
},
},
created() {
this.getQiniuToken()
},
methods: {
openSource() {
this.$refs['bottom-choose'].open()
},
sourceTypeChange(source) {
this.sourceType = [source]
this.$nextTick(()=>{ this.$refs['upload-images'].appStratChoose(this.sourceType) })
},
onChooseFail(error) {
console.log("onChooseFail:", error);
this.$emit('on-choose-fail');
},
filterList(listA, listB) {
listA = listA || []
listB = listB || []
let list = []
for (var item of listA) {
for (var obj of listB) {
if (obj.url == item.url) {
item.key = obj.key
}
}
list.push(item)
}
return list
},
handleListChange(lists, name) {
this.fileList = this.filterList(lists, this.fileList)
let newImages = this.fileList.filter((item) => {
return item.key == undefined
})
if (newImages && newImages.length > 0) {
this.$emit('update:uploading', true)
upload
.uploads(newImages, this.qiniuToken)
.then((res) => {
let list = []
if (res) {
for (var item of res) {
list.push({
url: item.url,
key: UPLOAD_FILE_HOST + item.key
})
}
}
this.fileList = this.filterList(this.fileList, list)
this.$emit('on-list-change', this.keyList)
console.log('upload:', this.fileList.length, this.keyList.length)
this.$emit('update:uploading', this.fileList.length != this.keyList.length)
})
.catch((msg) => {
console.log(msg)
})
} else {
this.$emit('on-list-change', this.keyList)
}
},
getQiniuToken() {
getQiNiuToken().then((res) => {
if (res.data) {
this.qiniuToken = res.data
}
})
},
selectFile() { // 触发选择图片;不能改文件名,外部要调
this.$refs['upload-images'].selectFile()
}
},
}
</script>
<style lang="scss" scoped>
/deep/.u-add-tips {
height: 0 !important;
margin-top: 0 !important;
overflow: hidden;
}
.slot-btn {
width: 160rpx;
height: 160rpx;
display: flex;
justify-content: center;
align-items: center;
background: #F6F7FA;
border-radius: 10rpx;
margin: 10rpx;
}
.slot-btn__hover {
background-color: rgb(235, 236, 238);
}
</style>
\ No newline at end of file
......
This diff is collapsed.
This diff is collapsed.
......@@ -46,8 +46,6 @@
"permissions" : [
"<uses-feature android:name=\"android.hardware.camera\"/>",
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
......@@ -78,10 +76,6 @@
"request" : "none",
"prompt" : "为保证您正常、安全地使用,需要获取设备识别码(部分手机提示为获取手机号码)使用权限,请允许。"
},
"permissionAccessFineLocation" : {
"request" : "none",
"prompt" : "为获取当地天气信息,需要获取 位置信息 使用权限,请允许。"
},
"schemes" : "com.shenjiying.jizhang",
"minSdkVersion" : 21,
"targetSdkVersion" : 30
......
......@@ -15,27 +15,26 @@
</view>
<view class="cropper-buttons safe-area-padding" :style="{ height: bottomNavHeight + 'px' }">
<!-- #ifdef H5 -->
<view class="upload" @tap="selectFile">选择图片</view>
<view class="upload" @tap="chooseImage">选择图片</view>
<!-- #endif -->
<!-- #ifndef H5 -->
<view class="upload" @tap="selectFile">重新选择</view>
<view class="upload" @tap="chooseImage">重新选择</view>
<!-- #endif -->
<view class="getCropperImage" @tap="getCropperImage(false)">确定</view>
</view>
<BottomChoose ref="bottom-choose" @change="sourceTypeChange" />
<AuthPopup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID" />
<view class="choose-image-view">
<ChooseImage ref="choose-image" :max-count="1" :width="144" :height="144"
@on-list-change="handlePicturesChange" />
</view>
</view>
</template>
<script>
import BottomChoose from '@/components/bottom-choose'
import AuthPopup from '@/components/auth-popup'
import {getSetting} from '@/utils/common.js'
import ChooseImage from '@/components/upload/chooseImage.vue';
import WeCropper from './weCropper.js';
export default {
components: {
BottomChoose,
AuthPopup
ChooseImage,
},
props: {
// 裁剪矩形框的样式,其中可包含的属性为lineWidth-边框宽度(单位rpx),color: 边框颜色,
......@@ -84,7 +83,6 @@
},
data() {
return {
sourceType: ['album', 'camera'],
// 底部导航的高度
bottomNavHeight: 50,
originWidth: 200,
......@@ -118,17 +116,8 @@
// 输出的图片类型,如果'png'类型发现裁剪的图片太大,改成"jpg"即可
fileType: 'jpg',
src: '', // 选择的图片路径,用于在点击确定时,判断是否选择了图片
isIOS:false,
permissionID:''
};
},
mounted() {
let res = uni.getSystemInfoSync();
let {
platform
} = res
this.isIOS=platform === 'ios'
},
onLoad(option) {
let rectInfo = uni.getSystemInfoSync();
this.width = rectInfo.windowWidth;
......@@ -168,9 +157,10 @@
frontColor: '#ffffff',
backgroundColor: '#000000'
});
},
onReady() {
this.selectFile()
this.chooseImage()
},
methods: {
touchStart(e) {
......@@ -211,68 +201,14 @@
}
});
},
openSource() {
this.$refs['bottom-choose'].open()
},
sourceTypeChange(source) {
this.sourceType = [source]
this.appStratChoose()
},
//打开自定义权限目的弹框
openAuth(permissionID) {
// this.permissionID = permissionID; //这个是对应的权限 ACCESS_FINE_LOCATION 位置权限 / WRITE_EXTERNAL_STORAGE 存储空间/照片权限 / CAMERA相机权限 / CALL_PHONE 拨打电话
setTimeout(() => {
this.$refs['authpup'].open();
}, 500)
chooseImage() {
this.$refs['choose-image'].selectFile()
},
//用户授权权限后的回调
changeAuth() {
//这里是权限通过后执行自己的代码逻辑
console.log('权限已授权,可执行自己的代码逻辑了');
this.stratChoose()
},
// 选择图片
selectFile() {
// #ifdef APP-PLUS
this.openSource()
// #endif
// #ifdef MP-TOUTIAO
getSetting('scope.camera', '检测到您没打开相机权限,是否去设置打开?', res => {
this.stratChoose();
});
// #endif
// #ifndef APP-PLUS || MP-TOUTIAO
// 小程序直接打开相机
this.stratChoose();
// #endif
},
appStratChoose() {
let permissionID = "CAMERA"
if (this.sourceType.findIndex(e => e === 'camera') !== -1) {
permissionID = "CAMERA"
} else if (this.sourceType.findIndex(e => e === 'album') !== -1) {
permissionID = "WRITE_EXTERNAL_STORAGE"
}
this.permissionID = permissionID
if (this.isIOS) {
this.stratChoose();
} else {
this.openAuth()
}
handlePicturesChange(lists) {
this.src = lists[0].url;
// 获取裁剪图片资源后,给data添加src属性及其值
this.cropper.pushOrign(this.src);
},
stratChoose() {
uni.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: this.sourceType, // 可以指定来源是相册还是相机,默认二者都有
success: (res) => {
this.src = res.tempFilePaths[0];
// 获取裁剪图片资源后,给data添加src属性及其值
this.cropper.pushOrign(this.src);
}
});
}
}
};
</script>
......@@ -282,6 +218,7 @@
.content {
background: rgba(255, 255, 255, 1);
overflow: hidden;
}
.cropper {
......@@ -335,4 +272,11 @@
text-align: right;
padding-right: 50rpx;
}
.choose-image-view {
top: -200%;
left: -200%;
position: absolute;
z-index: 99;
}
</style>
\ No newline at end of file
......@@ -8,6 +8,7 @@ export const userinfo = "USERINFO"
export const headName = 'admin-token';
export const temperature = 'TEMPERATURE';
export const appid = "wx55e75ad85611191f"
export const appName = "扳手记账"
export const API_HOST = ''; // 测试服
export const baseUrl = process.uniEnv.qn_base_url; // 七牛云对象存储图片地址
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment