Vue3使用kkFileView预览文件pdf

2023-11-28 07:28

本文主要是介绍Vue3使用kkFileView预览文件pdf,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

kkFileView - 在线文件预览kkFileView官网 - kkFileView使用Spring Boot搭建,易上手和部署,基本支持主流办公文档的在线预览,如doc,docx,Excel,pdf,txt,zip,rar,图片等等icon-default.png?t=N7T8https://kkfileview.keking.cn/zh-cn/docs/usage.html业务场景:需要点击按钮,弹出弹框预览pdf文件

这里使用的是3.x.x 版本,需要下载base64

3.x.x 版本 # 示例

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/js-base64@3.6.0/base64.min.js"></script>var originUrl = 'http://127.0.0.1:8080/filedownload?fileId=1'; //要预览文件的访问地址
var previewUrl = originUrl + '&fullfilename=test.txt'
window.open('http://127.0.0.1:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(previewUrl)));

 

 

配置baseUrl,如果是生产环境,走 location.origin 浏览器的当前地址,它包含了协议、域名和端口号,否则走项目配置中设置的环境变量 VITE_APP_API_URL  的值。

替换示例的文件地址,打开弹窗时把地址传给弹窗,弹窗里使用iframe

// 预览const handleClickOpenPreview = (row) => {if (row.fileState === '无') returnconst baseUrl = import.meta.env.PROD ? location.origin : import.meta.env.VITE_APP_API_URL// const originUrl = baseUrl + '/hs/document/downloadWord' + '?fileName=010001_20231015_1697332623776.docx'// const previewUrl = originUrl + '&fullfilename=010001_20231015_1697332623776.docx'// window.open('http://100.100.120.147:8012/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl)));// window.open(baseUrl + '/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl)));const originUrl = baseUrl + '/hs/document/downloadWord' + `?fileName=${row.fileName}`const previewUrl = originUrl + `&fullfilename=${row.fileName}`const url = baseUrl + '/preview/onlinePreview?url=' + encodeURIComponent(Base64.encode(previewUrl))state.PreViewFileDialogRef.open(row, url) // 把url传给弹窗}

 弹窗页

<template><PatrolDialog :show="show" @close="show = false" DeleteFooterBtn width="1370px" top="5vh"><template #title><div class="dialog-title"><img :src="weatherStationIcon" />预览</div></template><div class="formPart"><el-dropdown trigger="click" @command="handleClickExport" size="small"><span class="el-dropdown-link"><i class="icon iconfont icon-daochu" style="color: var(--gdky-primary-color);"></i></span><template #dropdown><el-dropdown-menu><el-dropdown-item command="word">word</el-dropdown-item><el-dropdown-item command="pdf">pdf</el-dropdown-item></el-dropdown-menu></template></el-dropdown><!-- 在弹窗中显示的内容 --><iframe :src="pageUrl" width="100%" height="800px" class="file"></iframe></div></PatrolDialog>
</template><script>
import { reactive, toRefs, computed, watch } from 'vue'
import PatrolDialog from '@/views/Components/PatrolDialog.vue'
import weatherStationIcon from '@/assets/imgs/title_img.png'
import { exportWord, exportPdf } from '@/api/PlatTool/CustomModules/HeatSourceDispatch/index'export default {components: {PatrolDialog},setup(_, { emit }) {const state = reactive({show: false,weatherStationIcon, // iconcurRow: null,pageUrl: "",})const methods = {// 打开弹窗async open(curRow, url) {state.show = true;state.curRow = curRow;state.pageUrl = url},// 导出handleClickExport(command) {if (command === "word") {exportWord({ fileName: state.curRow.fileName })} else {exportPdf({ fileName: state.curRow.pdfFileName })}}}return {...toRefs(state),...methods,}}
}
</script>
<style lang='less' scoped>
.dialog-title {display: flex;font-size: 16px;font-family: MicrosoftYaHeiSemibold;color: var(--gdky-main-content-color);line-height: 24px;padding-bottom: var(--base-padding);img {margin-right: 8px;}
}.formPart {display: flex;flex-direction: column;flex: 1;height: 100%;.file {display: flex;justify-content: center;align-items: center;margin-left: -15px;position: relative;}.el-dropdown-link {position: absolute;top: 5px;right: 88px;z-index: 999;}
}
</style><style lang="less">
.g-dark {.formPart {.el-dropdown-link {}}
}
</style>

这篇关于Vue3使用kkFileView预览文件pdf的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/429290

相关文章

使用Python开发Markdown兼容公式格式转换工具

《使用Python开发Markdown兼容公式格式转换工具》在技术写作中我们经常遇到公式格式问题,例如MathML无法显示,LaTeX格式错乱等,所以本文我们将使用Python开发Markdown兼容... 目录一、工具背景二、环境配置(Windows 10/11)1. 创建conda环境2. 获取XSLT

Python中Flask模板的使用与高级技巧详解

《Python中Flask模板的使用与高级技巧详解》在Web开发中,直接将HTML代码写在Python文件中会导致诸多问题,Flask内置了Jinja2模板引擎,完美解决了这些问题,下面我们就来看看F... 目录一、模板渲染基础1.1 为什么需要模板引擎1.2 第一个模板渲染示例1.3 模板渲染原理二、模板

浅析如何使用xstream实现javaBean与xml互转

《浅析如何使用xstream实现javaBean与xml互转》XStream是一个用于将Java对象与XML之间进行转换的库,它非常简单易用,下面将详细介绍如何使用XStream实现JavaBean与... 目录1. 引入依赖2. 定义 JavaBean3. JavaBean 转 XML4. XML 转 J

使用Python创建一个功能完整的Windows风格计算器程序

《使用Python创建一个功能完整的Windows风格计算器程序》:本文主要介绍如何使用Python和Tkinter创建一个功能完整的Windows风格计算器程序,包括基本运算、高级科学计算(如三... 目录python实现Windows系统计算器程序(含高级功能)1. 使用Tkinter实现基础计算器2.

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

Git可视化管理工具(SourceTree)使用操作大全经典

《Git可视化管理工具(SourceTree)使用操作大全经典》本文详细介绍了SourceTree作为Git可视化管理工具的常用操作,包括连接远程仓库、添加SSH密钥、克隆仓库、设置默认项目目录、代码... 目录前言:连接Gitee or github,获取代码:在SourceTree中添加SSH密钥:Cl

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib