| | |
| | | content: options.content, |
| | | confirmText: options.confirmText, |
| | | showCancel: false, |
| | | confirmColor: '#106efa', |
| | | success: (res) => { |
| | | if (res.confirm) { |
| | | uni.setStorageSync(LOCATION_NOTICE_STORAGE_KEY, true) |
| | |
| | | }) |
| | | } |
| | | |
| | | let hasEmittedLocationPermissionGranted = false |
| | | |
| | | export function getLocationWithNotice(locationOptions = {}, modalOptions = {}) { |
| | | return ensureLocationPermissionNotice(modalOptions).then((confirmed) => { |
| | | if (!confirmed) { |
| | |
| | | return new Promise((resolve, reject) => { |
| | | uni.getLocation(Object.assign({}, locationOptions, { |
| | | success: (res) => { |
| | | uni.$emit('locationPermissionGranted', res) |
| | | if (!hasEmittedLocationPermissionGranted) { |
| | | hasEmittedLocationPermissionGranted = true |
| | | uni.$emit('locationPermissionGranted', res) |
| | | } |
| | | if (typeof locationOptions.success === 'function') { |
| | | locationOptions.success(res) |
| | | } |
| | |
| | | resolve(res) |
| | | }, |
| | | fail: (err) => { |
| | | console.log('chooseImage fail', err) |
| | | const errMsg = (err && err.errMsg) || '' |
| | | if (errMsg && !/cancel/i.test(errMsg)) { |
| | | const errCode = (err && err.errCode) || '' |
| | | if (errMsg && errMsg.includes('chooseImage:fail No Permission')) { |
| | | // const sourceType = imageOptions.sourceType || ['album', 'camera'] |
| | | |
| | | let toastTitle = '' |
| | | |
| | | // 拍照权限 |
| | | // 拍照权限 |
| | | if (errCode === 11) { |
| | | toastTitle = '相机权限已关闭,请前往手机【设置】中手动开启' |
| | | } |
| | | |
| | | // 相册权限 |
| | | if (errCode === 12) { |
| | | toastTitle = '相册权限已关闭,请前往手机【设置】中手动开启' |
| | | } |
| | | |
| | | // if (sourceType.length === 1) { |
| | | // if (sourceType[0] === 'album') { |
| | | // toastTitle = '相册权限已关闭,请前往手机【设置】中手动开启' |
| | | // } else if (sourceType[0] === 'camera') { |
| | | // toastTitle = '相机权限已关闭,请前往手机【设置】中手动开启' |
| | | // } |
| | | // } else { |
| | | // if (errMsg.includes('camera') || errMsg.includes('Camera')) { |
| | | // toastTitle = '相机权限已关闭,请前往手机【设置】中手动开启' |
| | | // } else if (errMsg.includes('album') || errMsg.includes('Album') || errMsg.includes('photo') || errMsg.includes('Photo')) { |
| | | // toastTitle = '相册权限已关闭,请前往手机【设置】中手动开启' |
| | | // } |
| | | // } |
| | | |
| | | uni.showToast({ |
| | | title: '需要授权相机权限', |
| | | icon: 'none' |
| | | title: toastTitle, |
| | | icon: 'none', |
| | | duration: 3000 |
| | | }) |
| | | } |
| | | if (typeof imageOptions.fail === 'function') { |