|
|
@@ -84,9 +84,90 @@ export default {
|
|
|
filePath: res.tempFilePath,
|
|
|
success: function (data) {
|
|
|
uni.showToast({title:'下载成功!'})
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ // #ifdef MP-WEIXIN
|
|
|
+ const errMsg = (err && err.errMsg) || ''
|
|
|
+ if (errMsg.indexOf('auth deny') > -1 || errMsg.indexOf('auth denied') > -1) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请先在设置中开启“添加到相册”权限后再保存图片',
|
|
|
+ confirmText: '去设置',
|
|
|
+ success: (modalRes) => {
|
|
|
+ if (modalRes.confirm) {
|
|
|
+ uni.openSetting({
|
|
|
+ success: (settingRes) => {
|
|
|
+ if (settingRes.authSetting['scope.writePhotosAlbum']) {
|
|
|
+ this.downloadImg2(url)
|
|
|
+ } else {
|
|
|
+ this.$msg('未开启相册权限,无法保存图片')
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ this.$msg('打开设置失败,请手动开启相册权限')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ // #ifdef APP-PLUS
|
|
|
+ let hasNoAlbumPermission = false
|
|
|
+ const platformType = uni.getSystemInfoSync().platform
|
|
|
+ if (platformType === 'android') {
|
|
|
+ const writeStore = plus.navigator.checkPermission('android.permission.WRITE_EXTERNAL_STORAGE')
|
|
|
+ const readStore = plus.navigator.checkPermission('android.permission.READ_EXTERNAL_STORAGE')
|
|
|
+ hasNoAlbumPermission = writeStore !== 'authorized' || readStore !== 'authorized'
|
|
|
+ } else if (platformType === 'ios') {
|
|
|
+ const errMsg = (err && err.errMsg) || ''
|
|
|
+ hasNoAlbumPermission = errMsg.indexOf('No access') > -1 || errMsg.indexOf('auth deny') > -1
|
|
|
+ }
|
|
|
+ if (hasNoAlbumPermission) {
|
|
|
+ uni.showModal({
|
|
|
+ title: '提示',
|
|
|
+ content: '请先在系统设置中开启照片保存权限后再保存图片',
|
|
|
+ confirmText: '去设置',
|
|
|
+ success: (modalRes) => {
|
|
|
+ if (!modalRes.confirm) return
|
|
|
+ if (platformType === 'android') {
|
|
|
+ try {
|
|
|
+ const main = plus.android.runtimeMainActivity()
|
|
|
+ const Intent = plus.android.importClass('android.content.Intent')
|
|
|
+ const Settings = plus.android.importClass('android.provider.Settings')
|
|
|
+ const Uri = plus.android.importClass('android.net.Uri')
|
|
|
+ const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
|
|
|
+ intent.setData(Uri.parse('package:' + main.getPackageName()))
|
|
|
+ main.startActivity(intent)
|
|
|
+ } catch (e) {
|
|
|
+ this.$msg('打开设置失败,请手动开启照片权限')
|
|
|
+ }
|
|
|
+ } else if (platformType === 'ios') {
|
|
|
+ plus.runtime.openURL('app-settings:')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ console.log("下载失败信息--", err)
|
|
|
+ uni.showToast({
|
|
|
+ title:'权限刚开启,请重新点击保存图片',
|
|
|
+ icon: "none",
|
|
|
+ duration: 3000
|
|
|
+ });
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // #endif
|
|
|
+ this.$msg('保存失败,请稍后重试')
|
|
|
}
|
|
|
});
|
|
|
+ } else {
|
|
|
+ this.$msg('下载失败,请稍后重试')
|
|
|
}
|
|
|
+ },
|
|
|
+ fail: () => {
|
|
|
+ this.$msg('下载失败,请检查网络后重试')
|
|
|
}
|
|
|
});
|
|
|
},
|