vue3+uniapp 使用vue-plugin-hiprint中實現打印效果

前言:

????????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)編程界面 點擊“新建項目”或者“導入”進入編程界…