95 lines
2.7 KiB
JavaScript
95 lines
2.7 KiB
JavaScript
|
|
import permission from '@/common/permission'
|
|||
|
|
export function handleAuthLocation(msg) {
|
|||
|
|
return new Promise((resolve, reject) => {
|
|||
|
|
const appAuthorizeSetting = uni.getAppAuthorizeSetting()
|
|||
|
|
console.info(appAuthorizeSetting.locationAuthorized)
|
|||
|
|
let isIos
|
|||
|
|
// #ifdef APP-PLUS
|
|||
|
|
isIos = plus.os.name == 'iOS'
|
|||
|
|
// #endif
|
|||
|
|
if (appAuthorizeSetting.locationAuthorized === 'authorized' || (isIos && appAuthorizeSetting.locationAuthorized === 'not determined')) {
|
|||
|
|
resolve()
|
|||
|
|
} else {
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '温馨提示',
|
|||
|
|
content: msg,
|
|||
|
|
confirmText: '前往设置',
|
|||
|
|
success: function (res) {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
permission.gotoAppPermissionSetting()
|
|||
|
|
} else if (res.cancel) {
|
|||
|
|
console.log('用户点击取消')
|
|||
|
|
reject()
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function handleAuthCamera(msg) {
|
|||
|
|
const appAuthorizeSetting = uni.getAppAuthorizeSetting()
|
|||
|
|
console.info(appAuthorizeSetting.cameraAuthorized)
|
|||
|
|
let isIos
|
|||
|
|
// #ifdef APP-PLUS
|
|||
|
|
isIos = plus.os.name == 'iOS'
|
|||
|
|
// #endif
|
|||
|
|
if (appAuthorizeSetting.cameraAuthorized === 'denied' || (isIos && appAuthorizeSetting.albumAuthorized === 'denied')) {
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '温馨提示',
|
|||
|
|
content: msg,
|
|||
|
|
confirmText: '前往设置',
|
|||
|
|
success: function (res) {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
permission.gotoAppPermissionSetting()
|
|||
|
|
} else if (res.cancel) {
|
|||
|
|
console.log('用户点击取消')
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function _chooseImage(args) {
|
|||
|
|
return uni.chooseImage({
|
|||
|
|
...args,
|
|||
|
|
fail: function (error) {
|
|||
|
|
let isIos
|
|||
|
|
// #ifdef APP-PLUS
|
|||
|
|
isIos = plus.os.name == 'iOS'
|
|||
|
|
// #endif
|
|||
|
|
if(!isIos) {
|
|||
|
|
handleAuthCamera('需要获取相机,相册权限用于上传图片或拍摄视频,请允许此App获取此设备的相册/相机权限!')
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export function handleAuthScan() {
|
|||
|
|
return new Promise((resolve, reject) => {
|
|||
|
|
const appAuthorizeSetting = uni.getAppAuthorizeSetting()
|
|||
|
|
console.info(appAuthorizeSetting.cameraAuthorized)
|
|||
|
|
let isIos
|
|||
|
|
// #ifdef APP-PLUS
|
|||
|
|
isIos = plus.os.name == 'iOS'
|
|||
|
|
// #endif
|
|||
|
|
if (appAuthorizeSetting.cameraAuthorized === 'authorized' || (isIos && appAuthorizeSetting.cameraAuthorized === 'not determined')) {
|
|||
|
|
resolve()
|
|||
|
|
} else {
|
|||
|
|
uni.showModal({
|
|||
|
|
title: '温馨提示',
|
|||
|
|
content: '当前无相机访问权限,(请打开 设置-隐私-相机 来进行设置)',
|
|||
|
|
confirmText: '前往设置',
|
|||
|
|
success: function (res) {
|
|||
|
|
if (res.confirm) {
|
|||
|
|
permission.gotoAppPermissionSetting()
|
|||
|
|
} else if (res.cancel) {
|
|||
|
|
console.log('用户点击取消')
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
reject()
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
}
|