@[TOC]小程序开发//常用的小程序保存图片功能 利用mpvue开发
//触发函数
savePoster() {
wx.getSetting({
success: (res) => {
if (res.authSetting['scope.writePhotosAlbum']) {
this.wxSaveImg()
console.log('已经授权了')
} else if (res.authSetting['scope.writePhotosAlbum'] === undefined) {
console.log('未授权')
wx.authorize({
scope: 'scope.writePhotosAlbum',
success: () => {
this.wxSaveImg()
},
fail: () => {
wx.showToast({
title: '您没有授权,无法保存到相册',
icon: 'none'
})
}
})
} else {
this.wxUtils.showToast('打开相册授权才能保存哦')
wx.openSetting({
success: (res) => {
if (res.authSetting['scope.writePhotosAlbum']) {
this.saveImg()
} else {
wx.showToast({
title: '您没有授权,无法保存到相册',
icon: 'none'
})
}
}
})
}
}
})
}
保存
wxSaveImg() {
this.wxUtils.showLoading('正在保存中')
wx.getImageInfo({
src: this.posterUrl,
success: res => {
wx.saveImageToPhotosAlbum({
filePath: res.path,
success: res => {
this.wxUtils.showToast('保存成功')
if (this.estateId) {
this.appendEventLog({
eventPageAction: 6,
eventPage: 1,
dataId: this.estateId,
dataName: this.name,
dataType: 1,
eventDescribe: `保存了置业计划书`
})
}
},
fail: res => {
console.log(res)
this.wxUtils.showToast('保存失败,请重新尝试')
},
complete: res => {
this.wxUtils.hideLoading('正在保存中')
console.log(res, '结束')
}
})
},
complete: res => {
console.log(res, 'complete')
},
fail: res => {
console.log(res)
this.wxUtils.showToast('保存失败,请重新尝试')
}
})
},