【弹框组件封装】展示、打印、下载XX表(Base64格式图片)

devtools/2025/3/4 22:45:37/

目录

  • 打印、下载弹框组件
  • 组件使用
  • 弹框展示

打印、下载弹框组件

@/components/PrintDialog.vue

<!-- 打印、下载弹框 -->
<template><el-dialog:title="title"top="3vh"append-to-body:visible.sync="dialogVisible":close-on-click-modal="false":before-close="handleClose"width="50%"><div ref="printRef"><el-image :src="src" :preview-src-list="[src]" /></div><div v-if="!isPreview" slot="footer"><el-button @click="handleClose">取消</el-button><el-button :loading="downloadLoading" type="primary" @click="handleDownload">下载</el-button><el-button :loading="printLoading" type="primary" @click="handlePrint">打印</el-button></div></el-dialog>
</template><script>javascript">
import html2canvas from 'html2canvas'
import printJS from 'print-js'export default {name: 'PrintDialog',components: {},data() {return {dialogVisible: false,downloadLoading: false,printLoading: false,title: '',src: '',isPreview: false}},computed: {},watch: {},created() {},methods: {open(title, src, isPreview = false) {this.title = titlethis.src = srcthis.isPreview = isPreviewthis.dialogVisible = true},handlePrint() {this.printLoading = truehtml2canvas(this.$refs.printRef).then((canvas) => {const saveUrl = canvas.toDataURL('image/png')printJS({printable: [saveUrl],type: 'image'})})this.printLoading = false},handleDownload() {this.downloadLoading = truehtml2canvas(this.$refs.printRef).then((canvas) => {const imgUrl = canvas.toDataURL('image/png')let image = document.createElement('img')image.src = imgUrllet a = document.createElement('a')a.href = imgUrla.download = this.titlea.click()a = nullimage = null}).finally(() => {this.downloadLoading = false})},handleClose() {this.title = ''this.src = ''this.isPreview = falsethis.dialogVisible = false}}
}
</script><style lang='scss' scoped>
@import '@/styles/dialog-scss.scss';
.el-image {width: 100%;
}
</style>

组件使用

<template><el-button:disabled="selectList.length !== 1"icon="iconfont ico-daochu"type="text"size="mini"@click="printHandler">打印记分决定操作表</el-button><!-- 打印 --><PrintDialog ref="PrintDialogRef" />
</template><script>javascript">
import { previewScore } from '@/api/twelve-points'
import OperationDialog from './components/OperationDialog'export default {components: { PrintDialog },data() {return {jfbh: ''}},methods: {printHandler() {console.log('打印记分告知单')previewScore({ jdbh: this.jfbh }).then((res) => {this.$common.CheckCode(res, null, () => {if (!res.data) returnthis.$refs.PrintDialogRef.open('操作表', 'data:image/jpg;base64,' + res.data)// this.$refs.PrintDialogRef.open('文件名/弹框title', 'base64前缀' + Base64格式图片)})})},}
}
</script>

弹框展示

在这里插入图片描述


http://www.ppmy.cn/devtools/164577.html

相关文章

基于web端的ftp程序

搭建一个web页面访问的FTP服务器 github官网地址 vsftpd 程序搭建跳转地址 vsftpd 搭建完成之后&#xff0c;开始搭建 ftp-web 下载运行该项目需要 Node.js v4 才能运行。# node 版本为 v16.20.2 node -v v16.20.2git clone https://github.com/liuqi6908/ftp-web-client.gi…

SpringBoot系列之Spring AI+DeekSeek创建AI应用

使用 Spring AI 与 DeepSeek 创建智能 AI 应用 随着人工智能技术的飞速发展&#xff0c;AI 已经成为现代软件应用中不可或缺的一部分。从智能对话系统到内容生成工具&#xff0c;AI 的应用场景日益丰富。Spring AI 是 Spring 官方推出的用于简化 AI 集成的框架&#xff0c;而 …

java 项目中设计模式 之单例模式

本文是自己学习单例模式的记录&#xff0c;方便以后使用的时候查看&#xff0c;并不专业哈 一、单例模式 1、特点&#xff1a; 单例模式是最简单的一种模式&#xff0c;具有单例模式只能有一个实例&#xff0c;并且必须为其他对象提供一个访问点。单例模式分为懒汉模式和饥饿…

C语言总结目录

一、数据类型【文章链接】 二、标识符【文章链接】​​​​​​​ #编译GCC 三、程序结构语句 四、输入输出函数 五、数组 六、指针 七、数组指针&&指针数组 八、排序算法 九、结构体 十、链表 十一、宏定义 十二、文件读写 十三、静态库&&动态库…

计算机毕设JAVA——某高校宿舍管理系统(基于SpringBoot+Vue前后端分离的项目)

文章目录 概要项目演示图片系统架构技术运行环境系统功能简介 概要 网络上许多计算机毕设项目开发前端界面设计复杂、不美观&#xff0c;而且功能结构十分单一&#xff0c;存在很多雷同的项目&#xff1a;不同的项目基本上就是套用固定模板&#xff0c;换个颜色、改个文字&…

25年前端如何走的更稳

2025年&#xff0c;随着deepseek引起的AI大模型技术的深度革命&#xff0c;带来了很多机会和挑战&#xff0c;前端程序员作为互联网里一个普通但必不可少的岗位&#xff0c;在当前形势下&#xff0c;需要主动变革才能走的更稳。本文简单介绍三个方向&#xff0c;Web3前端、全栈…

本地部署 DeepSeek-R1大模型详细教程(桌面客户端美观UI)

大家好&#xff01;今天我来分享一篇超级详细的教程&#xff0c;教你如何在本地部署 DeepSeek-R1 大模型&#xff0c;让你的电脑也能成为一个强大的 AI 工作站&#xff01;这篇文章会从零开始&#xff0c;手把手带你完成所有步骤&#xff0c;适合小白操作。废话不多说&#xff…

Vue3 TransitionGroup组件深入解析:结合Element Plus实践指南

引言 在动态列表交互场景中&#xff0c;元素的增删排序需要优雅的过渡效果。Vue3的TransitionGroup组件为这类需求提供了专业解决方案。本文将通过Element Plus等流行UI库的实战案例&#xff0c;深入剖析TransitionGroup的应用技巧。 一、TransitionGroup核心特性 1.1 与Tran…