ofd后缀的文件预览,路径预览,上传预览,下载预览

npm install ty-ofd.js

<template>
  <div>
    <input
      ref="file"
      type="file"
      class="hidden"
      accept=".ofd"
      @change="fileChanged"
    >
    <div id="content" class="content_wrap">
      <div class="seal_img_div" />
    </div>
  </div>

</template>

<script>
import { parseOfdDocument, renderOfd } from 'ty-ofd.js'
export default {
  props: {
    fileurl: {
      type: String,
      default:
        'http://192.168.0.115:9527/train.ofd'
    },
    screenWidth: {
      type: Number,
      default: 600
    }
  },
  data() {
    return {}
  },
  watch: {},
  mounted() {
    // 直接预览ofd文件
    this.renderOfdFile(this.fileurl)
  },
  methods: {
    /**
     * 选择文件上传
     */
    fileChanged() {
      const file = this.$refs.file.files[0]
      this.renderOfdFile(file)
    },
    /**
     * ofd格式文件渲染
     */
    renderOfdFile(file) {
      const that = this
      parseOfdDocument({
        ofd: file, // file 可以为文件链接、上传的文件对象
        success(res) {
          // 输出ofd每页的div
          const divs = renderOfd(that.screenWidth, res[0])
          const contentDiv = document.getElementById('content')
          contentDiv.innerHTML = ''
          for (const div of divs) {
            contentDiv.appendChild(div)
          }
          for (const ele of document.getElementsByName('seal_img_div')) {
            this.addEventOnSealDiv(
              ele,
              JSON.parse(ele.dataset.sesSignature),
              JSON.parse(ele.dataset.signedInfo)
            )
          }
        },
        fail(error) {
          console.log(error)
        }
      })
    }
  }
}
</script>

<style scoped lang="scss"></style>
<div v-if="isOFD === true" id="ofdveri" />
renderOfdFile(file) {
      const that = this
      parseOfdDocument({
        ofd: file, // file 可以为文件链接、上传的文件对象
        success(res) {
          // 输出ofd每页的div
          const divs = renderOfd(that.screenWidth, res[0])
          const contentDiv = document.getElementById('ofdveri')
          contentDiv.innerHTML = ''
          for (const div of divs) {
            contentDiv.appendChild(div)
          }
        },
        fail(error) {
          console.log(error)
        }
      })
    },
imgshow(){
              downloadFileByUniq(
                encodeURIComponent(data.name)
              ).then(res => {
                const file = new File([res], data.name)
                this.isOFD = true
                this.renderOfdFile(file)
              }).finally(() => {
                this.imgLoading = false
              })
        } 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值