各种格式文件预览

 pdf文件

<embed:src="文件的地址" style="position:absolute; left: 0; top: 0;" width="100%" height="100%" type="application/pdf">

图片

<img :src="文件的地址" style="width: 100%;height: 100%;object-fit: contain;display: block;-webkit-user-select: none;margin: auto;background-color: hsl(0, 0%, 90%);" :οnlοad="加载成功返回">

txt

// 这属于一个通用的预览方式,可以预览多种格式的文件

 <iframe :src="文件的地址" width='100%' height='100%' frameborder='1' ></iframe>

 docx(安装 vue-office/docx)docx文件预览 | vue-office

<vue-office-docx :src="文件的地址" style="width: 100%;height: 100%;" @rendered="加载成功返回" />

 xlsx(安装 vue-office/xlsx)xlsx文件预览 | vue-office

 <vue-office-excel :src="文件的地址" style="width: 100%;height: 100%;" @rendered="加载成功返回" />

 视频 安装-ckplayer

// 调用

<shipinyulan :videoPath="文件的地址" @ReturnData="ReturnData" /> 

<!--
 * @Description: 视频预览文件
-->
<template>
  <div class="playerContainer" ref="playerContainer"></div>
</template>
<script>
import { onMounted, onUnmounted, ref, watch } from 'vue'

export default {
  props: {
    videoPath: {
      type: String,
      required: true
    }
  },
  setup (props, ctx) {
    const playerContainer = ref(null)
    let playerInstance = null

    onMounted(() => {
      initPlayer()
    })

    watch(
      () => props.videoPath, () => {
        // 当路径变化时重新播放新视频
        playerInstance && initPlayer()
      }
    )
    onUnmounted(() => {
      // 销毁播放器实例
      playerInstance && playerInstance.remove()
    })

    const initPlayer = () => {
      // 创建CKPlayer实例
      playerInstance = new ckplayer({
        container: playerContainer.value,
        autoplay: true, // 是否自动播放
        video: props.videoPath
      })
      playerInstance.duration(function (t) {
        // t=当前视频总时间
        console.log('当前视频总时间-----')
        console.log(t)
        ctx.emit('ReturnData', t)
      })
      playerInstance.time(function (t) {
        // t=当前播放时间
        console.log('当前播放时间-----')
        console.log(t)
        ctx.emit('ReturnData', t)
      })
      playerInstance.ended(function () {
        // 视频播放已结束
        console.log('视频播放已结束')
        ctx.emit('ReturnData', false)
      })
      playerInstance.error(function (obj) {
        // 监听到错误,obj=错误内容
        console.log('监听到错误-----')
        console.log(obj)
        ctx.emit('ReturnData', obj)
      })
    }

    return {
      playerContainer
    }
  }
}
</script>
<style scoped>
.card-header {
  text-align: center;
  border-bottom: 2px dotted #c5c5c5;
}
  .playerContainer {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }
</style>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值