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

server/2025/3/4 16:36:50/

目录

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

打印、下载弹框组件

@/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/server/172374.html

相关文章

信息发布小程序功能方案详解

信息发布小程序功能方案详解&#xff0c;php开发语言&#xff0c;可以源码搭建、二开&#xff0c;或者定制开发。 一 用户端&#xff1a;小程序核心功能模块 1.信息发布小程序&#xff0c;信息分类&#xff0c;分类的图标和名称是自定义设置的 2.查看信息&#xff1a;查看信…

Leetcode 49: 字母异位词分组

Leetcode 49: 字母异位词分组 这是一道经典的哈希表与字符串操作相关的题目&#xff0c;考察快速分组和使用数据结构的能力。所谓字母异位词&#xff0c;是指由相同的字母通过重新排列形成的不同单词。题目要求将一组字符串按照字母异位词分组。 问题描述 给定一个字符串数组…

【Go】十八、http 调用服务的编写

http接口框架的搭建 这个http接口框架的搭建参考之前的全量搭建&#xff0c;这里是快速搭建的模式&#xff1a; 直接对已有的http模块进行复制修改&#xff0c;主要修改点在于 proto部分与api、router 部分&#xff0c;剩余的要针对进行修改模块名称。 接口的具体编写 在 a…

使用Fuse-DFS挂载文件存储 HDFS-后端存储ceph

1. 编译环境准备 yum install cmake3 ln -s /usr/bin/cmake3 /usr/bin/cmake yum install gcc-c安装挂载依赖 yum -y install fuse fuse-devel fuse-libs执行以下命令&#xff0c;载入FUSE模块 modprobe fuse2. 下载源码包 hadoop-3.3.4-src.tar.gz解压后执行以下命令 打开…

Freertos卡在while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )

今天用CubeMX创建freertos点了一个灯让他闪&#xff0c;他竟然不闪&#xff0c;我giao&#xff0c;然后调试发现他一直卡在while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )这句话&#xff0c;后来搜了好多都不行&#xff0c;最后&#xff0c;改了这个 就ok了

重学SpringBoot3-Spring Retry实践

更多SpringBoot3内容请关注我的专栏&#xff1a;《SpringBoot3》 期待您的点赞??收藏评论 重学SpringBoot3-Spring Retry实践 1. 简介2. 环境准备3. 使用方式 3.1 注解方式 基础使用自定义重试策略失败恢复机制重试和失败恢复效果注意事项 3.2 编程式使用3.3 监听重试过程 监…

安卓基础组件Looper - 02 native层面的剖析

文章目录 native使用使用总结创建Looper构造函数创建(不推荐)使用举例源代码 Looper::prepare 获取Looper可忽略初始化Looper主动休眠 pollAll主动唤醒 wake 发送消息 sendMessage轮询消息 native使用 Android Native Looper 机制 - 掘金 (juejin.cn) /system/core/libutils/…

分布式中间件:Redis介绍

目录 Redis 概述 Redis 的特点 高性能 丰富的数据结构 持久化 分布式特性 简单易用 Redis 的数据结构 字符串&#xff08;String&#xff09; 哈希&#xff08;Hash&#xff09; 列表&#xff08;List&#xff09; 集合&#xff08;Set&#xff09; 有序集合&…