当前位置:网站首页>微信小程序保存图片的方法
微信小程序保存图片的方法
2022-06-26 04:37:00 【余白x】
下载(wx.downloadFile) + 保存(wx.saveImageToPhotosAlbum) +授权(wx.openSetting)
// 保存图片的方法
serve(img) {
wx.showLoading({
title: '加载中...'
});
//wx.downloadFile方法:下载文件资源到本地
wx.downloadFile({
url: img, //图片地址
success: function (res) {
//wx.saveImageToPhotosAlbum方法:保存图片到系统相册
wx.saveImageToPhotosAlbum({
filePath: res.tempFilePath, //图片文件路径
success: function (data) {
wx.hideLoading(); //隐藏 loading 提示框
wx.showToast({
title: '保存成功',
icon: 'none'
})
},
// 接口调用失败的回调函数
fail: function (err) {
if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny" || err.errMsg === "saveImageToPhotosAlbum:fail authorize no response") {
wx.showModal({
title: '提示',
content: '请授权保存到相册',
modalType: false,
success: res => {
if (res.confirm) {
wx.openSetting({
success(settingdata) {
console.log("settingdata", settingdata)
if (settingdata.authSetting['scope.writePhotosAlbum']) {
wx.showToast({
title: '授权成功',
icon: 'none'
})
} else {
wx.showToast({
title: '授权失败',
icon: 'none'
})
}
},
fail(failData) {
console.log("failData", failData)
},
complete(finishData) {
console.log("finishData", finishData)
}
})
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
},
complete(res) {
wx.hideLoading(); //隐藏 loading 提示框
}
})
}
})
},边栏推荐
- numpy 数据输入输出
- Motivational skills for achieving goals
- Sixtool- source code of multi-functional and all in one generation hanging assistant
- There is no response to redirection and jump in the laravel constructor [original]
- Tp6 is easy to tread [original]
- Performance test comparison between PHP framework jsnpp and thinkphp6
- CTF crypto (I) some simple encoding and encryption
- PHP syntax summary
- 2.8 learning summary
- 1064 (42000) error occurred when installing MySQL and modifying root password
猜你喜欢

Database design (I)

6、 Project practice --- identifying cats and dogs

NPM installation tutorial

Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start

1.16 learning summary

Install SVN in Pagoda and build SVN version Library

1.21 learning summary

#微信小程序# 在小程序里面退出退出小程序(navigator以及API--wx.exitMiniProgram)

记录一次循环引用的问题

Introduction to markdown grammar
随机推荐
CTF serialization and deserialization
TP5 distinct method paging problem
Install cenos in the virtual machine
Oracle 數據泵導錶
CDN with OSS acceleration
Nightmare
Physical design of database design (2)
MySQL enable logbin in Qunhui docker
numpy 随机数
Dameng database backup and restore
Simple personal summary of tp6 multi application deployment -- Part I [original]
记录一次循环引用的问题
1.21 learning summary
Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am
Oracle data pump table
一幅脑图总结一下需求分析(工作上实际遇到的情况的补充)
Report on demand situation and development trend of China's OTC industry from 2022 to 2028
PHP small factory moves bricks for three years - interview series - my programming life
2.9 learning summary
The select option in laravel admin contains a large amount of data