MtaPDF.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="pdf-container" v-if="pdfUrl">
  3. <view class="pdf-btn-box" @click="handleOpen"><icon></icon><text>pdf预览</text></view>
  4. </view>
  5. <uni-popup class="dljt-pdf-popup" ref="popup" type="bottom" background-color="#fff" :mask-click="false" :animation="false">
  6. <view class="pdf-popup-box">
  7. <uni-nav-bar class="pdf-return-btn" shadow left-icon="left" title="PDF预览" @clickLeft="handleBack" />
  8. <web-view class="dljt-pdf-view" :src="pdfUrl1" v-if="showPdfUrl" >
  9. </web-view>
  10. </view>
  11. </uni-popup>
  12. </template>
  13. <script setup>
  14. import {
  15. nextTick,
  16. ref,
  17. } from "vue"
  18. import {addClassToWebViewIframe}from "@/utils/common.js"
  19. const props = defineProps({
  20. pdfUrl: {
  21. type: String
  22. }
  23. })
  24. const showPdfUrl = ref(false)
  25. let pdfUrl1 = '';
  26. const popup = ref(null)
  27. const emits = defineEmits(['showNav'])
  28. function handleOpen() {
  29. popup.value.open('bottom')
  30. pdfUrl1 = `/hybrid/html/web/viewer.html?file=${encodeURIComponent(props.pdfUrl)}`;
  31. setTimeout(() => {
  32. showPdfUrl.value = true;
  33. emits('showNav', false)
  34. setTimeout(() => {
  35. addClassToWebViewIframe()
  36. },10)
  37. }, 50)
  38. }
  39. function handleBack() {
  40. popup.value.close()
  41. showPdfUrl.value = false;
  42. emits('showNav', true)
  43. }
  44. </script>
  45. <style lang="scss">
  46. .pdf-container {
  47. width: 100%;
  48. height: 200px; // 固定高度
  49. position: relative;
  50. overflow: hidden;
  51. border: 1px solid #eee;
  52. margin-top: 20px;
  53. }
  54. </style>