const util = require("../../utils/util");
Page({
/**
* 页面的初始数据
*/
data: {
fileUrl: '',
url: '',
reportShow: false
},
//tab切换
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
//接收上个页面传递过来的url参数
console.log('data', options);
this.setData({
url: encodeURIComponent(options.fileUrl), //pdf链接
})
wx.showLoading({
title: '文档加载中',
})
var that = this
var url = options.url;
that.setData({
reportUrl: url,
reportShow: false
})
调用微信小程序自带api下载到本地
wx.downloadFile({
url: options.fileUrl,
success: function (res) {
var Path = res.tempFilePath
wx.openDocument({
filePath: encodeURI(Path),
fileType: "pdf",
success: function (res) {
wx.hideLoading()
}
})
setTimeout(function () {
wx.hideLoading()
}, 1000)
},
fail: function (res) {
console.log(res);
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
// this.infoLists()
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})
微信小程序浏览PDF
于 2022-07-18 15:35:10 首次发布