|
@@ -57,83 +57,63 @@ Page({
|
|
|
|
|
|
download() {
|
|
|
if (!this.data.ls_url) return
|
|
|
- wx.downloadFile({
|
|
|
- url: this.data.ls_url, // 这里替换为你的图片链接
|
|
|
- success: function (res) {
|
|
|
- if (res.statusCode === 200) {
|
|
|
- wx.saveImageToPhotosAlbum({
|
|
|
- filePath: res.tempFilePath, // 使用下载得到的临时文件路径
|
|
|
- success: function (saveRes) {
|
|
|
- wx.showToast({
|
|
|
- title: '保存成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- if (err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied') {
|
|
|
- wx.showModal({
|
|
|
- title: '保存失败',
|
|
|
- content: '请前往设置页面授权保存图片到相册',
|
|
|
- showCancel: false,
|
|
|
- success: function (modalRes) {
|
|
|
- wx.openSetting({
|
|
|
- withSubscriptions: true,
|
|
|
- success: function (res) {
|
|
|
- if (res.authSetting['scope.writePhotosAlbum']) {
|
|
|
- // 用户重新授权后,再次尝试保存图片
|
|
|
- wx.saveImageToPhotosAlbum({
|
|
|
- filePath: res.tempFilePath,
|
|
|
- success: function (saveRes) {
|
|
|
- wx.showToast({
|
|
|
- title: '保存成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- wx.showToast({
|
|
|
- title: '保存失败',
|
|
|
- icon: 'none',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
+ wx.saveImageToPhotosAlbum({
|
|
|
+ filePath: this.data.ls_url, // 使用下载得到的临时文件路径
|
|
|
+ success: function (saveRes) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '已保存至相册',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ if (err.errMsg === 'saveImageToPhotosAlbum:fail:auth denied') {
|
|
|
+ wx.showModal({
|
|
|
+ title: '保存失败',
|
|
|
+ content: '请前往设置页面授权保存图片到相册',
|
|
|
+ showCancel: false,
|
|
|
+ success: function (modalRes) {
|
|
|
+ wx.openSetting({
|
|
|
+ withSubscriptions: true,
|
|
|
+ success: function (res) {
|
|
|
+ if (res.authSetting['scope.writePhotosAlbum']) {
|
|
|
+ // 用户重新授权后,再次尝试保存图片
|
|
|
+ wx.saveImageToPhotosAlbum({
|
|
|
+ filePath: res.tempFilePath,
|
|
|
+ success: function (saveRes) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '保存成功',
|
|
|
+ icon: 'success',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
},
|
|
|
fail: function (err) {
|
|
|
wx.showToast({
|
|
|
- title: '打开设置页面失败',
|
|
|
+ title: '保存失败',
|
|
|
icon: 'none',
|
|
|
duration: 2000
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- });
|
|
|
- } else {
|
|
|
- wx.showToast({
|
|
|
- title: '保存失败',
|
|
|
- icon: 'none',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
- }
|
|
|
+ },
|
|
|
+ fail: function (err) {
|
|
|
+ wx.showToast({
|
|
|
+ title: '打开设置页面失败',
|
|
|
+ icon: 'none',
|
|
|
+ duration: 2000
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
wx.showToast({
|
|
|
- title: '下载失败',
|
|
|
+ title: '保存失败',
|
|
|
icon: 'none',
|
|
|
duration: 2000
|
|
|
});
|
|
|
}
|
|
|
- },
|
|
|
- fail: function (err) {
|
|
|
- wx.showToast({
|
|
|
- title: '下载失败',
|
|
|
- icon: 'none',
|
|
|
- duration: 2000
|
|
|
- });
|
|
|
}
|
|
|
});
|
|
|
},
|