pdfPage.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <view>
  3. <web-view v-if="pdfUrl" :src="pdfUrl" @message="getPostMessage"></web-view>
  4. <ssDownload ref="ssRef"></ssDownload>
  5. </view>
  6. </template>
  7. <script setup>
  8. import {ref} from "vue"
  9. import {onLoad, onBackPress} from "@dcloudio/uni-app"
  10. import ssDownload from "./ssDownload.vue"
  11. import * as httpApi from "@/api/pdf.js"
  12. const pdfUrl = ref('');
  13. const httpUrl = ref('');
  14. const ssRef = ref(null)
  15. const banben1 =ref('');
  16. const nianji1 =ref('');
  17. function updatePdfUrl({banben,nianji}) {
  18. httpApi.getPDFUrl({
  19. banben,
  20. nianji,
  21. }).then(res => {
  22. httpUrl.value = res.data;
  23. pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(res.data);
  24. })
  25. }
  26. function getPostMessage() {
  27. // console.log('执行下载操作')
  28. ssRef.value.toDownload({
  29. type:2,
  30. src: httpUrl.value
  31. })
  32. }
  33. onBackPress((d) => {
  34. console.log('地址:',`/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`)
  35. uni.redirectTo({
  36. url: `/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`
  37. })
  38. return true
  39. })
  40. onLoad(({banben, nianji}) => {
  41. nianji1.value = nianji;
  42. banben1.value = banben;
  43. updatePdfUrl({banben, nianji});
  44. })
  45. </script>
  46. <style>
  47. </style>