微信小程序实现保存网络图片到本地相册

111 阅读1分钟

微信小程序实现保存网络图片到本地相册

const downPic = ()=>{
		wx.showLoading({
		      title: "正在下载图片... ",
		      mask: !1
		  })
		
		  wx.downloadFile({
		  url: 'https://source.redbks.net/image/20230710fenxiangyouli1.png',
		  success: function(t) {
		      wx.showLoading({
		          title: "正在保存图片",
		          mask: !1
		      })
			   wx.saveImageToPhotosAlbum({
			            filePath: t.tempFilePath,
			            success: function() {
			                wx.showModal({
			                    title: "自定义提示信息",
			                    content: "保存成功",
			                    showCancel: !1
			                });
			            },
			            fail: function(t) {
			                wx.showModal({
			                    title: "图片保存失败",
			                    content: t.errMsg,
			                    showCancel: !1
			                });
			            },
			            complete: function(t) {
			                wx.hideLoading();
			            }
			        });
		  },
		  fail: function(t) {
		      wx.showModal({
		          title: "图片下载失败",
		          content: t.errMsg,
		          showCancel: !1
		      });
		  },
		  complete: function(t) {
		      wx.hideLoading();
		  }
		  })
	}