123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- // pages/download/download.ts
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- codeUrl: "https://music-play.oss-cn-shenzhen.aliyuncs.com/device/20221107134141195228914.png",
- nvabarData: {
- showCapsule: 1, //是否显示左上角图标 1表示显示 0表示不显示
- title: '下载', //导航栏 中间的标题
- },
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- init().then((res)=> {
- this.setData({
- codeUrl: res.appDownQrCode,
- })
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- // 保存海报
- saveImageToPhotosAlbum() {
- const _this = this;
- wx.showLoading({
- title: '保存中...'
- })
- wx.downloadFile({
- url: _this.data.codeUrl,
- success: function (res) {
- //图片保存到本地
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function (data) {
- wx.hideLoading()
- wx.showToast({
- title: '保存成功',
- icon: 'success',
- duration: 2000
- })
- },
- fail: function (err) {
- if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
- // 这边微信做过调整,必须要在按钮中触发,因此需要在弹框回调中进行调用
- wx.showModal({
- title: '提示',
- content: '需要您授权保存相册',
- showCancel: false,
- success(){
- wx.openSetting({
- success(settingdata) {
- console.log("settingdata", settingdata)
- if (settingdata.authSetting['scope.writePhotosAlbum']) {
- wx.showModal({
- title: '提示',
- content: '获取权限成功,再次点击图片即可保存',
- showCancel: false,
- })
- } else {
- wx.showModal({
- title: '提示',
- content: '获取权限失败,将无法保存到相册哦~',
- showCancel: false,
- })
- }
- },
- fail(failData) {
- console.log("failData",failData)
- },
- complete(finishData) {
- console.log("finishData", finishData)
- }
- })
- }
- })
- }
- },
- complete(res) {
- wx.hideLoading()
- }
- })
- }
- })
- },
- })
|