pdfPage.vue 834 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. const pdfUrl = ref('');
  12. const httpUrl = ref('');
  13. const ssRef = ref(null)
  14. function updatePdfUrl(url) {
  15. httpUrl.value = url;
  16. pdfUrl.value = '/hybrid/html/web/viewer.html?file=' + encodeURIComponent(url);
  17. }
  18. function getPostMessage() {
  19. // console.log('执行下载操作')
  20. ssRef.value.toDownload({
  21. type:2,
  22. src: httpUrl.value
  23. })
  24. }
  25. onLoad(({url}) => {
  26. const mockUrl = "https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf"
  27. updatePdfUrl(url||mockUrl);
  28. })
  29. </script>
  30. <style>
  31. </style>