代码 judgePermissionPro 是申请权限的方法 promise 封装; 可以换成 plus.android.requestPermissions;最终效果如下
uni.showActionSheet({
itemList: ['拍照', '相册'],
success: function (res) {
const index = res.tapIndex + 1
if (index == 1) {
judgePermissionPro('camera').then(() => {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: [camera], //这要注意,camera掉拍照,album是打开手机相册
success: (res) => {
const tempFilePath = res.tempFilePaths[0]
pathToBase64(tempFilePath)
.then(base64 => {
callBack({
result: base64
})
})
}
})
})
} else if (index == 2) {
judgePermissionPro('READ_MEDIA_IMAGES').then(() => {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: [album], //这要注意,camera掉拍照,album是打开手机相册
success: (res) => {
const tempFilePath = res.tempFilePaths[0]
pathToBase64(tempFilePath)
.then(base64 => {
callBack({
result: base64
})
})
}
})
})
}
}
});