微信小程序> 微信小程序文件预览源码(可以直接用)

微信小程序文件预览源码(可以直接用)

浏览量:774 时间: 来源:xiaoyanyanlh

微信小程序的文件预览

微信小程序的文件预览需要先使用wx.downloadFile下载文件,然后使用下载文件的临时路径通过wx.openDocument进行文件的预览

wxml代码:
button  bindtap='preview'简历预览/button
js代码:
 //简历预览  preview: function () {    var that = this;    console.log("简历预览")//这里的value是先在data里面初始化,然后我根据用户切换单选框,获取的简历文件的主键id    console.log(this.data.value)    var id = that.data.value;    if (id == "") {      wx.showModal({        title: '',        content: '请选择一份简历',        showCancel: false,        confirmColor: "#FFB100"      })    } else {      //先通过简历的主键id,查询简历路径(大家可以根据自己的需求来传数据)      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          })          //下载简历          wx.downloadFile({            url: app.globalData.url + that.data.path,            success: function (res) {              var filePath = res.tempFilePath              console.log(filePath)              //预览简历              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)            }          })        }      })    }  },

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

最新资讯

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎