<!-- 文件预览组件 --> <script lang="ts" setup name="FilePreview"> import VuePdfEmbed from 'vue-pdf-embed' import * as pdfjsLib from 'pdfjs-dist' import { getBase64, getObjectURL } from '@/utils/download' // import { getPhotoUrl } from '@/api/file' import { printPage } from '@/api/eqpt/MeasurementBusiness/review' // 打印文件url const props = defineProps({ id: { type: String, require: true, }, }) const pdfUrl = ref('') /** * 初始化审批弹窗 * @param printFileName 文件名 */ function init() { printPage({ id: props.id, pdf: true }).then((res) => { const base64 = getBase64(res.data).then((res) => { pdfUrl.value = res }) // pdfUrl.value = // console.log(`${import.meta.env.VITE_APP_API_BASEURL}/${res.data}`) pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdf.worker.js' }) } onMounted(() => { init() }) </script> <template> <!-- pdf预览 --> <div style="margin: 0 auto;"> <vue-pdf-embed id="print-page" ref="pdf" :source="pdfUrl" class="vue-pdf-embed" /> </div> </template> <style lang="scss" scoped> // 样式 </style>