网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

微信小程序下載預覽PDF

發布時間:2021-06-23 14:26 所屬欄目:小程序開發教程

微信小程序的文件預覽需要先使用wx.downloadFile下載文件,然后使用下載文件的臨時路徑通過wx.openDocument進行文件的預覽

項目中,有的需要打開pdf 來閱讀信息。就需要用小程序自帶的api方法。

wxml代碼:


<button  bindtap='preview'>PDF文件預覽</button>

js代碼:

//PDF預覽
  preview: function () {
    var that = this;
    console.log("PDF預覽")
     
//這里的value是先在data里面初始化,然后我根據用戶切換單選框,獲取的PDF文件的主鍵id
    console.log(this.data.value)
    var id = that.data.value;
 
    if (id == "") {
      wx.showModal({
        title: '',
        content: '請選擇一份PDF',
        showCancel: false,
        confirmColor: "#FFB100"
      })
    } else {
 
      //先通過PDF的主鍵id,查詢PDF路徑(大家可以根據自己的需求來傳數據)
      wx.request({
        url: app.globalData.url + "/api/interview/queryFilePath",
        data: {
          id: id
        },
        method: 'POST',
        header: { "content-type": "application/x-www-form-urlencoded" },
        success: function (res) {
          console.log(res.data)
          that.setData({
            path: res.data.path,
            type: res.data.type
          })
          //下載PDF
          wx.downloadFile({
            url: app.globalData.url + that.data.path,
            success: function (res) {
              var filePath = res.tempFilePath
              console.log(filePath)
 
              //預覽PDF
              wx.openDocument({
                filePath: filePath,
                fileType: that.data.type,
                success: function (res) {
                  console.log("打開文檔成功")
                  console.log(res);
                },
                fail: function (res) {
                  console.log("fail");
                  console.log(res)
                },
                complete: function (res) {
                  console.log("complete");
                  console.log(res)
                }
              })
            },
            fail: function (res) {
              console.log('fail')
              console.log(res)
            },
            complete: function (res) {
              console.log('complete')
              console.log(res)
            }
          })
        }
      })
    }
  },


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/26700.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×