Newer
Older
xc-metering-front / src / views / tested / MeasurementBusiness / detection / components / pdfFile.vue
lyg on 8 Mar 2024 965 bytes 需求修改
<!-- 文件预览组件 -->
<script lang="ts" setup name="FilePreview">
import VuePdfEmbed from 'vue-pdf-embed'
// import * as pdfjsLib from 'pdfjs-dist'
import { ElLoading } from 'element-plus'
import { getBase64, getObjectURL } from '@/utils/download'
const emit = defineEmits(['getFile'])

const pdfUrl = ref('')

/**
 * 初始化
 */
function init() {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  emit('getFile', (res: any) => {
    if (res) {
      getBase64(res.data).then((res) => {
        pdfUrl.value = res as string
      })
      // pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.js'
      loading.close()
    }
    else {
      loading.close()
    }
  })
}

onMounted(() => {
  init()
})
</script>

<template>
  <!-- pdf预览 -->
  <vue-pdf-embed ref="pdf" :source="pdfUrl" class="vue-pdf-embed" />
</template>

<style lang="scss" scoped>
// 样式
</style>