pdfPage.vue 885 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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} 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. function updatePdfUrl({banben,nianji}) {
  16. httpApi.getPDFUrl({
  17. banben,
  18. nianji,
  19. }).then(url => {
  20. httpUrl.value = url;
  21. pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url);
  22. })
  23. }
  24. function getPostMessage() {
  25. // console.log('执行下载操作')
  26. ssRef.value.toDownload({
  27. type:2,
  28. src: httpUrl.value
  29. })
  30. }
  31. onLoad(({banben, nianji}) => {
  32. updatePdfUrl({banben, nianji});
  33. })
  34. </script>
  35. <style>
  36. </style>