zhangherong
2025-03-28 85cbb9a62a4f3a6b3c0cd241976c351eb0d7ed9b
src/components/jeecg/LxFilePreview.vue
@@ -9,10 +9,10 @@
    :footer="null"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <img v-if="isImage" :src="fileUrl" width="100%" height="100%" alt="图片预览" />
      <iframe v-else-if="isPdf" :src="fileUrl" width="100%" height="600px"></iframe>
      <img v-if="isImage" :src="localFileUrl" width="100%" height="100%" alt="图片预览" />
      <iframe v-else-if="isPdf" :src="localFileUrl" width="100%" height="600px"></iframe>
      <video v-else-if="isVideo" controls>
        <source :src="fileUrl" type="video/mp4">
        <source :src="localFileUrl" type="video/mp4">
        您的浏览器不支持 video 标签。
      </video>
      <pre v-else-if="isText">{{ textContent }}</pre>
@@ -33,25 +33,26 @@
      title: '预览',
      textContent: '',
      confirmLoading: false,
      visible: false
      visible: false,
      localFileUrl: this.fileUrl,
    }
  },
  computed: {
    isImage() {
      return /\.(jpeg|jpg|png|gif|bmp|webp)$/i.test(this.fileUrl)
      return /\.(jpeg|jpg|png|gif|bmp|webp)$/i.test(this.localFileUrl)
    },
    isPdf() {
      return /\.pdf$/i.test(this.fileUrl)
      return /\.pdf$/i.test(this.localFileUrl)
    },
    isVideo() {
      return /\.(mp4|webm|ogg)$/i.test(this.fileUrl)
      return /\.(mp4|webm|ogg)$/i.test(this.localFileUrl)
    },
    isText() {
      return /\.(txt|md|json|xml|yaml|yml)$/i.test(this.fileUrl)
      return /\.(txt|md|json|xml|yaml|yml)$/i.test(this.localFileUrl)
    }
  },
  watch: {
    fileUrl: 'fetchTextContent'
    localFileUrl: 'fetchTextContent'
  },
  mounted() {
    if (this.isText) {
@@ -77,7 +78,7 @@
    preview(fileUrl) {
      let url = getFileAccessHttpUrl(fileUrl)
      this.visible = true
      this.fileUrl = url
      this.localFileUrl = url
    },
    handleOk() {
      this.close()