使用 downloadFile 下载文件后 打印出来为 http://tmp/wxc905e5658c5470e1.o6zAJs9pU3Ut44t0jhm3K5Y9Kbts.B5FlNeBypdvtcefe00852649dd7e1dd6f981089e06a4.xml 地址
使用 openDocument打开时 设置文件类型为fileType: 'xlsx' 无反应 可以打开文档
代码如下:
< view data-url = "https://aksoapplet.oss-cn-hangzhou.aliyuncs.com/excel/20190731/84c40a1d7e27466fa6d34f4168a14289" data-type = "excel" catchtap = 'downloadFile' > < button >get_</ button > </ view > |
js:
downloadFile: function (e) { console.log(e); let type = e.currentTarget.dataset.type; let url = e.currentTarget.dataset.url; switch (type) { case "pdf" : url += 'pdf' ; break ; case "word" : url += 'docx' ; break ; case "excel" : url += 'xlsx' ; break ; default : url += 'pptx' ; break ; } wx.downloadFile({ url: url, header: { "productCode" : 'wgs-wechat' , "content-type" : "application/x-www-form-urlencoded" }, success: function (res) { var filePath = res.tempFilePath; console.log(filePath); // var fileType = ""; // let dIndex = filePath.lastIndexOf("."); // fileType = filePath.substring(dIndex + 1, filePath.length); // console.log('aaa', fileType) // if (fileType == "xml") { // fileType = "xlsx" // } // console.log("fileType-->", fileType); //打开文件 console.log( '地址' , filePath) wx.openDocument({ filePath: filePath, fileType: 'xlsx' , success: function (res) { console.log( '打开文档成功' ) }, fail: function (res) { console.log(res); }, complete: function (res) { console.log(res); } }) }, fail: function (res) { console.log( '文件下载失败' ); }, complete: function (res) {}, }) } |
求教怎么下载并预览文件 后端返回的为一个execl的url地址 如何才能下载并且在线预览?