<!-- 文件预览组件(通过文件名获取文件url) -->
<script lang="ts" setup name="WordOreview">
import VueOfficeExcel from '@vue-office/excel'
import '@vue-office/excel/lib/index.css'
import { ElLoading } from 'element-plus'
import { getPhotoUrl } from '@/api/file'
// 打印文件url
const props = defineProps({
  printFileName: {
    type: String,
  },
})
const wordUrl = ref('')

/**
 * 初始化
 */
function init() {
  const loading = ElLoading.service({
    lock: true,
    text: '加载中...',
    background: 'rgba(255, 255, 255, 0.6)',
  })
  getPhotoUrl(props.printFileName!).then((res: any) => {
    console.log('文件名称', props.printFileName)
    wordUrl.value = res.data
    console.log('wordUrl', wordUrl.value)
    loading.close()
  })
}

watch(() => props.printFileName, (newVal) => {
  // console.log('newVal', newVal)

  if (newVal) {
    // init()
    wordUrl.value = newVal
  }
}, { immediate: true })
const rendered = () => {
  console.log('渲染完成')
}
const errorHandler = () => {
  console.log('渲染失败')
}
onMounted(() => {
  // init()
})
</script>

<template>
  <vue-office-excel src="http://static.shanhuxueyuan.com/demo/excel.xlsx" style="width: 300px;height: 600px;" @rendered="rendered" @error="errorHandler" />
</template>

<style lang="scss">
// 样式
.docx-wrapper {
  background: transparent !important;
}
</style>
