pdfPage.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. uni.downloadFile({
  31. url: httpUrl.value,
  32. success: function (res) {
  33. var filePath = res.tempFilePath;
  34. uni.openDocument({
  35. filePath: filePath,
  36. showMenu: true,
  37. success: function (res) {
  38. console.log('打开文档成功');
  39. }
  40. });
  41. }
  42. });
  43. /*ssRef.value.toDownload({
  44. type:2,
  45. src: httpUrl.value,
  46. })*/
  47. }
  48. function getPostMessage() {
  49. console.log('执行下载操作')
  50. ssRef.value.toDownload({
  51. type:2,
  52. src: httpUrl.value,
  53. })
  54. }
  55. onBackPress((d) => {
  56. console.log('地址:',`/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`)
  57. uni.redirectTo({
  58. url: `/pages/my/sxtkPage?banben=${banben1.value}&nianji=${nianji1.value}`
  59. })
  60. return true
  61. })
  62. onLoad(({banben, nianji}) => {
  63. nianji1.value = nianji;
  64. banben1.value = banben;
  65. updatePdfUrl({banben, nianji});
  66. })
  67. </script>
  68. <style>
  69. </style>