if(fileType==='txt'){
wx.navigateTo({
url: `/packageBeforeClass/pages/txtView/txtView?fileName=${fileName}&fileType=${fileType}&url=${url}`,
}); //如果是txt文件,跳转到txtTextView 页
// txtTextView 页
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
wx.setNavigationBarTitle({
title: `${options.fileName}.${options.fileType}`
});
let fs = wx.getFileSystemManager();
const that=this;
let downloadTask = wx.downloadFile({
url: options.url,
filePath: `${wx.env.USER_DATA_PATH}/${options.fileName}.${options.fileType}`,
success: function () {
wx.hideLoading();
fs.readFile({
filePath: `${wx.env.USER_DATA_PATH}/${options.fileName}.${options.fileType}`,
encoding:'utf8',
complete(res){
that.setData({
txtTextView:res.data //在wxml做展示
});
}
})
},
fail: function(error) {
wx.hideLoading();
wx.showToast({
title: error.errMsg,
icon: "none"
});
}
});
},
文章评论