Small micro-channel program to save local

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed, up to tertiary niche: Reverse rest of his life, except you have https://blog.csdn.net/qq_36232611/article/details/90684382

image

Tip box:

wx.showToast(OBJECT)

Displays a message box

wx.saveImageToPhotosAlbum({
  filePath : "./test.png",   //这个只是测试路径,没有效果
  success(res) {
    console.log("success");
  },
  fail : function(res) {
    console.log(res);
  }
})
wx.showToast({

 title: '成功',

 icon: 'success',

 duration: 2000

})
wx.hideToast()

隐藏消息提示框
wx.showToast({

 title: '加载中',

 icon: 'loading',

 duration: 10000

})
setTimeout(function(){

 wx.hideToast()

},2000)

wx.showModal(OBJECT)

显示模态弹窗
wx.showModal({

 title: '提示',

 content: '这是一个模态弹窗',

 success: function(res) {

  if (res.confirm) {

   console.log('用户点击确定')

  }

 }

})
wx.showActionSheet({

 itemList: ['A', 'B', 'C'],

 success: function(res) {

  if (!res.cancel) {

   console.log(res.tapIndex)

  }

 }

})

wx.setNavigationBarTitle(OBJECT)

Dynamic setting title of the current page.

wx.setNavigationBarTitle({

 title: '当前页面'

})
wx.getSetting({
      success(res) {
        console.log(res)
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.openSetting({
            success(res) {
               //拒绝授权后重新提示授权,并授权成功
            }
          })
        }else{
          wx.saveImageToPhotosAlbum({
            filePath: 'imgs/home-icons/2019011709194.png',
            success(result) {
              //已授权过可直接执行保存图片
            }
          })
        }
      }
    })

image

wx.downloadFile({
  url: 'https://example.com/audio/123',     //仅为示例,并非真实的资源
  success: function (res) {
    // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
    if (res.statusCode === 200) {
      wx.saveImageToPhotosAlbum({
        filePath: res.tempFilePath,
        success(res) {
          wx.showToast({
            title: '保存图片成功!',
          })
        },
        fail(res) {
          wx.showToast({
            title: '保存图片失败!',
          })
        }
      })
    }
  }
})
wx.downloadFile({
  url: 'https://example.com/audio/123',     //仅为示例,并非真实的资源
  success: function (res) {
    // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
    if (res.statusCode === 200) {
      wx.saveImageToPhotosAlbum({
        filePath: res.tempFilePath,
        success(res) {
          wx.showToast({
            title: '保存图片成功!',
          })
        },
        fail(res) {
          wx.showToast({
            title: '保存图片失败!',
          })
        }
      })
    }
  }
})

Please thumbs up! Because your encouragement is the greatest power of my writing!

No public official micro letter

Blowing force exchange group: 711,613,774

Blowing force exchange group

Guess you like

Origin blog.csdn.net/qq_36232611/article/details/90684382