fileView.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <template>
  2. <view class="container">
  3. <!-- <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">检测报告</block>
  6. </cu-custom> -->
  7. <web-view :src="pdfUrl"></web-view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {
  14. pdfUrl:'',
  15. from:'app'
  16. }
  17. },
  18. onLoad(option) {
  19. console.log("接收参数")
  20. console.log(option)
  21. /**
  22. * 浏览情景
  23. */
  24. // 浏览情景1:浏览本地的pdf文件
  25. //this.pdfUrl = '/hybrid/html/web/viewer.html?file=./compressed.tracemonkey-pldi-09.pdf'
  26. // 浏览情景2:浏览在线的pdf文件
  27. this.pdfUrl = '/hybrid/html/web/viewer.html?file='+encodeURIComponent("https://www.szjyxt.com/group1/M00/00/0C/rBKdLGHuElCAVpUEAAY6VxViWJE056.pdf")
  28. },
  29. methods: {
  30. /**
  31. * 下载情景
  32. */
  33. downloadPdfClick(){
  34. // 下载情景1:h5内嵌app,通过分享给朋友的方式进行下载
  35. if(this.from == 'app'){
  36. let item = 'https://www.szjyxt.com/h5/hybrid/html/web/pdf.html?shareUrl='+encodeURIComponent(this.bgUrl)
  37. +'&shareTitle=PDF文件';
  38. window.open(item);
  39. return;
  40. }else if(this.from == 'wx wq'){
  41. // 下载情景2:h5内嵌微信小程序,从h5页面跳转到小程序页面后,然后通过调用小程序原生API进行下载
  42. // 注意: 先要引入微信jssdk [命令: npm install jweixin-module]
  43. // this.$wx.miniProgram.navigateTo({
  44. // url: '/pages/pdf/pdf_download?pdf='+ encodeURIComponent(this.bgUrl) //小程序页面链接
  45. // });
  46. }
  47. }
  48. }
  49. }
  50. </script>
  51. <style>
  52. </style>