前言:

        vue3+uniapp 使用vue-plugin-hiprint中实现打印效果

官网地址:gitee

https://gitee.com/ccsimple/vue-plugin-hiprinthttps://gitee.com/ccsimple/vue-plugin-hiprint

实现效果:

预览打印内容:

实现步骤:

1、安装插件

npm install vue-plugin-hiprint hiprint

2、main.js中配置

import { hiprint } from 'vue-plugin-hiprint' //添加const app = createApp(App)// 注册插件
app.use(hiprint, { //添加// 可选配置option: {// hiprint 配置项}
})app.mount('#app')

3、新建vue页面,上添加元素

template中添加元素:

hiprint-printTemplate :预览元素

hiprint-designTemplate:设计器,配置各种属性,如果点击设计模板没出来,再点击下dom元素就出现了

hiprint-printPagination:页码,支持打印多页

<template><view><!-- 打印预览容器 --><div id="hiprint-printTemplate"></div><!-- 打印设计器容器 --><div id="hiprint-designTemplate"></div><div class="hiprint-printPagination"></div><button @click="handlePrint">打印</button><button @click="showDesigner">设计模板</button></view>
</template>
js部分:

new hiprint.PrintTemplate  是最核心的配置,配置打印dom元素

dataContainer、settingContainer  都是指向dom元素

paginationContainer   页码dom元素

其他配置可以自己试试,没有也无所谓

<script setup>
import { ref, onMounted } from 'vue'
import { hiprint } from 'vue-plugin-hiprint'// 定义模板
const template = ref(null)
const printTemplate = ref(null)onMounted(() => {// 引入后使用示例hiprint.init();// 初始化打印模板printTemplate.value = new hiprint.PrintTemplate({template: {}, // 模板json// dataContainer: '#hiprint-printTemplate' // 元素参数容器settingContainer: '#hiprint-printTemplate', // 元素参数容器paginationContainer: '.hiprint-printPagination', // 多面板的容器// ------- 下列是可选功能 -------// 图片选择功能onImageChooseClick: (target) => {// 测试 3秒后修改图片地址值setTimeout(() => {// target.refresh(url,options,callback)// callback(el, width, height) // 原元素,宽,高// target.refresh(url,false,(el,width,height)=>{//   el.options.width = width;//   el.designTarget.css('width', width + "pt");//   el.designTarget.children('.resize-panel').trigger($.Event('click'));// })target.refresh("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAtAAAAIIAQMAAAB99EudAAAABlBMVEUmf8vG2O41LStnAAABD0lEQVR42u3XQQqCQBSAYcWFS4/QUTpaHa2jdISWLUJjjMpclJoPGvq+1WsYfiJCZ4oCAAAAAAAAAAAAAAAAAHin6pL9c6H/fOzHbRrP0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0u/SY9LS0tLS0tLS0tLS0n+edm+UlpaWlpaWlpaWlpaW/tl0Ndyzbno7/+tPTJdd1wal69dNa6abx+Lq6TSeYtK7BX/Diek0XULSZZrakPRtV0i6Hu/KIt30q4fM0pvBqvR9mvsQkZaW9gyJT+f5lsnzjR54xAk8mAUeJyMPwYFH98ALx5Jr0kRLLndT7b64UX9QR/0eAAAAAAAAAAAAAAAAAAD/4gpryzr/bja4QgAAAABJRU5ErkJggg==",{// auto: true, // 根据图片宽高自动等比(宽>高?width:height)// width: true, // 按宽调整高// height: true, // 按高调整宽real: true // 根据图片实际尺寸调整(转pt)})}, 3000)// target.getValue()// target.refresh(url)},// 自定义可选字体// 或者使用 hiprintTemplate.setFontList([])// 或元素中 options.fontList: []fontList: [{title: '微软雅黑', value: 'Microsoft YaHei'},{title: '黑体', value: 'STHeitiSC-Light'},{title: '思源黑体', value: 'SourceHanSansCN-Normal'},{title: '王羲之书法体', value: '王羲之书法体'},{title: '宋体', value: 'SimSun'},{title: '华为楷体', value: 'STKaiti'},{title: 'cursive', value: 'cursive'},],dataMode: 1, // 1:getJson 其他:getJsonTid 默认1history: true, // 是否需要 撤销重做功能onDataChanged: (type, json) => { // 模板发生改变回调console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转console.log(json); // 返回 template},onUpdateError: (e) => { // 更新失败回调console.log(e);},})...
js中,动态添加我们的打印内容
var panel = printTemplate.value.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 });//文本panel.addPrintText({ options: { width: 140, height: 15, top: 20, left: 20, title: 'hiprint插件手动添加text', textAlign: 'center' } });//条形码panel.addPrintText({ options: { width: 140, height: 35, top: 40, left: 20, title: '123456', textType: 'barcode' } });//二维码panel.addPrintText({ options: { width: 35, height: 35, top: 40, left: 165, title: '123456', textType: 'qrcode' } });//长文本panel.addPrintLongText({ options: { width: 180, height: 35, top: 90, left: 20, title: '长文本:hiprint是一个很好的webjs打印,浏览器在的地方他都可以运行' } });//打印// printTemplate.value.print({});
给页面上的打印按钮和设计器按钮添加事件

printTemplate.value.print  里面如果上面通过js添加了内容,就不要传参数了

const handlePrint = () => {if (printTemplate.value) {printTemplate.value.print({// 打印数据title: '测试打印',content: '这是打印内容...'})}
}const showDesigner = () => {printTemplate.value.design('#hiprint-designTemplate', {// 设计器配置}, (designer) => {// 设计器回调console.log('设计器已加载', designer)})
}</script>

4、引入公共的css文件,app.vue中引入,或者index.html中

<link rel="stylesheet" type="text/css" media="print" href="/static/print-lock.css">
<style>/*每个页面公共css */@import url('static/print-lock.css')
</style>

cdn地址:print-lock.css文件

npmmirror 镜像站

@media print {body {margin: 0px;padding: 0px;}
}@page {margin: 0;
}.hiprint-printPaper * {box-sizing: border-box;-moz-box-sizing: border-box; /* Firefox */-webkit-box-sizing: border-box; /* Safari */
}.hiprint-printPaper *:focus {outline: -webkit-focus-ring-color auto 0px;
}.hiprint-printPaper {position: relative;padding: 0 0 0 0;page-break-after: always;-webkit-user-select: none; /* Chrome/Safari/Opera */-moz-user-select: none; /* Firefox */user-select: none;overflow-x: hidden;overflow: hidden;
}.hiprint-printPaper .hiprint-printPaper-content {position: relative;
}/* 火狐浏览器打印 第一页过后 重叠问题 */
@-moz-document url-prefix() {.hiprint-printPaper .hiprint-printPaper-content {position: relative;margin-top: 20px;top: -20px}
}.hiprint-printPaper.design {overflow: visible;
}.hiprint-printTemplate .hiprint-printPanel {page-break-after: always;
}.hiprint-printPaper, hiprint-printPanel {box-sizing: border-box;border: 0px;
}.hiprint-printPanel .hiprint-printPaper:last-child {page-break-after: avoid;
}.hiprint-printTemplate .hiprint-printPanel:last-child {page-break-after: avoid;
}.hiprint-printPaper .hideheaderLinetarget {border-top: 0px dashed rgb(201, 190, 190) !important;
}.hiprint-printPaper .hidefooterLinetarget {border-top: 0px dashed rgb(201, 190, 190) !important;
}.hiprint-printPaper.design {border: 1px dashed rgba(170, 170, 170, 0.7);
}.design .hiprint-printElement-table-content, .design .hiprint-printElement-longText-content {overflow: hidden;box-sizing: border-box;
}.design .resize-panel {box-sizing: border-box;border: 1px dotted;
}.hiprint-printElement-text {background-color: transparent;background-repeat: repeat;padding: 0 0 0 0;border: 0.75pt none rgb(0, 0, 0);direction: ltr;font-family: 'SimSun';font-size: 9pt;font-style: normal;font-weight: normal;padding-bottom: 0pt;padding-left: 0pt;padding-right: 0pt;padding-top: 0pt;text-align: left;text-decoration: none;line-height: 9.75pt;box-sizing: border-box;word-wrap: break-word;word-break: break-all;
}.design .hiprint-printElement-text-content {border: 1px dashed rgb(206, 188, 188);box-sizing: border-box;
}.hiprint-printElement-longText {background-color: transparent;background-repeat: repeat;border: 0.75pt none rgb(0, 0, 0);direction: ltr;font-family: 'SimSun';font-size: 9pt;font-style: normal;font-weight: normal;padding-bottom: 0pt;padding-left: 0pt;padding-right: 0pt;padding-top: 0pt;text-align: left;text-decoration: none;line-height: 9.75pt;box-sizing: border-box;word-wrap: break-word;word-break: break-all;/*white-space: pre-wrap*/
}.hiprint-printElement-table {background-color: transparent;background-repeat: repeat;color: rgb(0, 0, 0);border-color: rgb(0, 0, 0);border-style: none;direction: ltr;font-family: 'SimSun';font-size: 9pt;font-style: normal;font-weight: normal;padding-bottom: 0pt;padding-left: 0pt;padding-right: 0pt;padding-top: 0pt;text-align: left;text-decoration: none;padding: 0 0 0 0;box-sizing: border-box;line-height: 9.75pt;
}.hiprint-printElement-table thead {background: #e8e8e8;font-weight: 700;
}table.hiprint-printElement-tableTarget {width: 100%;
}.hiprint-printElement-tableTarget, .hiprint-printElement-tableTarget tr, .hiprint-printElement-tableTarget td {border-color: rgb(0, 0, 0);/*border-style: none;*//*border: 1px solid rgb(0, 0, 0);*/font-weight: normal;direction: ltr;padding-bottom: 0pt;padding-left: 4pt;padding-right: 4pt;padding-top: 0pt;text-decoration: none;vertical-align: middle;box-sizing: border-box;word-wrap: break-word;word-break: break-all;/*line-height: 9.75pt;font-size: 9pt;*/
}.hiprint-printElement-tableTarget-border-all {border: 1px solid;
}
.hiprint-printElement-tableTarget-border-none {border: 0px solid;
}
.hiprint-printElement-tableTarget-border-lr {border-left: 1px solid;border-right: 1px solid;
}
.hiprint-printElement-tableTarget-border-left {border-left: 1px solid;
}
.hiprint-printElement-tableTarget-border-right {border-right: 1px solid;
}
.hiprint-printElement-tableTarget-border-tb {border-top: 1px solid;border-bottom: 1px solid;
}
.hiprint-printElement-tableTarget-border-top {border-top: 1px solid;
}
.hiprint-printElement-tableTarget-border-bottom {border-bottom: 1px solid;
}.hiprint-printElement-tableTarget-border-td-none td {border: 0px solid;
}
.hiprint-printElement-tableTarget-border-td-all td:not(:nth-last-child(-n+2)) {border-right: 1px solid;
}
.hiprint-printElement-tableTarget-border-td-all td:not(last-child) {border-right: 1px solid;
}
.hiprint-printElement-tableTarget-border-td-all td:last-child {border-left: 1px solid;
}
.hiprint-printElement-tableTarget-border-td-all td:last-child:first-child {border-left: none;
}/*.hiprint-printElement-tableTarget tr,*/
.hiprint-printElement-tableTarget td {height: 18pt;
}.hiprint-printPaper .hiprint-paperNumber {font-size: 9pt;
}.design .hiprint-printElement-table-handle {position: absolute;height: 21pt;width: 21pt;background: red;z-index: 1;
}.hiprint-printPaper .hiprint-paperNumber-disabled {float: right !important;right: 0 !important;color: gainsboro !important;
}.hiprint-printElement-vline, .hiprint-printElement-hline {border: 0px none rgb(0, 0, 0);}.hiprint-printElement-vline {border-left: 0.75pt solid #000;border-right: 0px none rgb(0, 0, 0) !important;border-bottom: 0px none rgb(0, 0, 0) !important;border-top: 0px none rgb(0, 0, 0) !important;
}.hiprint-printElement-hline {border-top: 0.75pt solid #000;border-right: 0px none rgb(0, 0, 0) !important;border-bottom: 0px none rgb(0, 0, 0) !important;border-left: 0px none rgb(0, 0, 0) !important;
}.hiprint-printElement-oval, .hiprint-printElement-rect {border: 0.75pt solid #000;
}.hiprint-text-content-middle {
}.hiprint-text-content-middle > div {display: grid;align-items: center;
}.hiprint-text-content-bottom {
}.hiprint-text-content-bottom > div {display: grid;align-items: flex-end;
}.hiprint-text-content-wrap {
}.hiprint-text-content-wrap .hiprint-text-content-wrap-nowrap {white-space: nowrap;
}.hiprint-text-content-wrap .hiprint-text-content-wrap-clip {white-space: nowrap;overflow: hidden;text-overflow: clip;
}.hiprint-text-content-wrap .hiprint-text-content-wrap-ellipsis {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;
}/*hi-grid-row */
.hi-grid-row {position: relative;height: auto;margin-right: 0;margin-left: 0;zoom: 1;display: block;box-sizing: border-box;
}.hi-grid-row::after, .hi-grid-row::before {display: table;content: '';box-sizing: border-box;
}.hi-grid-col {display: block;box-sizing: border-box;position: relative;float: left;flex: 0 0 auto;
}.table-grid-row {margin-left: -0pt;margin-right: -0pt;
}.tableGridColumnsGutterRow {padding-left: 0pt;padding-right: 0pt;
}.hiprint-gridColumnsFooter {text-align: left;clear: both;
}

更多资料:

1、核心资源:npmmirror 镜像站

2、其他资料:vue-plugin-hiprint:一款基于 Vue 开源的可视化打印编辑工具库,支持可视化设计器、报表设计、元素编辑、可视化打印编辑

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

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

相关文章

【elementUI踩坑记录】解决 el-table 固定列 el-table__fixed 导致部分滚动条无法拖动的问题

目录一、问题背景二、 问题现象三、核心原因四、解决办法增强方案&#x1f680;写在最后一、问题背景 在使用 Element UI 的 el-table 组件时&#xff0c;固定列功能虽然实用&#xff0c;但会引发滚动条交互问题&#xff1a; 固定列区域悬浮显示滚动条但无法正常拖动滚动条 …

【机器人编程基础】python文件的打开和关闭

文件的打开和关闭 在Python中,文件操作是一项基本而重要的任务,涉及到打开、读取、写入、关闭文件等操作。正确地管理文件对于数据持久化、输入输出处理等至关重要。下面将详细解释如何在Python中打开和关闭文件,并提供相应的代码示例。 文件打开 在Python中,可以使用内…

ShenYu实战、问题记录

概述 一款高性能的国产的Apache开源API网关&#xff0c;官方文档。 在ShenYu v2.6.1, ShenYu注册中心只支持http类型&#xff0c;中间件注册类型已经被移除。 所以&#xff0c;请使用http注册类型来注册你的服务。不是微服务注册中心&#xff0c;它只是将元数据、选择器数据、…

走近科学IT版:EasyTire设置了ip,但是一闪之后就变回到原来的dhcp获得的地址

EasyTier 是一款简单、安全、去中心化的内网穿透和异地组网工具&#xff0c;适合远程办公、异地访问、游戏加速等多种场景。无需公网 IP&#xff0c;无需复杂配置&#xff0c;轻松实现不同地点设备间的安全互联。 上次实践的记录&#xff1a;适合远程办公、异地访问的EasyTier…

rk3588平台USB 3.0 -OAK深度相机适配方法

目录 文件更改记录表 1、usb规则添加 2、拉取相关依赖 3、安装python3、安装pip 4、安装依赖 5、安装ffmeg 6、摄像头功能测试 7、将视频拷贝到U盘查看 1、usb规则添加 由于OAK是USB设备,因此为了在使用 udev 工具的系统上与之通信, 您需要添加udev规则以使…

工厂模式总结

工厂模式1. 简单工厂模式&#xff08;Simple Factory&#xff09; 核心思想 定义一个工厂类&#xff0c;根据输入参数创建不同的具体对象。客户端不直接调用具体类的构造函数&#xff0c;而是通过工厂类获取对象。 示例代码 #include <iostream> #include <memory>…

MySQL的三种安装方式(mis、zip、yum)

目录 2.0数据库安装 2.1windows上.mis格式 环境准备 MySQL的安装 环境配置&#xff08;非必要&#xff09; 2.2windows上.zip格式安装 环境准备 配置文件的内容 MySQL的安装 附录可能出现问题 图形工具远程连接数据库 2.3Linux上安装yum包 环境准备 过程命令 My…

串口学习和蓝牙通信HC05(第八天)

&#x1f468;‍&#x1f4bb;个人主页&#xff1a;开发者-削好皮的Pineapple! &#x1f468;‍&#x1f4bb; hello 欢迎 点赞&#x1f44d; 收藏⭐ 留言&#x1f4dd; 加关注✅! &#x1f468;‍&#x1f4bb; 本文由 削好皮的Pineapple! 原创 &#x1f468;‍&#x1f4b…

设计总监的“轻量化”新武器:用Adobe Express,音频一键驱动动画

在快节奏的创意项目中&#xff0c;如何将复杂的设计理念或冗长的研究报告&#xff0c;快速转化为易于理解、富有吸引力的动态内容&#xff0c;是衡量一个团队沟通效率的关键。作为一名在海外设计界工作了十余年的设计师&#xff0c;我发现&#xff0c;最高效的团队&#xff0c;…

零知开源——STM32F407VET6驱动SHT41温湿度传感器完整教程

✔零知开源是一个真正属于国人自己的开源软硬件平台&#xff0c;在开发效率上超越了Arduino平台并且更加容易上手&#xff0c;大大降低了开发难度。零知开源在软件方面提供了完整的学习教程和丰富示例代码&#xff0c;让不懂程序的工程师也能非常轻而易举的搭建电路来创作产品&…

Linux流量分析:tcpdump wireshark

前言 最近因为工作需要&#xff0c;研究了下如何使用tcpdump和wireshark分析业务流量。如果要使用tcpdump分析具体的HTTP请求耗时&#xff0c;需捕获网络数据包并分析时间戳信息&#xff0c;重点关注TCP连接的建立、HTTP请求发送到响应接收的全过程。 以下是具体步骤和技巧&…

深度学习图像分类数据集—角膜溃疡识别分类

该数据集为图像分类数据集&#xff0c;适用于ResNet、VGG等卷积神经网络&#xff0c;SENet、CBAM等注意力机制相关算法&#xff0c;Vision Transformer等Transformer相关算法。 数据集信息介绍&#xff1a;角膜溃疡识别分类&#xff1a;[dot, mix, slice] 训练数据集总共有270张…

功能强、超好用【PDF转换工具】的介绍下载与安装教程

Windows 电脑上一款简单好用的PDF转换工具&#xff0c;可以轻松地将其他文档转换为 PDF 格式&#xff0c;也可以将 PDF 文件转换为其他格式&#xff0c;如常见的 Word、Excel、PPT 等。 此外软件还支持 Office 文档合并分割、旋转页面、拼接页面、删除文字、删除页面、添加水印…

c# 钉钉应用实现监听审批事件以及获取审批结果的流程

oa的操作已经测试了一遍 image.png如果是自建oa则代表发起的审批是跳转网页&#xff0c;否则钉钉打开后是一个表单界面&#xff0c;不需要调整自己搞得oa。 所以我感觉目前公司的需求更适合官方oa 表单来填写,更灵活&#xff0c;还支持用户配置。 但是用户点了审批&#xff0c;…

Typecho架构深度剖析:轻量级博客系统的设计哲学与实现原理

文章目录 深度解析Typecho:轻量级博客系统的架构设计与实现1. Typecho概述与技术背景1.1 发展历程1.2 核心特性2. 系统架构设计分析2.1 核心架构图2.2 核心组件3. 核心模块实现分析3.1 路由系统实现3.2 数据库抽象层4. 插件系统深度解析4.1 Hook机制实现4.2 插件开发示例5. 性…

LangChain 内存(Memory)

1. 为什么需要内存&#xff1f; 大型语言模型&#xff08;LLM&#xff09;本身是无状态的。这意味着每次你向 LLM 发送一个请求&#xff08;Prompt&#xff09;&#xff0c;它都会独立处理这个请求&#xff0c;完全不记得之前任何的交互。这在构建一次性问答应用时没问题&#…

基于定制开发开源AI智能名片S2B2C商城小程序的社群游戏定制策略研究

摘要&#xff1a;本文聚焦社群游戏定制领域&#xff0c;深入探讨以社群文化和用户偏好为导向的定制策略。通过分析互动游戏活动、社群文化塑造等关键要素&#xff0c;结合定制开发开源AI智能名片S2B2C商城小程序的技术特性&#xff0c;提出针对性游戏定制方案。研究旨在提升社群…

自动驾驶决策与规划

目录 自动驾驶决策与规划概述 决策与规划体系结构 分层递阶式决策规划 反应式体系结构 混合式体系结构 决策与规划系统的关键环节 路径规划 轨迹规划 行为决策 异常处理 自动驾驶的路径规划技术 维诺图法 栅格法 Dijkstra算法 A*算法 自动驾驶的行为决策方法 …

C++编译期计算:常量表达式(constexpr)全解析

在C性能优化领域&#xff0c;"将计算尽可能转移到编译期"是一条黄金法则。编译期计算&#xff08;Compile-Time Computation&#xff09;能显著减少程序运行时的开销&#xff0c;提升执行效率&#xff0c;同时还能在编译阶段暴露潜在错误。C11引入的constexpr关键字及…

【micro:bit】从入门到放弃(一):在线、离线版本的使用

1、离线版 micro:bit 1)下载地址 https://makecode.microbit.org/offline-app 2)双击安装包,makecode-microbit-setup-win64.exe,自动安装,安装成功后图标如下图所示 3)运行程序,查看版本信息 4)主界面如下 5)编程界面 点击“新建项目”或者“导入”进入编程界…