当初开发这个功能时,网上一堆说苹果和安卓平台不一样,代码不一样,亲测一套代码安卓和苹果都可以打开预览,完全没问题,安卓也没有提示下载,改改传参直接用
wxml <web-view src="{{reportUrl}}" wx:if="{{reportShow}}"></web-view> <view wx:else></view> js const app = getApp() Page({ data: { reportUrl: null, reportShow: false }, onLoad: function (options) { wx.showLoading({ title: '报告加载中', }) var that = this var params = options.params; var id = options.pgxTestBasicId; that.setData({ reportUrl: params + '?pgxTestBasicId=' + id }) that.setData({ reportShow: false }) wx.downloadFile({ url: that.data.reportUrl, header: { "sessionKey": app.globalData.sessionKey }, success: function (res) { var Path = res.tempFilePath wx.openDocument({ filePath: Path, fileType: "pdf", success: function (res) { wx.hideLoading() } }) setTimeout(function () { wx.hideLoading() }, 2000) }, fail: function (res) { console.log(res); } }) }, onHide:function(){ wx.navigateBack({ delta: 1 }) } })