diff --git a/uniapp/pages/invite/index.vue b/uniapp/pages/invite/index.vue index aa451d0..bb575c3 100644 --- a/uniapp/pages/invite/index.vue +++ b/uniapp/pages/invite/index.vue @@ -277,22 +277,52 @@ function handleSaveQrcode() { uni.showToast({ title: '二维码未加载', icon: 'none' }) return } - uni.saveImageToPhotosAlbum({ - filePath: qrcodeUrl.value, - success: () => { uni.showToast({ title: '保存成功', icon: 'success' }) }, - fail: (err) => { - if (err.errMsg.includes('auth deny')) { - uni.showModal({ - title: '提示', - content: '需要您授权保存图片到相册', - confirmText: '去设置', - success: (res) => { if (res.confirm) uni.openSetting() } - }) - } else { - uni.showToast({ title: '保存失败', icon: 'none' }) + + /** + * 保存图片到相册 + * 需要先将网络图片下载到本地临时路径,再调用保存接口 + */ + function saveToAlbum(tempFilePath) { + uni.saveImageToPhotosAlbum({ + filePath: tempFilePath, + success: () => { uni.showToast({ title: '保存成功', icon: 'success' }) }, + fail: (err) => { + if (err.errMsg.includes('auth deny') || err.errMsg.includes('authorize')) { + uni.showModal({ + title: '提示', + content: '需要您授权保存图片到相册', + confirmText: '去设置', + success: (res) => { if (res.confirm) uni.openSetting() } + }) + } else { + uni.showToast({ title: '保存失败', icon: 'none' }) + } } - } - }) + }) + } + + // 网络图片需要先下载到本地 + if (qrcodeUrl.value.startsWith('http')) { + uni.showLoading({ title: '保存中...' }) + uni.downloadFile({ + url: qrcodeUrl.value, + success: (res) => { + uni.hideLoading() + if (res.statusCode === 200) { + saveToAlbum(res.tempFilePath) + } else { + uni.showToast({ title: '下载图片失败', icon: 'none' }) + } + }, + fail: () => { + uni.hideLoading() + uni.showToast({ title: '下载图片失败', icon: 'none' }) + } + }) + } else { + // 本地路径直接保存 + saveToAlbum(qrcodeUrl.value) + } } function handleShowWithdraw() {