|
|
@ -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('获取图片信息失败')) |
|
|
|
// } |
|
|
|
// }) |
|
|
|
}) |
|
|
|
}, |
|
|
|
|
|
|
|