saveImgToPhotosAlbum.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function saveImgToPhotosAlbum(url) {
  2. return new Promise((reslove, reject) => {
  3. if (url) {
  4. // console.log(url,"url")
  5. uni.showLoading({
  6. title: '保存中',
  7. mask: true
  8. })
  9. uni.getSetting({
  10. success(res) {
  11. uni.downloadFile({
  12. url: url,
  13. success: function (res) {
  14. // console.log(res)
  15. var temp = res.tempFilePath
  16. uni.saveImageToPhotosAlbum({
  17. filePath: temp,
  18. success: function (res) {
  19. uni.hideLoading()
  20. reslove(res)
  21. },
  22. fail: function (err) {
  23. uni.hideLoading()
  24. reject(err)
  25. }
  26. })
  27. },
  28. fail: function (err) {
  29. // console.log(err,"err")
  30. uni.hideLoading()
  31. // wx.utils.alert('保存失败')
  32. uni.showToast({
  33. title: '保存失败',
  34. icon: 'none',
  35. mask: true,
  36. })
  37. }
  38. })
  39. },
  40. fail(res) {
  41. }
  42. })
  43. } else {
  44. wx.showLoading({
  45. title: '请稍等',
  46. mask: true
  47. })
  48. setTimeout(() => {
  49. uni.hideLoading()
  50. }, 1000)
  51. }
  52. })
  53. }
  54. module.exports = {
  55. saveImgToPhotosAlbum
  56. }