diff --git a/manifest.json b/manifest.json index db6f562..e02faa9 100644 --- a/manifest.json +++ b/manifest.json @@ -59,7 +59,10 @@ "permission" : { "scope.userLocation" : { "desc" : "您的位置信息将用于选择寄件地址" - } + }, + "scope.writePhotosAlbum": { + "desc": "需要保存图片到您的相册" + } } }, "mp-alipay" : { diff --git a/pages/subcomponent/promo-qrcode.vue b/pages/subcomponent/promo-qrcode.vue index bc8e15c..fcd8238 100644 --- a/pages/subcomponent/promo-qrcode.vue +++ b/pages/subcomponent/promo-qrcode.vue @@ -177,35 +177,61 @@ export default { // 获取图片信息并保存到相册 imgApi(image) { return new Promise((resolve, reject) => { - // 获取图片的信息 - uni.getImageInfo({ - src: image, - success: (imageInfo) => { - // 保存图片到手机相册 - uni.saveImageToPhotosAlbum({ - filePath: imageInfo.path, - success: () => { - uni.showModal({ - title: '保存成功', - content: '图片已成功保存到相册', - showCancel: false - }) - resolve() - }, - fail: (err) => { - console.log('保存失败', err) - reject(new Error('保存失败')) - }, - complete: (res) => { - console.log('保存结果:', res) - } - }) - }, - fail: (err) => { - console.log('获取图片信息失败:', err) - reject(new Error('获取图片信息失败')) - } - }) + + // 先下载图片到本地临时路径 + wx.downloadFile({ + url: image, + success: (res) => { + if (res.statusCode === 200) { + const tempFilePath = res.tempFilePath; + // 保存到相册 + wx.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: () => { + wx.showToast({ title: '保存成功', icon: 'success' }); + }, + fail: (err) => { + console.error('保存失败:', err); + wx.showToast({ title: '保存失败', icon: 'none' }); + } + }); + } + }, + fail: (err) => { + console.error('下载失败:', err); + wx.showToast({ title: '图片下载失败', icon: 'none' }); + } + }); + + // // 获取图片的信息 + // uni.getImageInfo({ + // src: image, + // success: (imageInfo) => { + // // 保存图片到手机相册 + // uni.saveImageToPhotosAlbum({ + // filePath: imageInfo.path, + // success: () => { + // uni.showModal({ + // title: '保存成功', + // content: '图片已成功保存到相册', + // showCancel: false + // }) + // resolve() + // }, + // fail: (err) => { + // console.log('保存失败', err) + // reject(new Error('保存失败')) + // }, + // complete: (res) => { + // console.log('保存结果:', res) + // } + // }) + // }, + // fail: (err) => { + // console.log('获取图片信息失败:', err) + // reject(new Error('获取图片信息失败')) + // } + // }) }) },