pdfPage.vue 1.4 KB

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