【Vue】word / excel / ppt / pdf / 视频(mp4,mov) 预览

文件预览

    • Vue3
    • 一. word
    • 二. excel
    • 三. ppt
    • 四. pdf
      • 4.1 vue-pdf-embed
      • 4.2 iframe
    • 五. 视频
    • 六:扩展——kkFileView

Vue3

一. word

  1. 安装:npm install docx-preview
  2. 父页面
<template><div><DocPreviewv-if="filePath.includes('docx')":doc-url="filePath"/></div>
</template>
<script setup>
import DocPreview from '@/components/DocPreview'
const filePath = ref('https://xxxxxxxxxxxx.docx') 
</script>
  1. 组件
    路径:@/components/DocPreview
<!-- word 文档阅读 -->
<template><div><div v-if="message" class="doc-empty">{{ message }}</div><div v-else class="doc-render-wraper"><div ref="fileRef"><div ref="fileStyleRef"></div></div></div></div>
</template><script setup>
import axios from 'axios'
// const docx = require('docx-preview')
import { renderAsync } from 'docx-preview'const props = defineProps({// 文档地址docUrl: {type: String,default: ''}
})const service = axios.create({baseURL: props.docUrl,timeout: 600000
})
const fileRef = ref(null)
const fileStyleRef = ref(null)
const message = ref('')
// 预览
const init = async () => {const { data } = await service({method: 'get',responseType: 'blob'})// console.log(data)if (data.size === 0) {message.value = '当前文档内容为空,无可阅读内容'} else {message.value = ''renderAsync(data, fileRef.value, fileStyleRef.value)}
}watch(() => props.docUrl,newVal => {if (newVal !== null && newVal !== '') {init()}}
)init()
</script>
<style lang="scss" scoped>
.doc-render-wraper {width: 840px;padding-top: 10px;margin: 0 auto;overflow-x: auto;// fileStyleRef css> div {border: 1px solid #e6edf5;}
}
.doc-empty {display: flex;align-items: center;justify-content: center;font-size: 14px;color: #0f5c9f;background-color: #e6edf5;width: 100%;height: 50px;
}
</style>

二. excel

在这里插入图片描述

  1. 安装:npm install @vue-office/excel
  2. 父页面
<template><div><XlsxPreview :xlsx-url="filePath" /></div>
</template>
<script setup>
import XlsxPreview from '@/components/XlsxPreview'
</script>
  1. 组件
<!-- excel 文档阅读 -->
<template><div class="xlsx-preview"><vue-office-excel :src="source" class="vue-office-excel" /></div>
</template>
<script setup>
// 引入VueOfficeExcel组件
import VueOfficeExcel from '@vue-office/excel'
// 引入相关样式
import '@vue-office/excel/lib/index.css'
const props = defineProps({// 文档地址xlsxUrl: {type: String,default: ''}
})
const source = ref(props.xlsxUrl)
</script>
<style lang="scss" scoped>
.xlsx-preview {width: 840px;height: 100%;padding: 20px 0;margin: 0 auto;box-sizing: border-box;
}
.vue-office-excel {width: 100%;height: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}
</style>

三. ppt

  1. 官网:https://github.com/meshesha/PPTXjs
    demo:https://pptx.js.org/pages/demos.html
  2. 注意:先引入pptjs
    在这里插入图片描述
    在这里插入图片描述
  3. 父文件
<template><div><PptxPreview :pptx-url="filePath" /></div>
</template>
<script setup>
import PptxPreview from '@/components/PptxPreview/index.vue'
const filePath = ref("")</script>
  1. 组件
<!-- pptx 文档阅读 -->
<template><div class="xlsx-preview"><div class="page-tool"><div class="page-tool-item" @click="pageZoomOut">放大</div><div class="page-tool-item" @click="pageZoomIn">缩小</div></div><!-- <div style="display: grid; place-content: center; color: darkgrey">pptx文件暂时无法预览~~~</div> --><div style="height: 1200px; width: 90%; zoom: 0.5; overflow-y: auto; overflow-x: auto; margin: 0 30px"><divid="your_div_id_result"style="position: relative":style="`transform:scale(${size});transform-origin:0% 0%`"></div></div></div>
</template>
<script setup>
const props = defineProps({// 文档地址pptxUrl: {type: String,default: ''}
})
const size = ref(1)
function init(newVal) {$('#your_div_id_result').pptxToHtml({pptxFileUrl: newVal,slidesScale: '50%'})
}
onBeforeUnmount(() => {$('#your_div_id_result').empty()
})
const pageZoomOut = () => {if (size.value < 3) {size.value += 0.1}
}
const pageZoomIn = () => {if (size.value > 0.8) {size.value -= 0.1}
}
watch(() => props.pptxUrl,newVal => {if (newVal) {setTimeout(() => {init(newVal)}, 1000)}},{ immediate: true }
)
</script>
<style lang="scss" scoped>
// import './css/pptxjs.css' import './css/nv.d3.min.css'
.xlsx-preview {width: 840px;height: 100%;// margin-left: 80px;padding: 20px 0;// margin: 0 auto;box-sizing: border-box;
}
.vue-office-excel {width: 100%;height: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}.page-tool {display: flex;align-items: center;justify-content: center;margin-left: 50px;margin-bottom: 20px;padding: 8px 0;// width: 400px;width: 80%;text-align: center;background: #e6edf5;color: #0f5c9f;border-radius: 19px;cursor: pointer;
}.page-tool-item {padding: 0 15px;padding-left: 10px;cursor: pointer;
}
</style>
  1. 缺陷
    (1)不支持上传jpg格式的图片:若ppt中含有jpg格式的图片,报错
    (2)支持仅pptx文件格式

四. pdf

4.1 vue-pdf-embed

功能:放大、缩小、跳转到某页
在这里插入图片描述

  1. 安装: npm install vue-pdf-embed
  2. 父页面
<template><div><PdfPreview :key="fileIndex" :pdf-url="filePath" /></div>
<template>
<script setup>
const fileIndex = ref(0)
const filePath = ref(https://xxxxxxxxxxxxxxx.pdf)</script>
  1. 组件
<template><div class="pdf-preview"><div v-if="props.pdfUrl.indexOf('undefined') == -1" v-loading="pdfLoading"><div class="page-tool"><div class="page-tool-item" @click="lastPage">上一页</div><div class="page-tool-item" @click="nextPage">下一页</div><div class="page-tool-item">{{ state.pageNum }}/{{ state.numPages }}</div><div class="page-tool-item" @click="pageZoomOut">放大</div><div class="page-tool-item" @click="pageZoomIn">缩小</div><div class="page-tool-item">前往</div><el-input v-model.number="currentPage" style="width: 100px" @input="goToPage(currentPage)" /></div><div class="pdf-wrap"><vue-pdf-embedref="pdfRef":source="{cMapUrl: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.6.347/cmaps/',url: state.source,cMapPacked: true}"class="vue-pdf-embed":style="`transform:scale(${state.scale});transform-origin:0% 0%`":page="state.pageNum"@loading-failed="pdfLoading = false"@rendered="handleDocumentRender"/></div></div></div>
</template>
<script setup>
import { defineAsyncComponent } from 'vue'
const { proxy } = getCurrentInstance()
const VuePdfEmbed = defineAsyncComponent(() => import('vue-pdf-embed'))
const props = defineProps({pdfUrl: {type: String,required: true,default: ''}
})
const pdfLoading = ref(true)
const currentPage = ref(1)
const state = reactive({source: props.pdfUrl, // 预览pdf文件地址pageNum: 1, // 当前页面scale: 1, // 缩放比例numPages: 0 // 总页数
})// 加载完成
const handleDocumentRender = () => {pdfLoading.value = falsestate.numPages = proxy.$refs.pdfRef.pageCount
}
const lastPage = () => {if (state.pageNum > 1) {state.pageNum -= 1currentPage.value = state.pageNum}
}const nextPage = () => {if (state.pageNum < state.numPages) {state.pageNum += 1currentPage.value = state.pageNum}
}
const pageZoomOut = () => {if (state.scale < 3) {state.scale += 0.1}
}
const pageZoomIn = () => {if (state.scale > 0.8) {state.scale -= 0.1}
}const goToPage = page => {if (page >= 1 && page <= state.numPages) {currentPage.value = pagestate.pageNum = page}
}
</script>
<style lang="scss" scoped>
.pdf-preview {//   position: relative;width: 840px;// height: 1250px;padding: 10px 0;margin: 0 auto;box-sizing: border-box;
}
.pdf-wrap {overflow-y: auto;
}
.vue-pdf-embed {text-align: center;width: 100%;border: 1px solid #e5e5e5;margin: 0 auto;box-sizing: border-box;
}.page-tool {display: flex;align-items: center;justify-content: center;margin: 10px auto;// width: 400px;width: 80%;text-align: center;background: #e6edf5;color: #0f5c9f;border-radius: 19px;cursor: pointer;
}.page-tool-item {padding: 0 15px;padding-left: 10px;cursor: pointer;
}
</style>

4.2 iframe

<template><div><iframe type="application/pdf" :src="filePath"width="800" height="1000"></iframe></div>
<template>
<script setup>
const filePath = ref("")
<script>

五. 视频

在这里插入图片描述

  1. 支持格式:.mov,.mp4
  2. 父文件
<template><div><VideoPreviewv-if="subfix == 'mp4' || 'mov')":url="videoUrl":isExport="isExport"/></div>
</template setup>
<script>
import VideoPreview from '@/components/VideoPreview'
const subfix = ref('mp4') // 视频文件后缀
const videoUrl = ref('')
const isExport = ref(true)
</script>
  1. 组件
<template><div v-if="filePath" style="overflow-x: auto"><videooncontextmenu="return false;":src="filePath":style="`width: ${widths}% `"class="w-[218px] h-[140px] rounded-[4px] bg-second video"controlsautoplaydisablePictureInPicture:controlsList="isDownload ? 'noremoteplayback noplaybackrate' : 'noremoteplayback noplaybackrate nodownload'"><source /></video></div>
</template>
<script setup>
import dragWidthStore from '@/views/satisfiedEngineering/evaluationProcedure/store/dragWidth'
const widths = computed(() => dragWidthStore().width)
const filePath = ref('')
const isDownload = ref(false) // 是否给控件赋予下载权限
const props = defineProps({url: {type: String,default: ''},isExport: {type: Boolean,default: true,require: false}
})watch(() => props.url,newValue => {filePath.value = newValue},{ deep: true, immediate: true }
)watch(() => props.isExport,newValue => {isDownload.value = newValue},{ deep: true, immediate: true }
)
</script>

六:扩展——kkFileView

项目中没涉及到,大致记录一下

  1. 官网:https://kkfileview.keking.cn/kkFileView-4.1.0-docker.tar

  2. 支持格式
    在这里插入图片描述

  3. 组件

<!-- 文件预览支持 doc, docx, xls, xlsx, xlsm, ppt, pptx, csv, tsv, dotm, xlt, xltm, dot, dotx, xlam, xla, pages 等 Office 办公文档支持 wps, dps, et, ett, wpt 等国产 WPS Office 办公文档支持 odt, ods, ots, odp, otp, six, ott, fodt, fods 等OpenOffice、LibreOffice 办公文档支持 vsd, vsdx 等 Visio 流程图文件支持 wmf, emf 等 Windows 系统图像文件支持 psd, eps 等 Photoshop 软件模型文件支持 pdf ,ofd, rtf 等文档支持 xmind 软件模型文件支持 bpmn 工作流文件支持 eml 邮件文件支持 epub 图书文档支持 obj, 3ds, stl, ply, gltf, glb, off, 3dm, fbx, dae, wrl, 3mf, ifc, brep, step, iges, fcstd, bim 等 3D 模型文件支持 dwg, dxf, dwf, iges , igs, dwt, dng, ifc, dwfx, stl, cf2, plt 等 CAD 模型文件支持 txt, xml(渲染), md(渲染), java, php, py, js, css 等所有纯文本支持 zip, rar, jar, tar, gzip, 7z 等压缩包支持 jpg, jpeg, png, gif, bmp, ico, jfif, webp 等图片预览(翻转,缩放,镜像)支持 tif, tiff 图信息模型文件支持 tga 图像格式文件支持 svg 矢量图像格式文件支持 mp3,wav,mp4,flv 等音视频格式文件支持 avi,mov,rm,webm,ts,rm,mkv,mpeg,ogg,mpg,rmvb,wmv,3gp,ts,swf 等视频格式转码预览支持 dcm 等医疗数位影像预览支持 drawio 绘图预览Docker环境部署:网络环境方便访问docker中央仓库docker pull keking/kkfileview:4.1.0网络环境不方便访问docker中央仓库wget https://kkfileview.keking.cn/kkFileView-4.1.0-docker.tardocker load -i kkFileView-4.1.0-docker.tar -->
<template><div><iframe:src="`${containerUrl}/onlinePreview?url=` + encodeURIComponent(Base64.encode(fileUrl))"frameborder="0"class="fileView"></iframe></div>
</template><script setup>
import { Base64 } from 'js-base64'const props = defineProps({// 浏览器访问容器地址containerUrl: {type: String,default: ''},// 文档地址fileUrl: {type: String,default: ''}
})
</script>
<style lang="scss" scoped>
.fileView {width: 800px;height: 1020px;border-width: 1px;
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/58144.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

react 总结+复习+应用加深

文章目录 一、React生命周期1. 挂载阶段&#xff08;Mounting&#xff09;补充2. 更新阶段&#xff08;Updating&#xff09;补充 static getDerivedStateFromProps 更新阶段应用补充 getSnapshotBeforeUpdate3. 卸载阶段&#xff08;Unmounting&#xff09; 二、React组件间的…

基于.NET 8.0,C#中Microsoft.Office.Interop.Excel来操作office365的excel

开发环境&#xff1a; Visual Studio 2022 office365 项目模板&#xff1a;WPF应用程序 框架&#xff1a;.NET 8.0 依赖&#xff1a;Microsoft.Office.Interop.Excel 注意&#xff1a; 1.使用Microsoft.Office.Interop.Excel库时&#xff0c;服务器或电脑里面必须安装得…

NLP--一起学习Word Vector【实践】

纸上得来终觉浅&#xff0c;绝知此事要躬行。 《冬夜读书示子聿》 值此1024的程序员节&#xff0c;我们一起学习 Word Vector。 本章一起学习文本向量化&#xff0c;掌握文本向量的相关概念&#xff0c;了解各个文本向量&#xff0c;实现文本向量的算法 我开启了一个NLP共学坊…

Pytest 插件的种类

引言 Pytest是一个功能强大且扩展性强的测试框架&#xff0c;支持丰富的插件体系。通过插件&#xff0c;Pytest的功能可以得到极大扩展&#xff0c;满足各种测试需求。本文将介绍几类常用的Pytest插件&#xff0c;并简要说明其功能和使用场景。 Pytest 插件的分类 报告和输出…

代码+编译环境一并保存Git仓库,Jenkins使用docker编译

大家好&#xff0c;欢迎来到停止重构的频道。 上期介绍了Jenkins的基本用法&#xff0c;本期补充介绍Jenkins使用docker进行软件编译。 如果对docker不太熟悉&#xff0c;可以先翻看往期《docker详解》。 我们按这样的顺序展开讨论&#xff1a; 1、为什么使用docker编译软件…

网址访问小工具(模拟浏览器)

网址访问小工具&#xff08;模拟浏览器&#xff09; 文章说明核心代码运行截图源码下载 文章说明 本篇文章主要是我写的一个小demo&#xff0c;感觉效果还蛮不错的&#xff0c;作为一个记录新想法的实现思路&#xff1b;介绍了模拟浏览器页面的一些页面实现的小细节。 采用vue3…

文理学院数据库应用技术实验报告0

文理学院数据库应用技术实验报告0 实验内容 打开cmd,利用MySQL命令连接MySQL服务器。 mysql -u root -p查看当前MySQL服务实例使用的字符集(character)。 SHOW VARIABLES LIKE character_set_server;查看当前MySQL服务实例支持的字符序(collation)。 SHOW VARIABLES LIKE c…

ReactOS系统中平衡二叉树按从左到右的顺序找到下一个结点

ReactOS系统中平衡二叉树按从左到右的顺序找到下一个结点MmIterateNextNode()按从左到右的顺序找到下一个结点 文章目录 ReactOS系统中平衡二叉树按从左到右的顺序找到下一个结点MmIterateNextNode()按从左到右的顺序找到下一个结点MmIterateNextNode() MmIterateNextNode() /*…

解锁知识潜力:十款企业培训知识库全面解析

在当今这个快速变化的时代&#xff0c;企业要想保持竞争力&#xff0c;就必须不断提升员工的技能和知识水平。知识库作为企业培训的重要工具&#xff0c;不仅能够帮助员工快速获取所需信息&#xff0c;还能促进知识的共享和创新。 1. HelpLook AI知识库 亮点功能&#xff1a;…

React第十一章(useReducer)

useReducer useReducer是React提供的一个高级Hook,没有它我们也可以正常开发&#xff0c;但是useReducer可以使我们的代码具有更好的可读性&#xff0c;可维护性。 useReducer 跟 useState 一样的都是帮我们管理组件的状态的&#xff0c;但是呢与useState不同的是 useReducer…

python基础综合案例(数据可视化-动态柱状图)

1.基础柱状图的构建 打开浏览器&#xff0c;你会发现这是一个动态图&#xff0c;会随着时间变化而变化 具体效果大家可以看我主页有个动态柱状图视频 本质上来说&#xff0c;是和我们构建一个折线统计图差不多的&#xff0c;只是把对象换了一下 如果我们需要反转x和y轴&#…

从SQL到NoSQL:数据库类型及应用场景

在当今数据驱动的时代&#xff0c;数据库技术已经成为了支撑各类应用的核心。在讨论数据库类型时&#xff0c;SQL数据库与NoSQL数据库无疑是最常被提及的两种主流选择。 一、SQL数据库&#xff08;关系型数据库&#xff09; SQL数据库&#xff0c;通常也被称为关系型数据库&am…

YOLOv8实战野生动物识别

本文采用YOLOv8作为核心算法框架&#xff0c;结合PyQt5构建用户界面&#xff0c;使用Python3进行开发。YOLOv8以其高效的实时检测能力&#xff0c;在多个目标检测任务中展现出卓越性能。本研究针对野生动物数据集进行训练和优化&#xff0c;该数据集包含丰富的野生动物图像样本…

【动手学强化学习】part6-策略梯度算法

阐述、总结【动手学强化学习】章节内容的学习情况&#xff0c;复现并理解代码。 文章目录 一、算法背景1.1 算法目标1.2 存在问题1.3 解决方法 二、REINFORCE算法2.1 必要说明softmax()函数交叉熵策略更新思想 2.2 伪代码算法流程简述 2.3 算法代码2.4 运行结果2.5 算法流程说明…

LSTM(Long Short-Term Memory,长短期记忆网络)在高端局效果如何

lstm 杂乱数据分析 LSTM&#xff08;Long Short-Term Memory&#xff0c;长短期记忆网络&#xff09;在高端局&#xff0c;即复杂的机器学习和深度学习应用中&#xff0c;展现出了其独特的优势和广泛的应用价值。以下是对LSTM在高端局中的详细解析&#xff1a; 一、LSTM的优势…

大语言模型驱动的跨域属性级情感分析——论文阅读笔记

前言 论文PDF下载地址&#xff1a;7156 最近想搜一下基于大语言模型的情感分析论文&#xff0c;搜到了这篇在今年发表的论文&#xff0c;于是简单阅读之后在这里记一下笔记。 如图1所示&#xff0c;在餐厅领域中的"快"是上菜快&#xff0c;属于正面情感&#xff0c;但…

jfif图片怎么改成jpg?几种非常简单的jfif转jpg方法

jfif图片怎么改成jpg&#xff1f;随着图像技术的日新月异&#xff0c;用户在图像的编辑、处理与分享过程中&#xff0c;常常需要根据实际需求&#xff0c;灵活转换图像格式&#xff0c;以适应多样化的应用场景。正是这一需求&#xff0c;催生了将jfif格式向jpg格式转换的广泛实…

一些剪视频需要下载视频、chatTTS文字转语音的相关代码

可以在YouTube下载视频&#xff0c;下载字幕&#xff0c;以及需要文字转音频的一些代码&#xff0c;自己写的&#xff0c;目前也是能实现一点小需求~ 是需要下载FFmpeg、yt-dlp.exe、chrome_cookies插件&#xff0c;需要下载的自行search&#xff0c;不再赘述 人机验证 需要…

电能表预付费系统-标准传输规范(STS)(22)

6.5.2.3 DecoderKey classification 6.5.2.3.1 Classification of decoder keys STS DecoderKeys are classified according to the KT values given in Table 32 and inherit their type from that of the VendingKey, from which they are derived. STS decoderkey根据表32…

msvcr100.dll丢失怎么办,总结六种解决msvcr100.dll丢失的方法

​msvcr100.dll是Microsoft Visual C 2010 Redistributable Package中的一个关键动态链接库文件。它包含了运行由Visual C 2010编译的应用程序所需的一系列函数和类。简单来说&#xff0c;许多使用 Visual C 2010 编译的应用程序在启动或运行过程中会依赖 msvcr100.dll 文件。如…