当前位置:网站首页>微信小程序保存圖片的方法
微信小程序保存圖片的方法
2022-06-26 04:40: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 提示框
}
})
}
})
},边栏推荐
- PHP small factory moves bricks for three years - interview series - my programming life
- Jenkins introduces custom jars
- NVM installation and use and NPM package installation failure record
- 修改Oracle连接数
- Simple use of redis in laravel
- There is no response to redirection and jump in the laravel constructor [original]
- Group by and order by are used together
- Large numbers (C language)
- Compiling and installing phpredis extension on MAC
- mysql高级学习(跟着尚硅谷老师周阳学习)
猜你喜欢

1.11 learning summary

1.12 learning summary

Resolve PHP is not an internal or external command

1.24 learning summary

CTF PHP audit bypasses filtering learning from topics

记录一次循环引用的问题

A brain map to summarize the needs analysis (a supplement to the actual situation at work)

PHP small factory moves bricks for three years - interview series - my programming life

SixTool-多功能多合一代挂助手源码

Multipass中文文档-远程使用Multipass
随机推荐
Dameng database backup and restore
Add, delete, modify and query curd in PHP native SQL
Zhimeng CMS will file a lawsuit against infringing websites
Simple application of KMP
JWT token authentication verification
MySQL index details
Navicat connects the pit of shardingsphere sub table and sub library plug-ins
Realize video call and interactive live broadcast in the applet
Redis cache message queue
Group by and order by are used together
Multipass中文文档-使用实例命令别名
Multipass中文文档-使用Multipass服务授权客户端
Simple use of redis in laravel
Simple personal summary of tp6 multi application deployment -- Part I [original]
问题随记 —— pip 换源
Numpy data input / output
1.21 learning summary
Is education important or ability important in software testing
Clean up photo SCR virus / iframekill injection removal /iframekill removal photo scr
2022 talent strategic transformation under the development trend of digital economy