<template>
  <el-empty v-if="isError" description="加载中..." class="h-100vh"></el-empty>
  <div class="w-100%">
    <VuePdfEmbed :source="preview.url" class="w-full" @loaded="handlePdfLoaded" @error="handlePdfError" />
  </div>
</template>

<script lang="ts" setup>
  import { ref } from 'vue'
  import VuePdfEmbed from 'vue-pdf-embed'

  const isError = ref(true)
  const url = new URL(window.location.href)
  const preview = {
    url: url.searchParams.get('url') || '',
  }

  // PDF加载成功回调
  const handlePdfLoaded = (pdfInfo: any) => {
    isError.value = false
    console.log('PDF页数:', pdfInfo.numPages)
    // 可在此处添加自定义逻辑
  }

  // PDF加载失败回调
  const handlePdfError = (error: Error) => {
    // isError.value = false
    console.error('PDF加载失败:', error)
    // 可在此处添加错误处理逻辑
  }
</script>

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