当前位置:网站首页>微信小程序保存圖片的方法
微信小程序保存圖片的方法
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 提示框
}
})
}
})
},边栏推荐
猜你喜欢

Tp6 multi table Association (table a is associated with table B, table B is associated with table C, and table d)

Database design (3): database maintenance and optimization

Rdkit chemical formula molecular formula search

TP5 distinct method paging problem

Dameng database backup and restore

Install Damon database

Install cenos in the virtual machine

文件上传与安全狗

2.9 learning summary
![Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am](/img/71/ed3b2ca9e6d4afd2dae3c601b3a75b.jpg)
Fastadmin always prompts sqlstate[23000]: integrity constraint violation: 1052 column 'ID' in order clause is am
随机推荐
Nabicat连接:本地Mysql&&云服务Mysql以及报错
Use shell script to analyze system CPU, memory and network throughput
Essential foundation of programming - Summary of written interview examination sites - computer network (1) overview
Physical design of database design (2)
LISP programming language
Mysql8.0 configuring my SQL in INI file_ mode=NO_ AUTO_ CREATE_ User can start
防撤回测试记录
Sixtool- source code of multi-functional and all in one generation hanging assistant
Compiling and installing phpredis extension on MAC
Resolve PHP is not an internal or external command
The statistics in the MySQL field become strings, and then they are converted into numbers for sorting
Condition query
做软件测试学历重要还是能力重要
202.2.9
Install cenos in the virtual machine
CTF crypto (I) some simple encoding and encryption
Numpy random number
ctf [RoarCTF 2019]easy_ calc
Numpy data input / output
"Eight hundred"