MtaPDF.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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" ></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. const emits = defineEmits(['showNav'])
  26. function handleOpen() {
  27. popup.value.open('bottom')
  28. pdfUrl1 = `/hybrid/html/web/viewer.html?file=${encodeURIComponent(props.pdfUrl)}`;
  29. setTimeout(() => {
  30. showPdfUrl.value = true;
  31. emits('showNav', false)
  32. }, 50)
  33. }
  34. function handleBack() {
  35. popup.value.close()
  36. showPdfUrl.value = false;
  37. emits('showNav', true)
  38. }
  39. </script>
  40. <style lang="scss">
  41. .pdf-container {
  42. width: 100%;
  43. height: 200px; // 固定高度
  44. position: relative;
  45. overflow: hidden;
  46. border: 1px solid #eee;
  47. margin-top: 20px;
  48. }
  49. </style>