PDFViewer.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <div style="width: 100%; height: 100%; position: relative;">
  3. <iframe v-if="type === 'pdf'" :src="src" width="100%" height="100%" style="position: relative;border: medium none;">
  4. </iframe>
  5. <div class="close-icon" @click=" emits('close')">
  6. <CloseOutlined />
  7. </div>
  8. </div>
  9. </template>
  10. <script setup>
  11. import { CloseOutlined, FullscreenOutlined } from '@ant-design/icons-vue';
  12. const emits = defineEmits(['close'])
  13. const props = defineProps({
  14. src: String,
  15. })
  16. const type = ref('pdf')
  17. watch(props.src, v => {
  18. if(v) {
  19. if(v.endsWith('.pdf')) {
  20. type.value = 'pdf'
  21. } else if(v.endsWith('.txt')) {
  22. type.value = 'txt'
  23. }
  24. }
  25. })
  26. const src = computed(() => {
  27. return `/lib/pdfjs/web/viewer.html?file=${props.src}&t=`+ new Date().getTime();
  28. // return `/lib/pdfjs/web/viewer.html?file=http://121.40.148.47:8530/doc/knowledge_base/download_doc/国土资源部 国家发展和改革委员会+财政部+住房和城乡建设部农业部+中国人民银行+国家林业局+中国银行业监督管理委员会关于扩大国有土地有偿使用范围的意见%28279-283%29.pdf`
  29. })
  30. </script>
  31. <style scoped lang="scss">
  32. .close-icon {
  33. position: absolute;
  34. top: 8px;
  35. right: 12px;
  36. cursor: pointer;
  37. }
  38. </style>