MtaPDF.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <view class="pdf-container" v-if="pdfUrl">
  3. <button @click="handleOpen">PDF预览</button>
  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" ></web-view>
  9. </view>
  10. </uni-popup>
  11. </template>
  12. <script setup>
  13. import {
  14. nextTick,
  15. ref
  16. } from "vue"
  17. const props = defineProps({
  18. pdfUrl: {
  19. type: String
  20. }
  21. })
  22. const showPdfUrl = ref(false)
  23. let pdfUrl1 = '';
  24. const popup = ref(null)
  25. function handleOpen() {
  26. popup.value.open('bottom')
  27. pdfUrl1 = `/hybrid/html/web/viewer.html?file=${encodeURIComponent(props.pdfUrl)}`;
  28. setTimeout(() => {
  29. showPdfUrl.value = true;
  30. }, 50)
  31. }
  32. function handleBack() {
  33. popup.value.close()
  34. showPdfUrl.value = false;
  35. }
  36. </script>
  37. <style lang="scss">
  38. .pdf-container {
  39. width: 100%;
  40. height: 200px; // 固定高度
  41. position: relative;
  42. overflow: hidden;
  43. border: 1px solid #eee;
  44. margin-top: 20px;
  45. }
  46. </style>