diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c57409..0c40fa18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,234 @@ ### 💐️ GitHub 提交 PR 合并后可自动发布到 npm 仓库; ### 💐 同时自动更新 GitHub Pages 同步 Gitee; ### 💐 感谢各位贡献者的支持。 🔥 +### 💐 希望各位多看看文档、文章、更新日志; 📢 本页面支持 Ctrl/Command + F 搜索 + +## 0.0.60 (2025-03-24) +> 使用此版本 请更新最新的 print-lock.css + +
+ 01. ✨ 调整优化 hinnn.dateFormat 支持时间戳 +
+
+ 02. ✨ 调整优化 engines node >=16 +
+
+ 03. 🐛️ fix install bwipjs error +
+
+ 04. 🐛️ fix 某些特定情况下 onload 函数重复调用 导致重复弹出浏览器预览打印弹窗的bug +
+
+ 05. 🐛️ fix table 数据格式问题(Array.isArray) +
+ +## 0.0.58 (2024-11-02) +> 使用此版本 请更新最新的 print-lock.css + +> 感谢各位提交 PR 的码友们! 感谢~ + +> 同时希望各位多看看文档、文章、更新日志; 📢 本页面支持 Ctrl/Command + F 搜索 + +- 点击 ▶ 可查看详情 + +
+ 01. 🌈 新增面板排列功能 (横向、纵向 支持间距) + +- 小模板 传数组 铺满 对应纸张 +
+
+ 02. 🌈 新增支持 barcode、qrcode 条码颜色设置 + +
+
+ 03. 🌈 新增支持 表格列 条形码/二维码值显示设置 + +
+
+ 04. 🌈 新增支持 全选元素API 可批量删除 + +hiprintTemplate.selectAllElements(); +
+
+ 05. 🌈 新增支持 根据字段名 选中元素 + +hiprintTemplate.selectElementsByField(['name']); +
+
+ 06. 🌈 新增支持 获取打印机纸张信息 API (客户端^1.0.10) + +> ❗️ node-hiprint-transit 中转暂未添加支持 + + ```js + // 获取指定打印机纸张信息 + hiprint.getPaperInfo(printerName); + // 获取所有打印机纸张信息 + hiprint.getPaperInfo(); + + // 获取纸张信息方法是异步请求的,没有返回值,你可以使用 hinnn.event.on("paperSizeInfo", () => {}) 监听数据返回 + hinnn.event.on("paperSizeInfo", (paperSize) => { + console.log(paperSize); + }); + // [ + // { + // "PrinterName": "Microsoft Print to PDF", + // "TaskNumber": 0, // 打印队列数 + // "Status": 0, // 设备状态码 + // "StatusMsg": "准备就绪(Ready)", // 设备状态信息 + // "PaperSizes": [ + // { + // "Height": 1100, // 单位 mm + // "Kind": 1, + // "PaperName": "信纸", + // "RawKind": 1, + // "Width": 850 // 单位 mm + // } + // ] + // } + // ] + ```> ❗️ node-hiprint-transit 中转暂未添加支持 + + ```js + // 获取指定打印机纸张信息 + hiprint.getPaperInfo(printerName); + // 获取所有打印机纸张信息 + hiprint.getPaperInfo(); + + // 获取纸张信息方法是异步请求的,没有返回值,你可以使用 hinnn.event.on("paperSizeInfo", () => {}) 监听数据返回 + hinnn.event.on("paperSizeInfo", (paperSize) => { + console.log(paperSize); + }); + // [ + // { + // "PrinterName": "Microsoft Print to PDF", + // "TaskNumber": 0, // 打印队列数 + // "Status": 0, // 设备状态码 + // "StatusMsg": "准备就绪(Ready)", // 设备状态信息 + // "PaperSizes": [ + // { + // "Height": 1100, // 单位 mm + // "Kind": 1, + // "PaperName": "信纸", + // "RawKind": 1, + // "Width": 850 // 单位 mm + // } + // ] + // } + // ] + ``` +
+
+ 07. 🌈 新增支持 print2支持分批打印(需客户端 v1.0.11) + +支持单模版大单据量连续打印 @george-hong ([#138](https://github.com/CcSimple/vue-plugin-hiprint/pull/138)) + ```js + hiprintTemplate.print2(printDataList, { + printer: '打印机名称', + title: '打印标题', + printByFragments: true, // 是否需要分批打印,分批打印能够支持连续打印大量数据,但会增加打印所需时间 + generateHTMLInterval: 30, // 多条数据生成HTML的间隔,单位ms,默认10 + fragmentSize: 10000, // 分片字符长度,默认50000 + sendInterval: 20, // 分片传输间隔,单位ms,默认10 + }) + ``` +
+
+ 08. ✨ 调整优化 text、barcode 类型条码自动增加宽度优化 + +
+
+ 09. ✨ 调整优化 text条形码: 支持设置条码文本模式: 单独文本、svg文本 + +
+
+ 10. ✨ 调整优化 API 更新元素时 属性同步 + +
+
+ 11. ✨ 调整优化 缩放时 框选框 移动偏差问题 + +
+
+ 12. ✨ 调整优化 分组头/脚函数 自动判断return是否包含 tr、td + +
+
+ 13. ✨ 调整优化 hiprint.setConfig API + +- 支持隐藏参数分组 +- 隐藏部分参数分组 +
+
+ 14. ✨ 调整优化 update 更新模板时 尺寸跟着改变 + +
+
+ 15. ✨ 调整优化 静默打印 图片默认不转 base64 + +
+
+ 16. ✨ 调整优化 表格 分组序号 支持续编 + +
+
+ 17. ⚠️ 修改 print2 打印成功回调事件为 success + +项目初始时 print2 打印成功回调事件即为 `successs` 事件 (手抖多打了个 s),electron-hiprint v1.0.8 重构关键代码时发现了该问题,为了标准及向下兼容,同时保留了 `succsss` 和 `success` 事件,经过 8 个多月的过渡期,现统一改为 `success` ,该改动仅对 electron-hiprint 1.0.7 及以前的客户端版本造成破坏性更新,后续版本无影响,我们也推荐大家及时更新至 1.0.11 以后的版本,体验更多优秀的功能。 +
+
+ 18. 🐛✨🐛✨🐛✨🐛 其他修复或优化见详情(或见 git history) + +- 修复选择图片后refresh方法参数real属性无效,以及回调函数可能不会执行的问题 +- i18n相关修复优化 +- fix: 修复复制元素自动聚焦的bug +- 将图片的缩放控制点从[se,r]改为[s,e,se,r] (#98) +- 修复双击文本出现冒号的bug (#102) +- fix #104 修复表格中存在多列rowSpan时多页rowSpan错误 +- 修复表格分页colspan问题 +- fix: 修复新添加的条形码/二维码元素-左右对齐参数不生效的问题 +- add 表格添加 colgroup 解决分页不显示表头时列宽各种问题 +- fix 表格 样式参数设置不生效的 bug +- fix 表格里面当字段类型为图片时,单元格高度设置无效BUG修复,并设置最小高度避免表单高度计算失败 +
+ + + +## 0.0.57-beta28(2024-08-10) +**⚠️⚠️⚠️ 有限的破坏性更新 Breaking changes** +
+ 01. 🌈 新增支持 print2支持分批打印(需客户端 v1.0.11) + + 支持单模版大单据量连续打印 @george-hong ([#138](https://github.com/CcSimple/vue-plugin-hiprint/pull/138)) + ```js + hiprintTemplate.print2(printDataList, { + printer: '打印机名称', + title: '打印标题', + printByFragments: true, // 是否需要分批打印,分批打印能够支持连续打印大量数据,但会增加打印所需时间 + generateHTMLInterval: 30, // 多条数据生成HTML的间隔,单位ms,默认10 + fragmentSize: 10000, // 分片字符长度,默认50000 + sendInterval: 20, // 分片传输间隔,单位ms,默认10 + }) + ``` +
+ +
+ 02. ⚠️ 修改 print2 打印成功回调事件为 success + + 项目初始时 print2 打印成功回调事件即为 `successs` 事件 (手抖多打了个 s),electron-hiprint v1.0.8 重构关键代码时发现了该问题,为了标准及向下兼容,同时保留了 `succsss` 和 `success` 事件,经过 8 个多月的过渡期,现统一改为 `success` ,该改动仅对 electron-hiprint 1.0.7 及以前的客户端版本造成破坏性更新,后续版本无影响,我们也推荐大家及时更新至 1.0.11 以后的版本,体验更多优秀的功能。 +
+ +## 0.0.57-beta27(2024-07-30) +
+ 01. 🐛️ fix 表格字段为图片,单元格高度无效修复 + + 表格里面当字段类型为图片时,单元格高度设置无效 BUG 修复,并设置最小高度避免表单高度计算失败 @zhmlsj ([#131](https://github.com/CcSimple/vue-plugin-hiprint/pull/131)) +
## 0.0.57-beta26(2024-07-11)
01. ✨ 调整优化 水印 打印无需在浏览器预览勾选背景图案 - 需要支持 [-webkit-print-color-adjust](https://caniuse.com/?search=-webkit-print-color-adjust) 样式 + 需要支持 [-webkit-print-color-adjust](https://caniuse.com/?search=-webkit-print-color-adjust) 样式 @Xavier ([#129](https://github.com/CcSimple/vue-plugin-hiprint/pull/129))
## 0.0.57-beta25(2024-07-10) @@ -21,7 +243,8 @@ ## 0.0.57-beta23(2024-05-17)
01. 🌈 新增支持 添加 selectElementsByField 属性,通过传入field的字符串数组选中文本类型的元素 - + +@xiaolonggee ([#123](https://github.com/CcSimple/vue-plugin-hiprint/pull/123)) ```js hiprintTemplate.selectElementsByField(['name']) ``` @@ -34,7 +257,7 @@ 01. ✨ 调整优化 text、barcode 类型条码自动增加宽度优化 经过一段时间的测试及实验,找到了 [JsBarcode](https://github.com/lindell/JsBarcode) 与 [bwip-js](https://github.com/metafloor/bwip-js) 两个库实现条码宽度自动增加的较优方案。(感谢Q群用户 【︶ㄣ夏^熟 。】的测试) - + 现在你可以在 text[textType='barcode']、barCode 元素中设置 barAutoWidth 属性,使条码以渲染时 svg 提供的最小尺寸自动增加宽度。 > 0.0.57-beta20 版本中 条码宽度 = svg宽度 * 1.2,该倍率不是很合理,在此版本中修改为 1.05 @@ -78,7 +301,7 @@
01. 🌈 新增支持 获取打印机纸张信息 Beta ❗️ - + 当客户端运行在 window 系统环境时可以获取打印机纸张信息,你需要自行拉取最新客户端代码[electron-hiprint](https://github.com/CcSimple/electron-hiprint),自行构建最新版本(v1.0.10) > ❗️ node-hiprint-transit 中转暂未添加支持 @@ -185,7 +408,7 @@ const template = new hiprint.PrintTemplate({ template: panel, }) - + template.selectAllElements() ```
diff --git a/README.md b/README.md index cde34725..b77f5a86 100644 --- a/README.md +++ b/README.md @@ -23,81 +23,75 @@ ## 关于此插件 -vue-plugin-hiprint(基于[hiprint 2.5.4](http://hiprint.io/)) 当时只是为了方便我(并非hiprint原作者) 在vue项目中引入使用,所以以此命名。 +vue-plugin-hiprint (基于 [hiprint 2.5.4](http://hiprint.io/)) 当时只是为了方便 我(并非 hiprint 原作者) 在 vue 项目中引入使用,所以以此命名。 -此插件仅仅是一个JavaScript【工具库】而非 Vue【组件库】,所以它默认是不包含demo中所见的那些组件页面的(demo代码随便复制修改拿去用)。 +此 插件 仅仅是一个 JavaScript【工具库】 而非 Vue【组件库】,所以它默认不包含 demo 中的那些组件页面(demo 代码可复制使用)。 -由于hiprint官网最后一次更新时间为2019年【hiprint 2.5.4 是 [LGPL](#关于lgpl协议) 协议】,后在诸多使用者及反馈下进行了许多优化调整。[更新日志](CHANGELOG.md)(同时感谢各位群友支持和参与) +由于 hiprint 官网最后一次更新时间为 2019 年【hiprint 2.5.4 是 [LGPL](#关于lgpl协议) 协议】,后在诸多使用者及反馈下进行了许多优化调整。 -## vue-plugin-hiprint [更新日志](CHANGELOG.md) -> hiprint for Vue2.x / Vue3.x (基于jQuery, 理论上应该也是支持其他框架的) +## vue-plugin-hiprint -> **jQuery/uniapp** 项目 见下方 [jQuery/uniapp 项目使用](#jQuery/uniapp 项目使用) +> [✨ 立即体验(Github 访问慢)](https://ccsimple.github.io/vue-plugin-hiprint/)

[✨ 国内访问(www.ibujian.cn)](https://www.ibujian.cn/)

[🌈 更新日志 (页面支持 Ctrl + F 搜索)](CHANGELOG.md)

[🐛 常见问题(入门必看!)](#常见问题) ⚠️⚠️ [📕 系列教程文章(入门必看!)](#文章链接)

[🚀 项目生态(打印客户端、node 服务端、uniapp)](#插件生态) -## 注意事项!! +> hiprint for Vue2.x / Vue3.x (基于 jQuery, 理论上其他框架可用。[react demo 分支](https://github.com/CcSimple/vue-plugin-hiprint/tree/react_demo)) -- NodeJs 需要 16.x 版本 (开发使用的 16.18.1) --
【vue-plugin-hiprint】与【hiprint.io官网】差异甚多,请忽混用!请忽混用!请忽混用!
--
请使用我提供的打印客户端,或者自行修改打印客户端的源码,以适配本项目的模板!
-- 主分支是融合版本的最新代码,如果你不需要修改 hiprint 相关代码. 请使用 npm 包的方式安装. -- 使用直接客户端时,本地开发连接没问题,部署到线上出现跨域无法连接打印客户端问题: -- [线上跨域问题,请升级 https! 说明:https://www.cnblogs.com/daysme/p/15493523.html](https://www.cnblogs.com/daysme/p/15493523.html) -- 如需提交 PR 请前往 github 合并后可自动发布npm包并同步代码到 gitee -- vue-plugin-hiprint 包不包含UI界面,需要自行处理。如果想更快速引入请查看 [sv-print组件库](https://ccsimple.github.io/sv-print-docs/) +> **jQuery/uniapp (html/h5)** 项目 见下方 [jQuery/uniapp 项目使用](#jqueryuniapp-项目使用) -## 快速链接 - -Demo预览:[https://ccsimple.gitee.io/vue-plugin-hiprint/](https://ccsimple.gitee.io/vue-plugin-hiprint/)(已挂,恢复看gitee官方情况) - -Github Demo预览:[https://ccsimple.github.io/vue-plugin-hiprint/](https://ccsimple.github.io/vue-plugin-hiprint/)(慢,请墙) - -更新记录:[npm包版本及更新记录](CHANGELOG.md) - -打印客户端:[https://gitee.com/CcSimple/electron-hiprint](https://gitee.com/CcSimple/electron-hiprint) - -中转服务:[https://github.com/Xavier9896/node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) +> [!IMPORTANT] +> +> **注意事项** +> +> - NodeJs 需要 16.x 版本 (开发使用 16.18.1) +> -
【vue-plugin-hiprint】与【hiprint.io官网】差异甚多,请忽混用!请忽混用!请忽混用!
+> -
请使用项目关联的打印客户端,或者自行修改打印客户端的源码,以适配本项目的模板!
+> - 主分支是融合版本的最新代码,如果你不需要修改 hiprint 相关代码. 请使用 npm 包的方式安装. +> - 使用直接客户端时,本地开发连接没问题,部署到线上出现跨域无法连接打印客户端问题: +> - [线上跨域问题,请升级 https! 说明:https://www.cnblogs.com/daysme/p/15493523.html](https://www.cnblogs.com/daysme/p/15493523.html) +> - 如需提交 PR 请前往 github 合并后可自动发布 npm 包并同步代码到 gitee +> - vue-plugin-hiprint 包不包含 UI 界面,需要自行处理。如果想更快速引入请查看 [sv-print 组件库](https://www.ibujian.cn/svp/) ## 文章链接 -入门篇: [【vue-plugin-hiprint】使用-入门篇](https://mp.weixin.qq.com/s/4N4f7CkxodA-fuTJ_FbkOQ) - -进阶篇: [【vue-plugin-hiprint】使用-进阶篇](https://mp.weixin.qq.com/s/LYZP2iqV0gy4m76mttplAw) - -provider: [【vue-plugin-hiprint】如何自定义可拖拽元素 provider](https://mp.weixin.qq.com/s/n9i1j8hhVJvnlfJRPRtWog) - -打印篇: [【vue-plugin-hiprint】使用-打印篇](https://mp.weixin.qq.com/s/P-Zz8YfELmRNi4EuED4QmA) +2元快速入门: [一文彻底入门可视化打印 vue-plugin-hiprint](https://mp.weixin.qq.com/s/R8juiaQsLhMmyZebv55tUA) -参数篇: [【vue-plugin-hiprint】使用-参数篇](https://mp.weixin.qq.com/s/vfgSG62tAXn7Ot7y3x68fw) +6元解锁云打印: [三端通用的云打印方案: uniapp + nodejs中转服务!(附源码)](https://mp.weixin.qq.com/s/3_zEsr6nIYAqKdDsKqhg7A) -实战动态provider: [【vue-plugin-hiprint】实战-动态provider](https://mp.weixin.qq.com/s/UVkhul1tynjaUjdC_NaHfw) +> 更多文章见公众号、小程序(文章,服务端预览,云打印) -实战动态模板: [【vue-plugin-hiprint】实战-动态模板](https://mp.weixin.qq.com/s/JXXC9Fyy_PgPXrwh1mDBTQ) - -常见问题汇总①: [【vue-plugin-hiprint】常见问题汇总①](https://mp.weixin.qq.com/s/E-ZfuKLH3-GvKn4AosRvaw) - -常见问题汇总②: [【vue-plugin-hiprint】常见问题汇总②](https://mp.weixin.qq.com/s/UEnr24bB_P6KmpZ7iZmYvA) - -常见问题汇总③: [【vue-plugin-hiprint】常见问题汇总③](https://mp.weixin.qq.com/s/lRimQ-cjuwN3mg6RicPyag) - -## 更多参数的文档请仔细查阅文档 - -hiprint官方文档:[http://hiprint.io/docs/start](http://hiprint.io/docs/start) - -本人写的部分文档: [https://ccsimple.gitee.io/sv-print-docs/config/hiprint.html](https://ccsimple.gitee.io/sv-print-docs/config/hiprint.html) + + + + + +
## 安装使用 + ``` npm install vue-plugin-hiprint ``` ```html - - + + + + - + ``` ## 项目截图 + @@ -113,20 +107,20 @@ npm install vue-plugin-hiprint
+## 拖拽设计使用(推荐) -## 拖拽设计使用 ```javascript -import {hiprint,defaultElementTypeProvider} from 'vue-plugin-hiprint' +import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint"; // 初始化可拖拽的元素 hiprint.init({ - providers: [new defaultElementTypeProvider()] -}) + providers: [new defaultElementTypeProvider()], +}); // $('.ep-draggable-item') 包含 tid, 与上边的 provider 中的 tid 对应 才能正常拖拽生成元素 -hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item')); +hiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item")); hiprintTemplate = new hiprint.PrintTemplate({ template: {}, // 模板json - settingContainer: '#PrintElementOptionSetting', // 元素参数容器 - paginationContainer: '.hiprint-printPagination', // 多面板的容器, 实现多面板, 需要在添加一个
+ settingContainer: "#PrintElementOptionSetting", // 元素参数容器 + paginationContainer: ".hiprint-printPagination", // 多面板的容器, 实现多面板, 需要在添加一个
// ------- 下列是可选功能 ------- // ------- 下列是可选功能 ------- // ------- 下列是可选功能 ------- @@ -141,13 +135,16 @@ hiprintTemplate = new hiprint.PrintTemplate({ // 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.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) }, @@ -155,164 +152,340 @@ hiprintTemplate = new hiprint.PrintTemplate({ // 或者使用 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'}, + { 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 默认1 history: true, // 是否需要 撤销重做功能 - onDataChanged: (type, json) => { // 模板发生改变回调 + onDataChanged: (type, json) => { + // 模板发生改变回调 console.log(type); // 新增、移动、删除、修改(参数调整)、大小、旋转 console.log(json); // 返回 template }, - onUpdateError: (e) => { // 更新失败回调 + onUpdateError: (e) => { + // 更新失败回调 console.log(e); }, }); // 设计器的容器 -hiprintTemplate.design('#hiprint-printTemplate'); +hiprintTemplate.design("#hiprint-printTemplate"); ``` -## 代码模式使用 +## 代码模式使用(不推荐) ```javascript -import {hiprint, defaultElementTypeProvider} from 'vue-plugin-hiprint' +import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint"; // 引入后使用示例 hiprint.init(); // 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面 -// 想要实现拖拽设计页面,请往下看 '自定义设计' var hiprintTemplate = new hiprint.PrintTemplate(); -var panel = hiprintTemplate.addPrintPanel({ width: 100, height: 130, paperFooter: 340, paperHeader: 10 }); +var panel = hiprintTemplate.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: 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: 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.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打印,浏览器在的地方他都可以运行' } }); +panel.addPrintLongText({ + options: { + width: 180, + height: 35, + top: 90, + left: 20, + title: "长文本:hiprint是一个很好的webjs打印,浏览器在的地方他都可以运行", + }, +}); //打印 hiprintTemplate.print({}); ``` -## i18n 设置 +## vue/vue3 全局引入 -原生为简体中文,英语、德语、西班牙语、法语、意大利语、日语、俄语、繁体中文皆为 AI 机翻,欢迎帮助 [订正](https://github.com/CcSimple/vue-plugin-hiprint/tree/main/src/i18n)。 +> 全局引入,方便在任何地方不引入直接调用打印 -可在 init 时传入语言进行设置,默认为 `cn` 。 +```javascript +// main.js中 引入安装 +import { hiPrintPlugin } from "vue-plugin-hiprint"; +Vue.use(hiPrintPlugin, "$pluginName"); // $pluginName 为自定义名称 +hiPrintPlugin.disAutoConnect(); + +/// 提供的全局方法: + +// this.$pluginName == hiprint 全局对象 +let hiprintTemplate = this.$pluginName.PrintTemplate({ + template: {}, // 模板json [对象] +}); +hiprintTemplate.print({name:'i不简'}); + +/// provider 不能为null, 可以为 undefined args: 同模板对应调用 print 方法 + +// 1. 打印 +this.$print(undefined, templateJson, ...args); +this.$print(provider, templateJson, ...args); +// 2. 直接打印 +this.print2(undefined, templateJson, ...args); +this.print2(provider, templateJson, ...args); +``` + +## jQuery/uniapp 项目使用 + +> uniapp 需要嵌入到 web 浏览器中.(需要支持 window 全局对象环境) + +```html + + + + + + + + + + + + + + + + + + + + + + + + + + + + +``` + +## 常见问题 + +> 打印重叠 / 样式问题 + +```javascript +/** + * 从 在index.html添加: + * + * 或者 + * + * 以处理打印所需css, 当然你也可以自行处理 + * 比如: index.html目录下放一个print-lock.css, 然后在index.html添加: + * + */ + +// 添加自定义样式 +hiprintTemplate.print( + this.printData, + {}, + { + styleHandler: () => { + // 这里拼接成放html->head标签内的css/style + // 1.例如:使用hiprin官网的样式 + let css = + ''; + // 2.重写样式:所有文本红色 + css += ""; + return css; + }, + } +); +// 直接打印 +hiprintTemplate.print2(this.printData, { + styleHandler: () => { + // 这里拼接成放html->head标签内的css/style + // 1.例如:使用hiprin官网的样式 + let css = + ''; + // 2.重写样式:所有文本红色 + css += ""; + return css; + }, +}); +``` + +> 取消自动 socket 连接 / socket 连接报错问题 + +```javascript +/** + * 取消自动连接 + */ +// 在main.js中设置 +import { hiPrintPlugin } from "vue-plugin-hiprint"; +Vue.use(hiPrintPlugin, "$hiprint", false); +// hiPrintPlugin 同时提供了 disAutoConnect 方法 +hiPrintPlugin.disAutoConnect(); +// 在组件中使用 见: demo/design/index.vue +import { disAutoConnect, autoConnect, hiprint } from "vue-plugin-hiprint"; +disAutoConnect(); +// 同时 export了 autoConnect,disAutoConnect 方法 +/** + * 连接回调及打印 + */ +autoConnect((status, msg) => { + if (status) { + hiprintTemplate.print2(printData, { + printer: "", + title: "hiprint测试打印", + }); + } +}); +/** + * socket连接报错? + * 由于npm包更新到socket.io 3.x版本,官网提供的客户端,npm包是无法连接的 + * 请使用gitee提供的客户端, 同时gitee客户端可传更多的参数, 如是否打印颜色/打印份数/DPI等 + * 详情electron见:https://www.electronjs.org/zh/docs/latest/api/web-contents + */ +``` + +> print/print2 打印回调 + +```javascript +// 浏览器预览打印, 无法监听是否点击了 打印/取消 按钮 +hiprintTemplate.print( + this.printData, + {}, + { + callback: () => { + console.log("浏览器打印窗口已打开"); + }, + } +); +// 直接打印 +// 打印机名称: 通过 hiprintTemplate.getPrinterList() 获取 其中的 name +hiprintTemplate.print2(printData, { printer: "打印机名称", title: "打印标题" }); +hiprintTemplate.on("printSuccess", function (data) { + console.log("打印完成"); +}); +hiprintTemplate.on("printError", function (data) { + console.log("打印失败"); +}); +``` + +> 直接打印 地址端口 与 Token 设置 ```js hiprint.init({ - lang: 'en', // 设置语言 ['cn', 'en', 'de', 'es', 'fr', 'it', 'ja', 'ru', 'cn_tw'] + host: "http://localhost:17521/", // 可在此处设置连接地址与端口号 + token: "token", // 可在此处设置连接 token 可缺省 }); ``` -## 直接打印 地址端口 与 Token 设置 +## i18n 设置 ^0.0.55-beta8 + +原生为简体中文,英语、德语、西班牙语、法语、意大利语、日语、俄语、繁体中文皆为 AI 机翻,欢迎帮助 [订正](https://github.com/CcSimple/vue-plugin-hiprint/tree/main/src/i18n)。 + +可在 init 时传入语言进行设置,默认为 `cn` 。 ```js hiprint.init({ - host: 'http://localhost:17521/', // 可在此处设置连接地址与端口号 - token: 'token', // 可在此处设置连接 token 可缺省 + lang: "en", // 设置语言 ['cn', 'en', 'de', 'es', 'fr', 'it', 'ja', 'ru', 'cn_tw'] }); ``` -## vue/vue3 全局引入 +## 参与项目 -> 全局引入,方便在任何地方不引入直接调用打印。示例为代码模式 (拖拽设计请往下看) +```console +git clone https://gitee.com/CcSimple/vue-plugin-hiprint.git -```javascript -// main.js中 引入安装 -import {hiPrintPlugin} from 'vue-plugin-hiprint' -Vue.use(hiPrintPlugin, '$pluginName') -hiPrintPlugin.disAutoConnect(); // 取消自动连接直接打印客户端 +// init +cd vue-plugin-hiprint && npm i -// 下列代码为示例,不要再 main.js中 使用 -// 引入后使用示例 -this.$pluginName.init(); -// 下列方法都是没有拖拽设计页面的, 相当于代码模式, 使用代码设计页面 -// 想要实现拖拽设计页面,请往下看 '自定义设计' -var hiprintTemplate = new this.$pluginName.PrintTemplate(); -var panel = hiprintTemplate.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打印,浏览器在的地方他都可以运行' } }); -//表格 -panel.addPrintTable({ options: { width: 252, height: 35, top: 130, left: 20, content: $('#testTable').html() } }); -//Html -panel.addPrintHtml({ options: { width: 140, height: 35, top: 180, left: 20, content:'' } }); -//竖线//不设置宽度 -panel.addPrintVline({ options: { height: 35, top: 230, left: 20 } }); -//横线 //不设置高度 -panel.addPrintHline({ options: { width: 140, top: 245, left: 120 } }); -//矩形 -panel.addPrintRect({ options: { width: 35, height: 35, top: 230, left: 60 } }); -//打印 -hiprintTemplate.print({}); -//直接打印,需要安装客户端 -hiprintTemplate.print2({}); -``` +// 调试预览demo +npm run serve -## jQuery/uniapp 项目使用 +// 打包demo (打包后生成在 demo 目录) +npm run build-demo -> uniapp 需要嵌入到 web 浏览器中.(需要支持 window 全局对象环境) +// 打包插件(vue-plugin-hiprint 插件资源) +npm run build +``` -```html - - - - - - - - - - - - - - - - - - - - - - - - +## demo 调试(显示打印 iframe) + +```javascript +// 快速显示/隐藏 打印iframe 方便调试  ̄□ ̄|| +// 在浏览器控制台输入: +// 显示打印页面 +$("#app").css("display", "none"); +$("#hiwprint_iframe").css("visibility", "visible"); +$("#hiwprint_iframe").css("width", "100%"); +$("#hiwprint_iframe").css("height", "251.09mm"); // 这里替换个实际高度才能显示完 +// 显示vue页面 +$("#app").css("display", "block"); +$("#hiwprint_iframe").css("visibility", "hidden"); ``` -## 配套直接打印客户端(win/mac/linux)[源码链接](https://gitee.com/CcSimple/electron-hiprint) -
如果使用npm包或者本项目,请使用如下样子的直接打印客户端
-
+## 配套直接打印客户端[electron-hiprint](https://gitee.com/CcSimple/electron-hiprint) -![image](./res/tool.jpeg) +### [electron-hiprint api](./apiDoc.md) -
-
本项目需要上面样式的直接打印客户端; 下载地址:
+> 使用本项目,请使用如下样子的直接打印客户端 + +支持 win、mac、linux 系统 -> [https://gitee.com/CcSimple/electron-hiprint/releases](https://gitee.com/CcSimple/electron-hiprint/releases) +> [国内 Gitee 下载](https://gitee.com/CcSimple/electron-hiprint/releases)

[Github 下载](https://github.com/CcSimple/electron-hiprint/releases) + +![image](./res/tool.jpeg) ### URLScheme `hiprint://` + > 安装客户端时请 `以管理员身份运行` ,才能成功添加 URLScheme 使用:浏览器地址栏输入 `hiprint://` 并回车 @@ -321,10 +494,14 @@ hiprintTemplate.print2({}); ```js // js -window.open("hiprint://") +window.open("hiprint://"); // element-ui -this.$alert(`连接【${hiwebSocket.host}】失败!
请确保目标服务器已 下载 运行 打印服务!`, "客户端未连接", {dangerouslyUseHtmlString: true}) +this.$alert( + `连接【${hiwebSocket.host}】失败!
请确保目标服务器已 下载 运行 打印服务!`, + "客户端未连接", + { dangerouslyUseHtmlString: true } +); // ant-design this.$error({ @@ -339,9 +516,7 @@ this.$error({ target="_blank" > 下载 - - 并 - + 运行 打印服务! @@ -357,16 +532,16 @@ this.$error({ 连接中转服务只需要修改 host, 添加 token ```js -import { hiprint } from 'vue-plugin-hiprint' +import { hiprint } from "vue-plugin-hiprint"; hiprint.init({ - host: 'https://printjs.cn:17521/', // 此处输入服务启动后的地址 - token: 'vue-plugin-hiprint', // 用于鉴权的token + host: "https://v4.printjs.cn:17521/", // 此处输入服务启动后的地址 + token: "hiprint-17521", // 用于鉴权的token,hiprint* (*可替换为[0-9a-zA-Z\-_]字符) }); // or -hiwebSocket.setHost("https://printjs.cn:17521/", "vue-plugin-hiprint") +hiwebSocket.setHost("https://printjs.cn:17521/", "vue-plugin-hiprint"); ``` 具体使用请转至 [node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) @@ -376,220 +551,94 @@ hiwebSocket.setHost("https://printjs.cn:17521/", "vue-plugin-hiprint") 1. 你可以从 `hiwebSocket` 中获取到 `clients`、`printerList` ,里面都将包含 `client` 信息 2. print2、ippRequest、ippRequest api options 中需要添加 `client` 指定客户端 - eg: - ```js - var clientId = "AlBaUCNs3AIMFPLZAAAh" - var client = hiwebSocket.clients[clientId] - var printer = hiwebSocket.printerList[0] + eg: - hiprintTemplate.print2(printData, { client: clientId, printer: client.printerList[n].name, title: 'hiprint测试打印' }); + ```js + var clientId = "AlBaUCNs3AIMFPLZAAAh"; + var client = hiwebSocket.clients[clientId]; + var printer = hiwebSocket.printerList[0]; - hiprintTemplate.print2(printData, { client: printer.clientId, printer: printer.name, title: 'hiprint测试打印' }); - ``` - > 如果你不提供 client 中转服务将抛出一个 error + hiprintTemplate.print2(printData, { + client: clientId, + printer: client.printerList[n].name, + title: "hiprint测试打印", + }); -## 常见问题 + hiprintTemplate.print2(printData, { + client: printer.clientId, + printer: printer.name, + title: "hiprint测试打印", + }); + ``` -> 可能花几分钟读一读下面的文章就能找到你遇到的问题: + > 如果你不提供 client 中转服务将抛出一个 error -常见问题汇总①: [【vue-plugin-hiprint】常见问题汇总①](https://mp.weixin.qq.com/s/E-ZfuKLH3-GvKn4AosRvaw) +## 插件生态 -常见问题汇总②: [【vue-plugin-hiprint】常见问题汇总②](https://mp.weixin.qq.com/s/UEnr24bB_P6KmpZ7iZmYvA) +| 项目名称 | 项目地址 | 下载地址 | 描述 | +| ------------------------ | ------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------- | ------------------------------------------------------------------ | +| vue-plugin-hiprint | [github](https://github.com/CcSimple/vue-plugin-hiprint)、[gitee](https://gitee.com/CcSimple/vue-plugin-hiprint) | [npm](https://www.npmjs.com/package/vue-plugin-hiprint) | 打印设计器 | +| electron-hiprint | [github](https://github.com/CcSimple/electron-hiprint)、[gitee](https://gitee.com/CcSimple/electron-hiprint) | [releases](https://github.com/CcSimple/electron-hiprint/releases) | 直接打印客户端 | +| node-hiprint-transit | [github](https://github.com/Xavier9896/node-hiprint-transit)、[gitee](https://gitee.com/Xavier9896/node-hiprint-transit) | [releases](https://github.com/Xavier9896/node-hiprint-transit/releases) | web 与客户端中转服务 Node 实现 | +| hiprint-transporter-java | [github](https://github.com/LyingDoc/hiprint-transit-java)、[gitee](https://gitee.com/dut_cc/hiprint-transporter-java) | - | web 与客户端中转服务 Java 实现 | +| hiprint-transit-java | [github](https://github.com/weaponready/hiprint-transit-java) | - | web 与客户端中转服务 Java 实现 | +| uni-app-hiprint | [github](https://github.com/Xavier9896/uni-app-hiprint) | - | uni-app 项目通过 webview 使用 vue-plugin-hiprint demo | +| node-hiprint-pdf | [github](https://github.com/CcSimple/node-hiprint-pdf) | - | 提供通过 node 对 vue-plugin-hiprint 模板生成 矢量 pdf、image、html | -常见问题汇总③: [【vue-plugin-hiprint】常见问题汇总③](https://mp.weixin.qq.com/s/lRimQ-cjuwN3mg6RicPyag) -> design时怎么修改默认图片? -```vue - - - - - -``` -> print/print2 打印回调 -```javascript -// 浏览器预览打印 -hiprintTemplate.print(this.printData, {}, { - callback: () => { - console.log('浏览器打印窗口已打开') - } -}) -// 直接打印 -// 打印机名称: 通过 hiprintTemplate.getPrinterList() 获取 其中的 name -hiprintTemplate.print2(printData, {printer: '打印机名称', title: '打印标题'}) -hiprintTemplate.on('printSuccess', function (data) { - console.log('打印完成') -}) -hiprintTemplate.on('printError', function (data) { - console.log('打印失败') -}) -``` -> 打印重叠 / 样式问题 -```javascript -/** - * 从 0.0.19 起, 在index.html添加: - * - * 以处理打印所需css, 当然你也可以自行处理 - * 比如: index.html目录下放一个print-lock.css, 然后在index.html添加: - * - */ - -// 添加自定义样式 -hiprintTemplate.print(this.printData, {}, { - styleHandler: () => { - // 这里拼接成放html->head标签内的css/style - // 1.例如:使用hiprin官网的样式 - let css = '' - // 2.重写样式:所有文本红色 - css += '' - return css - } -}) -// 直接打印 -hiprintTemplate.print2(this.printData, { - styleHandler: () => { - // 这里拼接成放html->head标签内的css/style - // 1.例如:使用hiprin官网的样式 - let css = '' - // 2.重写样式:所有文本红色 - css += '' - return css - } -}) -``` -> 修改默认配置 / 显示/隐藏元素设置参数 -```javascript -// 0.0.13, 新增setConfig方法 -// 还原配置 -hiprint.setConfig() -// 替换配置 -hiprint.setConfig({ - movingDistance: 2.5, - text:{ - supportOptions: [ - { - name: 'styler', - hidden: true - }, - { - name: 'formatter', - hidden: true - }, - ] - } -}) -``` -> 取消自动socket连接 / socket连接报错问题 -```javascript -/** - * 取消自动连接 - */ -// 在main.js中设置 -import {hiPrintPlugin} from 'vue-plugin-hiprint' -Vue.use(hiPrintPlugin,'$hiprint', false); -// hiPrintPlugin 同时提供了 disAutoConnect 方法 -hiPrintPlugin.disAutoConnect(); -// 在组件中使用 见: demo/design/index.vue -import {disAutoConnect, autoConnect, hiprint} from 'vue-plugin-hiprint' -disAutoConnect(); -// 同时 export了 autoConnect,disAutoConnect 方法 -/** - * 连接回调及打印 - */ -autoConnect((status,msg) => { - if (status) { - hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'}); - } -}); -/** - * socket连接报错? - * 由于npm包更新到socket.io 3.x版本,官网提供的客户端,npm包是无法连接的 - * 请使用gitee提供的客户端, 同时gitee客户端可传更多的参数, 如是否打印颜色/打印份数/DPI等 - * 详情electron见:https://www.electronjs.org/zh/docs/latest/api/web-contents - */ -``` - -## 参与项目 -```console -git clone https://gitee.com/CcSimple/vue-plugin-hiprint.git -// init -cd vue-plugin-hiprint -npm i -// 调试预览 -npm run serve -// 打包 -npm run build -``` -## demo调试(显示打印iframe) -```javascript -// 快速显示/隐藏 打印iframe 方便调试  ̄□ ̄|| -// 在浏览器控制台输入: -// 显示打印页面 -$('#app').css('display','none'); -$('#hiwprint_iframe').css('visibility','visible'); -$('#hiwprint_iframe').css('width','100%'); -$('#hiwprint_iframe').css('height','251.09mm'); // 这里替换个实际高度才能显示完 -// 显示vue页面 -$('#app').css('display','block'); -$('#hiwprint_iframe').css('visibility','hidden'); -``` +> 带 * 项目为周边社区维护项目,更新迭代、兼容性、稳定性无法得到保证。 ## 交流群 + - - + +
-> 群人数已超过200 请 '加我好友' 备注加群, 邀你进群 +> 群人数已超过 200 请 '加我好友' 备注加群, 邀你进群 -## 捐赠支持, 或者请我喝杯咖啡☕️ +## 捐赠支持, 或者请我喝杯咖啡 ☕️ -> 如果对您有帮助,请点击右上角⭐Star关注或扫码捐赠,感谢支持开源! +> 如果对您有帮助,请点击右上角 ⭐Star 关注或扫码捐赠,感谢支持开源! - - + +
-## 状态/调整/优化 请查看[更新记录](CHANGELOG.md) - 本项目使用 开发 +## Star History + +[![Star History Chart](https://api.star-history.com/svg?repos=CcSimple/vue-plugin-hiprint&type=Date)](https://star-history.com/#CcSimple/vue-plugin-hiprint&Date) + ## 分支说明 -> main: vue2.x + ant1.7.x融合版 及 npm包源代码 -> npm_demo: vue2.x + ant1.7.x + npm包使用 示例 +> main: vue2.x + ant1.7.x 融合版 及 npm 包源代码 + +> npm_demo: vue2.x + ant1.7.x + npm 包使用 示例 -> npm_demo_ele: vue2.x + ElementUi 2.x + npm包使用 示例 +> npm_demo_ele: vue2.x + ElementUi 2.x + npm 包使用 示例 -> npm_demo_v3: vue3.x + vite + npm包(0.0.18)使用 示例 +> npm_demo_v3: vue3.x + vite + npm 包(0.0.18)使用 示例 ## 关于如何融合处理 + > 自己融合请查看 vue.config.js 对比 hiprint.bundle.js -> webpack.config.js,是npm打包需要处理的 +> webpack.config.js,是 npm 打包需要处理的 ## 开源使用说明 -> npm包是基于hiprint官网2.5.4版本基础做的调整及优化;
+ +> npm 包是基于 hiprint 官网 2.5.4 版本基础做的调整及优化;
> 本人对开源协议理解有限,如有侵权不合理的地方,请联系告知我;
hiprint 开源协议如下: + ``` /** * jQuery Hiprint 2.5.4 @@ -602,7 +651,7 @@ hiprint 开源协议如下: */ ``` -## 关于LGPL协议 +## 关于 LGPL 协议 ``` LGPL是GPL的一个为主要为类库使用设计的开源协议。和GPL要求任何使用/修改/衍生之GPL类库的的软件必须采用GPL协议不同。 diff --git a/apiDoc.md b/apiDoc.md new file mode 100644 index 00000000..193d78cd --- /dev/null +++ b/apiDoc.md @@ -0,0 +1,506 @@ +# 连接客户端、中转文档 + +## 1. 连接客户端或中转 + +### 1.1 hiprint init 时入参 `host`、`token` + +```js +hiprint.init({ + ...otherOptions, + host: "http://localhost:17521/", // 桌面客户端地址 + token: "vue-plugin-hiprint", // 客户端设置的令牌 +}); +``` + +### 1.2 调用 hiwebsocket 提供的 api + +```js +hiwebSocket.setHost( + "http://localhost:17521/", + "vue-plugin-hiprint", + // callback + (connect) => { + if (connect) { + console.log("连接成功"); + // do something after connected + } else { + console.log("连接失败"); + } + } +); +``` + +### 1.3 连接中转服务器 + +```js +hiprint.init({ + ...otherOptions, + host: "https://v5.printjs.cn:17521/", // 桌面客户端地址 + token: "hiprint-17521", // 中转服务器设置的令牌 +}); + +// OR + +hiwebSocket.setHost( + "https://v5.printjs.cn:17521/", + "hiprint-17521", + // callback + (connect) => { + if (connect) { + console.log("连接成功"); + // do something after connected + } else { + console.log("连接失败"); + } + } +); +``` + +> [!TIP] +> 如果你使用公益中转服务器 [v5.printjs.cn:17521](https://github.com/Xavier9896/node-hiprint-transit#%E5%85%8D%E8%B4%B9%E6%9C%8D%E5%8A%A1-%E7%94%A8%E7%88%B1%E5%8F%91%E7%94%B5) `token` 支持通配符,请设置一个唯一的 `token` +> +> `hiprint-test-1`、`hiprint-17521`、`hiprint_10086`。 +> +> 更多中转相关信息请查看 [node-hiprint-transit](https://github.com/Xavier9896/node-hiprint-transit) 文档 + +## 2. 获取客户端或中转信息 + +### 2.1 直连客户端 + +#### 2.1.1 获取客户端信息 clientInfo + +连接成功后客户端会主动发送客户端信息到 web。 + +```js +// 连接成功的情况下从 hiwebSocket 获取客户端信息 +if (hiwebSocket.opened) { + console.log("客户端信息:", hiwebSocket.clientInfo); +} +``` + +
+ 查看示例数据 + +```js +clientInfo = { + hostname: "Admin", // 主机名 + version: "1.0.13", // 客户端版本 + platform: "win32", // 平台类型 + arch: "x64", // 系统架构 + mac: "d0:46:0c:97:4b:68", // mac 地址 + ip: "192.168.0.114", // 设备 ip + ipv6: "fe80::2157:4b26:1c2f:c4ca", // 设备 ipv6 + clientUrl: "http://192.168.0.114:17521/", // 本地服务地址 + machineId: "0e8b222e-517b-491e-883a-b6283a62e280", // 设备唯一 ID(可用于标识) + nickName: "打印客户端", // 客户端设置的友好昵称(可用于显示、标识) +}; +``` + +
+ +调用 api 获取最新的客户端信息 + +> [!TIP] +> 基本上无需调用该 API,客户端修改配置、重启会重新连接,直接从 `hiwebSocket.clientInfo` 获取即可,如果你确实需要也可以手动调用 + +```js +hiprint.getClientInfo((clientInfo) => { + console.log("最新客户端信息:", clientInfo); +}); +// OR +hiwebSocket.getClientInfo(); +hinnn.event.on("clientInfo", (clientInfo) => { + console.log("最新客户端信息:", clientInfo); +}); +``` + +#### 2.1.2 直连客户端,获取打印机列表 printerList + +连接成功后客户端会主动发送打印机列表到 web。 + +```js +// 在连接成功的情况下从 hiwebSocket 获取打印机列表 +if (hiwebSocket.opened) { + console.log("打印机列表:", hiwebSocket.printerList); +} +``` + +
+ 查看示例数据 + +```js +printerList = [ + { + description: "", + displayName: "Microsoft Print to PDF", + isDefault: true, + name: "Microsoft Print to PDF", + options: { + "printer-location": "", + "printer-make-and-model": "Microsoft Print To PDF", + system_driverinfo: + "Microsoft Print To PDF;10.0.19041.3570 (WinBuild.160101.0800);Microsoft® Windows® Operating System;10.0.19041.3570", + }, + status: 0, + }, {…}, {…} +]; +``` + +
+ +调用 api 获取最新的打印机列表 + +```js +hiprint.refreshPrinterList((printerList) => { + console.log("最新打印机列表:", printerList); +}); +// OR +hiwebSocket.refreshPrinterList(); +hinnn.event.on("printerList", (printerList) => { + console.log("最新打印机列表:", printerList); +}); +``` + +#### 2.1.3 获取纸张信息 仅 win 支持,需主动请求 + +```js +// 获取指定打印机纸张信息 +hiwebSocket.getPaperSizeInfo(printerName); +// 获取所有打印机纸张信息 +hiwebSocket.getPaperSizeInfo(); +hinnn.event.on("paperSizeInfo", (paperSize) => { + console.log(`${printerName} 纸张:`, paperSize); +}); +``` + +
+ 查看示例数据 + +```js +paperSize = [ + { + "PrinterName": "Microsoft Print to PDF", + "TaskNumber": 0, // 打印队列任务数 + "Status": 0, // 打印机状态码 + "StatusMsg": "准备就绪(Ready)", // 打印机状态信息 + "PaperSizes": [ + { + "Height": 1100, + "Kind": 1, + "PaperName": "信纸", + "RawKind": 1, + "Width": 850 + }, + {...}, {...}, {...} + ] + } +] +``` + +
+ +### 2.2 连接中转服务器 + +#### 2.2.1 获取客户端集合 clients + +连接成功后中转服务器会主动发送 clients 到 web。 + +```js +// 在连接成功的情况下从 hiwebSocket 获取客户端集合 +if (hiwebSocket.opened) { + console.log("客户端集合:", hiwebSocket.clients); +} +``` + +调用 api 获取最新的客户端集合 + +```js +hiprint.getClients((clients) => { + console.log("客户端集合:", clients); +}); +// OR +hiwebSocket.getClients(); +hinnn.event.on("clients", (clients) => { + console.log("客户端集合:", clients); +}); +``` + +
+ 查看示例数据 + +```js +paperSize = { + HB2OhMUEJuQx9YdxAAAV: { + clientId: "HB2OhMUEJuQx9YdxAAAV", + printerList: [ + { + name: "导出为WPS PDF", + displayName: "导出为WPS PDF", + description: "", + status: 0, + isDefault: false, + options: { + "printer-location": "", + "printer-make-and-model": "Kingsoft Virtual Printer Driver", + system_driverinfo: + "Kingsoft Virtual Printer Driver;0,3,0,0;WPS Office;12,1,0,19768", + }, + }, {...}, {...} + ], + hostname: "PC-2024111111", + version: "1.0.13", + platform: "win32", + arch: "x64", + mac: "aa:bb:cc:dd:ee:ff", + ip: "192.168.1.2", + ipv6: "240e:390:96a4:bb70:1486:fcc8:3ed9:42be", + clientUrl: "http://192.168.1.2:17521/", + machineId: "5a6f6a42-fb17-4b3f-bc2f-3fb104f4910a", + nickName: "打印客户端1", + }, + "wHOB6kn6JkPLV-b5AAAm": { + clientId: "wHOB6kn6JkPLV-b5AAAm", + printerList: [ + { + name: "TSC TTP-244", + displayName: "TSC TTP-244", + description: "", + status: 0, + isDefault: true, + options: { + "printer-location": "", + "printer-make-and-model": "TSC TTP-244", + system_driverinfo: + "TSC TTP-244;0.3.0.0;Seagull Printer Drivers;1.0.0", + }, + }, {...}, {...} + ], + hostname: "PC-2025111111", + version: "1.0.13", + platform: "win32", + arch: "x64", + mac: "aa:bb:cc:dd:ee:ff", + ip: "192.168.1.3", + ipv6: "fe80::99e:98ee:16f:18", + clientUrl: "http://192.168.127.111:17521/", + machineId: "48017401-113e-4394-a348-2526f0c9031b", + nickName: "打印客户端2", + }, +}; +``` + +
+ +#### 2.2.2 获取打印机列表 printerList + +连接成功后中转服务器会主动发送打印机列表到 web。 + +```js +// 在连接成功的情况下从 hiwebSocket 获取打印机列表 +if (hiwebSocket.opened) { + console.log("打印机列表:", hiwebSocket.printerList); +} +``` + +
+ 查看示例数据 + +与直连 `electron-hiprint` 类似的数据结构,不同的地方在于 `printer` 对象中会多一个 `server` 对象,该对象指示了打印机所属的客户端信息,方便可以快速根据打印机反选出客户端。 + +```diff +printerList = [ + { + name: "导出为WPS PDF", + displayName: "导出为WPS PDF", + description: "", + status: 0, + isDefault: false, + options: { + "printer-location": "", + "printer-make-and-model": "Kingsoft Virtual Printer Driver", + system_driverinfo: + "Kingsoft Virtual Printer Driver;0,3,0,0;WPS Office;12,1,0,19768", + }, ++ server: { ++ clientId: "2EhIpBydILmQRrVLAAAE", ++ hostname: "PC-2024111111", ++ version: "1.0.13", ++ platform: "win32", ++ arch: "x64", ++ mac: "fc:34:97:be:39:3f", ++ ip: "192.168.1.2", ++ ipv6: "240e:390:96a4:bb70:1486:fcc8:3ed9:42be", ++ clientUrl: "http://192.168.1.2:17521/", ++ machineId: "5a6f6a42-fb17-4b3f-bc2f-3fb104f4910a", ++ nickName: "打印客户端1", ++ }, + }, {...}, {...} +]; +``` + +
+ +## 3. 打印 + +### 3.1 直连 `electron-hiprint` 静默打印 + +#### 3.1.1 打印 hiprint 模板 + +```js +const hiprintTemplate = new hiprint.PrintTemplate({ + template: {}, // 模板json对象 +}); +// 单一模板静默打印 +hiprintTemplate.print2( + printData, // Object | Array 打印数据,数组时为批量打印 + { ...offsetOption, printer: "打印机名称", title: "打印任务名称" } +); +hiprintTemplate.on("printSuccess", (res) => { + console.log("打印成功", res); +}); +hiprintTemplate.on("printError", (err) => { + console.error("打印失败", err); +}); + +// OR + +// 多模板静默打印 +hiprint.print2( + { + templates: [ + { + template: hiprintTemplate, + data: printData, // Object | Array 打印数据,数组时为批量打印 + options: { + printer: "Microsoft Print to PDF", // 打印机名称 + copies: 2, // 打印份数 + landscape: false, // 是否横向打印 + }, + }, + // 支持多模板,在此处继续添加如上格式即可 + ], + }, + (res) => { + console.log("打印成功", res); + }, + (err) => { + console.error("打印失败", err); + } +); +``` + +#### 3.1.2 render api 获取 jpeg、pdf、打印 + +> [!TIP] +> render api 是 `electron-hiprint@^1.0.12-beta7` 扩展支持的功能,hiprint 中未对这些 api 提供内置,直接调用 `hiwebSocket.socket` 发送即可。 +> +> 详见 [模板+data 或 html 返回 jpeg、pdf、打印](https://github.com/CcSimple/electron-hiprint#%E6%A8%A1%E6%9D%BFdata-%E6%88%96-html-%E8%BF%94%E5%9B%9E-jpegpdf%E6%89%93%E5%8D%B0) + +```js +const socket = hiwebSocket.socket; +socket.emit("render-jpeg", { + template: panel, // 模板对象 + data: printData, // Object打印数据 +}); +socket.emit("render-jpeg", { + html: "html字符串", // html 字符串 +}); +socket.on("render-jpeg-success", (data) => { + // data.buffer +}); +socket.on("render-jpeg-error", (data) => { + // data.msg +}); +``` + +### 3.2 中转打印 + +> [!IMPORTANT] +> +> 前置条件,获取 `clients`,参考 [2.2.1 获取客户端集合 clients](#221-获取客户端集合-clients) + +#### 3.2.1 打印 hiprint 模板 + +```js +const hiprintTemplate = new hiprint.PrintTemplate({ + template: {}, // 模板json对象 +}); +// 单一模板静默打印 +hiprintTemplate.print2( + printData, // Object | Array 打印数据,数组时为批量打印 + { + client: "HB2OhMUEJuQx9YdxAAAV", // 客户端 ID + printer: "打印机名称", + title: "打印任务名称", + } +); +hiprintTemplate.on("printSuccess", (res) => { + console.log("打印成功", res); +}); +hiprintTemplate.on("printError", (err) => { + console.error("打印失败", err); +}); + +// OR + +// 多模板静默打印 +hiprint.print2( + { + templates: [ + { + template: hiprintTemplate, + data: printData, // Object | Array 打印数据,数组时为批量打印 + options: { + printer: "Microsoft Print to PDF", // 打印机名称 + copies: 2, // 打印份数 + landscape: false, // 是否横向打印 + }, + }, + // 支持多模板,在此处继续添加如上格式即可 + ], + options: { + client: "HB2OhMUEJuQx9YdxAAAV", // 客户端 ID + }, + }, + (res) => { + console.log("打印成功", res); + }, + (err) => { + console.error("打印失败", err); + } +); +``` + +#### 3.2.2 render api 获取 jpeg、pdf、打印 + +> [!TIP] +> render api 是 `electron-hiprint@^1.0.12-beta7` 扩展支持的功能,hiprint 中未对这些 api 提供内置,直接调用 `hiwebSocket.socket` 发送即可。 +> +> 详见 [模板+data 或 html 返回 jpeg、pdf、打印](https://github.com/CcSimple/electron-hiprint#%E6%A8%A1%E6%9D%BFdata-%E6%88%96-html-%E8%BF%94%E5%9B%9E-jpegpdf%E6%89%93%E5%8D%B0) + +```js +const socket = hiwebSocket.socket; +socket.emit("render-jpeg", { + clientId: "HB2OhMUEJuQx9YdxAAAV", // 客户端 ID + template: panel, // 模板对象 + data: printData, // Object打印数据 +}); +socket.emit("render-jpeg", { + clientId: "HB2OhMUEJuQx9YdxAAAV", // 客户端 ID + html: "html字符串", // html 字符串 +}); +socket.on("render-jpeg-success", (data) => { + // data.buffer +}); +socket.on("render-jpeg-error", (data) => { + // data.msg +}); +``` + +## 4. 写在最后 + +[hiprint](https://github.com/hinnncom/hiprint) 原包中并没有内置 [socket.io-client](https://socket.io/zh-CN/docs/v4/client-api/),`vue-plugin-hiprint` 默认内置,并提供 `print2`、`refreshPrinterList` 等 api 旨在方便用户,但 api 文档四纷五落,虽然 `electron-hiprint` 有非常全面的 api 文档,但不少用户反馈 `vue-plugin-hiprint`、`electron-hiprint` 和 `node-hiprint-transit` 的文档各有不同,不知道应该以哪个为尊,故此次对 `vue-plugin-hiprint` api 文档进行编写完善。 + +本质上所有 API 都只需要获取到 `hiwebSocket.socket` 按 `electron-hiprint` 文档调用即可。 + +以上内容如有错误,欢迎 PR 或 issue 指正。 \ No newline at end of file diff --git a/package.json b/package.json index 3103deeb..04d3fa11 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vue-plugin-hiprint", "description": "hiprint for Vue2.x / Vue3.x 支持拖拽(分页(不分页)、表头表脚、样式设置、复制粘贴、缩放、撤销重做)生成打印模板、导出json模板数据、静默打印/获取MAC地址(借助客户端)", - "version": "0.0.57-beta26", + "version": "0.0.61-beta3", "author": "CcSimple", "license": "MIT", "main": "dist/vue-plugin-hiprint.js", @@ -30,7 +30,7 @@ "pub-beta": "npm run build && npm --registry https://registry.npmjs.org/ publish --tag beta" }, "engines": { - "node": "16.x" + "node": ">=16" }, "browserslist": [ "> 1%", diff --git a/public/static/template8.png b/public/static/template8.png new file mode 100644 index 00000000..faab1578 Binary files /dev/null and b/public/static/template8.png differ diff --git a/res/wmp.jpg b/res/wmp.jpg new file mode 100644 index 00000000..8dc52428 Binary files /dev/null and b/res/wmp.jpg differ diff --git a/res/ww.png b/res/ww.png new file mode 100644 index 00000000..1ad7ce54 Binary files /dev/null and b/res/ww.png differ diff --git a/src/demo/design/index.vue b/src/demo/design/index.vue index 67936ca2..4f18cd71 100644 --- a/src/demo/design/index.vue +++ b/src/demo/design/index.vue @@ -40,15 +40,6 @@ 预览 - - 直接打印 - - - Api单独打印 - - - Api单独直接打印 - + + + 都不看,我就不看 + {{ item.name }} + + 更多功能示例 + + + - + +
直接打印/api打印:
+ + 直接打印 + + + 分批直接打印 + + + Api单独打印 + + + Api单独直接打印 + +
+ +
导出PDF文件/流:
导出获取pdf(Blob) @@ -83,7 +99,8 @@ 导出查看pdf(PdfObjectNewWindow)
- + +
ipp打印(需打印机支持):
ipp获取 打印机 参数情况 @@ -96,7 +113,9 @@ ipp请求 打印测试 -
元素参数操作:
+
+ +
元素参数操作:
测试隐藏参数[看代码] 隐藏[文本] "边框"、"高级" @@ -110,7 +129,8 @@ 还原配置
- + +
模板导入导出:
@@ -122,7 +142,8 @@
- + +
元素获取/更新参数:
获取选中元素 @@ -136,7 +157,9 @@ 选中元素字体Bolder -
选中元素后点击:
+
+ +
元素对齐/间距(需先选中):
水平间距10 垂直间距10 @@ -325,7 +348,7 @@ import printPreview from './preview' import jsonView from "../json-view.vue"; import fontSize from "./font-size.js"; import scale from "./scale.js"; -import { decodeVer } from '@/utils' +import {decodeVer} from '@/utils' // disAutoConnect(); var hiprint, defaultElementTypeProvider, panel; let hiprintTemplate; @@ -378,6 +401,17 @@ export default { // 导入导出json jsonIn: '', jsonOut: '', + // 功能 + curKey: '', + keyList: [ + {key: 1, name: '直接打印/api打印'}, + {key: 2, name: '导出PDF文件/流'}, + {key: 3, name: 'ipp打印(需打印机支持)'}, + {key: 4, name: '元素参数操作'}, + {key: 5, name: '模板导入导出'}, + {key: 6, name: '元素获取/更新参数'}, + {key: 7, name: '元素对齐/间距(需先选中)'}, + ], } }, computed: { @@ -888,11 +922,36 @@ export default { ), }); }, + handleMenuClick(e) { + const {key} = e; + this.curKey = key; + }, print() { - if (window.hiwebSocket.opened) { + this.doOperationWhenClientConnected(() => { const printerList = hiprintTemplate.getPrinterList(); console.log(printerList) hiprintTemplate.print2(printData, {printer: '', title: 'hiprint测试打印'}); + }) + }, + printByFragments() { + this.doOperationWhenClientConnected(() => { + const dataList = new Array(50).fill(printData) + // 原有方法打印不成功,原因是获取HTML的方法处理时间过长,导致超过socket心跳间隔 + // hiprintTemplate.print2(dataList, {printer: '', title: 'hiprint测试打印'}); + hiprintTemplate.print2(dataList, { + printer: '', + title: 'hiprint测试打印', + printByFragments: true, // 是否需要分批打印,分批打印能够支持连续打印大量数据,但会增加打印所需时间 + // generateHTMLInterval: 30, // 多条数据生成HTML的间隔,单位ms,默认是10 + // fragmentSize: 10000, // 分片字符长度,默认50000 + // sendInterval: 20, // 分片传输间隔,单位ms,默认10 + // type: 'pdf', + }); + }) + }, + doOperationWhenClientConnected(operation) { + if (window.hiwebSocket.opened) { + operation?.() return } this.$error({ @@ -1100,6 +1159,13 @@ export default { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
入职信息登记表
入职部门:\\\${d.department}入职岗位:\\\${d.position}填表时间:\\\${d.form_date}
姓名\\\${d.pInfo.name}性别\\\${d.pInfo.gender}出生年月\\\${d.pInfo.birth_date}贴照片处
籍贯\\\${d.pInfo.place_of_birth}民族\\\${d.pInfo.ethnicity}政治面貌\\\${d.pInfo.political_affiliation}
文化程度\\\${d.pInfo.education_level}专业\\\${d.pInfo.major}毕业时间\\\${d.pInfo.graduation_year}
身高\\\${d.pInfo.height}体重\\\${d.pInfo.weight}血型\\\${d.pInfo.blood_type}
家庭住址\\\${d.pInfo.address}
联系电话\\\${d.pInfo.phone}电子邮箱\\\${d.pInfo.email}
期望薪资\\\${d.pInfo.expected_salary}到岗时间\\\${d.pInfo.availability}
语言能力普通话\\\${d.pInfo.mandarin_level}外语\\\${d.pInfo.foreign_language_level}
其他
\` + +// ! 这里的处理很关键 +if (d) { + return html.replace(/\\$\{(\\S+)\}/g, (match, key) => { + return eval(key); + }); +} else { + return html; +} +// ! 这里的处理很关键 + }`, + }, + printElementType: { title: "html", type: "html" }, + }, + { + options: { + left: 12, + top: 460, + height: 45, + width: 566, + title: + "说明:此处模版使用 HTML 元素生成动态表格,方便实现自定义表格,减少拖拽生成表格的繁琐操作,你可以使用 www.lingdaima.com/table 对 EXCEL 进行转换,转换前既可在 excel 中预填字段 ${prop},模板 EXCEL: https://docs.qq.com/document/DUlFUYVh5aWVHVWZX", + }, + printElementType: { title: "说明", type: "longText" }, + }, + { + options: { + left: 12, + top: 505, + height: 24, + width: 566, + color: "#FF0000", + title: + "注意:www.lingdaima.com/table 提供的转换服务会一直转圈,但你仍可从 f12 网络面板中获取到转换后的 html 代码,你需要对转换后的 td 样式进行修改,并且需要转义 模版字符串 \\\\\\\${} 否知你将无法实现该 demo 效果!", + }, + printElementType: { title: "注意", type: "longText" }, + }, + ], + paperNumberLeft: 565.5, + paperNumberTop: 819, + paperNumberContinue: true, + watermarkOptions: {}, + }, + ], +}; +export default { + preview: preview, + name: name, + desc: desc, + author: author, + link: link, + printData: printData, + json: json, +}; diff --git a/src/hiprint/hiprint.bundle.js b/src/hiprint/hiprint.bundle.js index 72fc879c..1bdebbe5 100644 --- a/src/hiprint/hiprint.bundle.js +++ b/src/hiprint/hiprint.bundle.js @@ -316,7 +316,7 @@ var hiprint = function (t) { return this.orderBy(o, e).concat([i], this.orderBy(r, e)); }, hinnn.dateFormat = function (t, e) { if (t) try { - var o = "string" == typeof t ? new Date(t) : t; + var o = new Date(`${t}`); var n = { "y+": o.getFullYear(), "M+": o.getMonth() + 1, @@ -564,7 +564,7 @@ var hiprint = function (t) { } return d; }, t.prototype.getLeft = function () { - return this.left; + return this.left - 0; }, t.prototype.posLeft = function () { var left = this.left; if (this.transform) left += this.getRectInfo().diffW; @@ -579,7 +579,7 @@ var hiprint = function (t) { }, t.prototype.setLeft = function (t) { null != t && (this.left = t); }, t.prototype.getTop = function () { - return this.top; + return this.top - 0; }, t.prototype.posTop = function () { var top = this.top; if (this.transform) top += this.getRectInfo().diffH; @@ -600,7 +600,7 @@ var hiprint = function (t) { var i = this.getRectInfo(); return i.h + i.diffH; } - return this.height; + return this.height - 0; }, t.prototype.displayHeight = function () { return this.height + "pt"; }, t.prototype.setHeight = function (t) { @@ -610,7 +610,7 @@ var hiprint = function (t) { var i = this.getRectInfo(); return i.w + i.diffW; } - return this.width; + return this.width - 0; }, t.prototype.displayWidth = function () { return this.width + "pt"; }, t.prototype.setWidth = function (t) { @@ -1791,7 +1791,7 @@ var hiprint = function (t) { r(a); } return TableExcelHelper.syncTargetWidthToOption(t), [i, colgroup]; - }, TableExcelHelper.createTableFooter = function (t, e, n, i, o, r) { + }, TableExcelHelper.createTableFooter = function (t, e, n, i, o, r, pageIndex) { // n=>options e=>表格所有数据 o=>所有打印数据 r=>表格每页数据 var a = $(""), p = this.getFooterFormatter(n, i); var tst = this.tableSummaryTitle; @@ -1870,7 +1870,8 @@ var hiprint = function (t) { a.append(tableFooter); } if (p) { - a.append(p(n, e, o, r)); + // pageIndex: 当前页码(0开始) 如果表格脚最后页显示,则中间回调 undefined + a.append(p(n, e, o, r, pageIndex)); } return a; }, TableExcelHelper.tableSummaryTitle = function (column, title, data) { @@ -1881,8 +1882,10 @@ var hiprint = function (t) { var o = TableExcelHelper.reconsitutionTableColumnTree(t), r = $(""); var gff = h.getGroupFieldsFormatter(n, i); + var groupRowIndex = 0; var groupFields = gff ? (n.groupFields = gff(i, n, e)) : i.groupFields ? i.groupFields : []; - (e || (e = []), groupFields.length) ? _assets_plugins_hinnn__WEBPACK_IMPORTED_MODULE_1__.a.groupBy(e, groupFields, function (t) { + e = Array.isArray(e) ? e : []; + groupFields.length ? _assets_plugins_hinnn__WEBPACK_IMPORTED_MODULE_1__.a.groupBy(e, groupFields, function (t) { var e = {}; return groupFields.forEach(function (n) { return e[n] = t[n]; @@ -1902,8 +1905,10 @@ var hiprint = function (t) { var groupFooterFormatter = h.getGroupFooterFormatter(n, i); var groupData = t; if (groupData.rows.forEach(function (t, rowIndex) { - var e = TableExcelHelper.createRowTarget(o, t, n, i, rowIndex, groupData.rows, printData); + let sequenceIndex = n.groupSequenceContinue ? groupRowIndex : rowIndex; + var e = TableExcelHelper.createRowTarget(o, t, n, i, sequenceIndex, groupData.rows, printData); r.append(e); + groupRowIndex += 1; }), groupFooterFormatter) { let result = groupFooterFormatter(o.colspan, e, printData, t, n) if ($(result).is("tr")) { @@ -1990,6 +1995,7 @@ var hiprint = function (t) { var imagebox = $('
') imagebox.find('img').attr('src', p) + imagebox.find('img').attr("height", t.tableColumnHeight || 50 + 'pt') console.log(imagebox.find('img').css('width')) r.html(imagebox) } @@ -2745,6 +2751,22 @@ var hiprint = function (t) { this.target.remove(); }, t; }(), + barTextMode = function () { + function t() { + this.name = "barTextMode"; + } + return t.prototype.createTarget = function() { + this.target = $(`
${i18n.__('条码文本模式')}
`) + return this.target; + }, t.prototype.getValue = function() { + var t = this.target.find("select").val(); + return t || void 0; + }, t.prototype.setValue = function(t) { + this.target.find("select").val(t) + }, t.prototype.destroy = function() { + this.target.remove() + }, t; + }(), barWidth = function () { function t() { this.name = "barWidth"; @@ -5073,7 +5095,7 @@ var hiprint = function (t) { } return t.prototype.createTarget = function () { - return this.target = $(`
\n
\n ${i18n.__('表格脚函数')}\n
\n
\n \n
\n
`), this.target; + return this.target = $(`
\n
\n ${i18n.__('表格脚函数')}\n
\n
\n \n
\n
`), this.target; }, t.prototype.getValue = function () { var t = this.target.find("textarea").val(); if (t) return t; @@ -5083,6 +5105,21 @@ var hiprint = function (t) { this.target.remove(); }, t; }(), + groupSequenceContinue = function () { + function t() { + this.name = "groupSequenceContinue"; + } + + return t.prototype.createTarget = function () { + return this.target = $(`
\n
\n ${i18n.__('分组序号续编')}\n
\n
\n \n
\n
`), this.target; + }, t.prototype.getValue = function () { + if ("true" == this.target.find("select").val()) return !0; + }, t.prototype.setValue = function (t) { + this.target.find("select").val((null == t ? "" : t).toString()); + }, t.prototype.destroy = function () { + this.target.remove(); + }, t; + }(), groupFieldsFormatter = function () { function t() { this.name = "groupFieldsFormatter"; @@ -5340,7 +5377,7 @@ var hiprint = function (t) { t.init(), t.printElementOptionItems[e.name] = e; }, t.getItem = function (e) { return t.init(), t.printElementOptionItems[e]; - }, t._printElementOptionItems = [new fontFamily(), new r(), new a(), new p(), new i(), new s(), new l(), new pt(), new u(), new d(), new c(), new h(), new f(), new g(), new m(), new d2(), new c2(), new v(), new y(), new b(), new E(), new qrCodeLevel(), new T(), new P(), new _(), new w(), new x(), new coordinate(), new widthHeight(), new C(), new imageFit(), new O(), new H(), new D(), new paperNumberContinue(), new watermarkOptions(), new I(), new R(), new pageBreak(), new M(), new M2(), new S(), new B(), new F(), new L(), new A(), new z(), new k(), new st(), new N(), new V(), new W(), new j(), new U(), new borderRadius(), new zIndex(), new K(), new G(), new q(), new X(), new Y(), new Q(), new J(), new Z(), new tt(), new et(), new nt(), new it(), new ot(),new textWrap(), new at(), new lt(), new panelLayoutOptions(), new ut(), new ith(), new dt(), new ct(), new ht(), new ft(), new gt(), new mt(), new rowcolumns(), new rowsColumnsMergeClean(), new groupFieldsFormatter(), new groupFormatter(), new groupFooterFormatter(), new vt(), new yt(), new bt(), new Tt(), new Et(), new Pt(), new stylerHeader(), new renderFormatter(), new _t(), new wt(), new maxRows(), new xt(), new tableColumnH(), new tableE(), new tableQRCodeLevel(), new tablept(), new tableSummaryTitle(), new tableSummaryText(), new tableSummaryColspan(), new tableSummary(), new tableSummaryAlign(), new tableSummaryNumFormat(), new tableSummaryFormatter(),new showCodeTitle(), new upperCase(), new barcodeType(), new qrcodeType(), new barColor(), new barWidth(), new barAutoWidth()], t; + }, t._printElementOptionItems = [new fontFamily(), new r(), new a(), new p(), new i(), new s(), new l(), new pt(), new u(), new d(), new c(), new h(), new f(), new g(), new m(), new d2(), new c2(), new v(), new y(), new b(), new E(), new qrCodeLevel(), new T(), new P(), new _(), new w(), new x(), new coordinate(), new widthHeight(), new C(), new imageFit(), new O(), new H(), new D(), new paperNumberContinue(), new watermarkOptions(), new I(), new R(), new pageBreak(), new M(), new M2(), new S(), new B(), new F(), new L(), new A(), new z(), new k(), new st(), new N(), new V(), new W(), new j(), new U(), new borderRadius(), new zIndex(), new K(), new G(), new q(), new X(), new Y(), new Q(), new J(), new Z(), new tt(), new et(), new nt(), new it(), new ot(),new textWrap(), new at(), new lt(), new panelLayoutOptions(), new ut(), new ith(), new dt(), new ct(), new ht(), new ft(), new gt(), new mt(), new rowcolumns(), new rowsColumnsMergeClean(), new groupSequenceContinue(), new groupFieldsFormatter(), new groupFormatter(), new groupFooterFormatter(), new vt(), new yt(), new bt(), new Tt(), new Et(), new Pt(), new stylerHeader(), new renderFormatter(), new _t(), new wt(), new maxRows(), new xt(), new tableColumnH(), new tableE(), new tableQRCodeLevel(), new tablept(), new tableSummaryTitle(), new tableSummaryText(), new tableSummaryColspan(), new tableSummary(), new tableSummaryAlign(), new tableSummaryNumFormat(), new tableSummaryFormatter(),new showCodeTitle(), new upperCase(), new barcodeType(), new qrcodeType(), new barColor(), new barTextMode(), new barWidth(), new barAutoWidth()], t; }(); }, function (t, e, n) { "use strict"; @@ -5660,7 +5697,7 @@ var hiprint = function (t) { if (this.printElementType.formatter) return (n = $("
")).append(this.printElementType.formatter(t)), (i = n.find("table")).addClass("hiprint-printElement-tableTarget"), i; var o = $('
'); let headerList = _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableHead(this.getColumns(), this.options.getWidth() / this.options.getGridColumns()); - return this.isNotDesign ? o.append(headerList) : o.append(headerList[0]), o.append(_table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableRow(this.getColumns(), t, e, this.options, this.printElementType)), "no" == this.options.tableFooterRepeat || _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, t, this.options, this.printElementType, e, t).insertBefore(o.find("tbody")), o; + return (this.isNotDesign && ['first', 'none'].includes(this.options.tableHeaderRepeat)) ? o.append(headerList) : o.append(headerList[0]), o.append(_table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableRow(this.getColumns(), t, e, this.options, this.printElementType)), "no" == this.options.tableFooterRepeat || _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, t, this.options, this.printElementType, e, t).insertBefore(o.find("tbody")), o; }, TablePrintElement.prototype.getEmptyRowTarget = function () { return _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createEmptyRowTarget(this.getColumns(), this); }, TablePrintElement.prototype.getHtml = function (t, e) { @@ -5815,9 +5852,9 @@ var hiprint = function (t) { if ("last" == this.options.tableFooterRepeat && !c.isEnd) break; if ("no" !== this.options.tableFooterRepeat) { if (noPaging) { - d.find("tbody").append(_table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, this.getData(t), this.options, this.printElementType, t, h).children()) + d.find("tbody").append(_table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, this.getData(t), this.options, this.printElementType, t, h, o).children()) } else { - _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, this.getData(t), this.options, this.printElementType, t, h).insertBefore(d.find("tbody")); + _table_TableExcelHelper__WEBPACK_IMPORTED_MODULE_6__.a.createTableFooter(this.printElementType.columns, this.getData(t), this.options, this.printElementType, t, h, o).insertBefore(d.find("tbody")); } that.css(d, t); } @@ -6223,8 +6260,9 @@ var hiprint = function (t) { }), this.target.before(i), this.rgripContariner = new d(i, n), this.syncRowGrips(); }, t.prototype.syncGrips = function (t, e) { var n = t.getTarget(); + var scale = ($('.hiprint-printPaper')[0].style.transform && parseFloat($('.hiprint-printPaper')[0].style.transform.slice(6, -1))) || 1; e.cell = t, e.target.css({ - left: n.offset().left - this.target.offset().left + n.outerWidth(!1), + left: (n.offset().left / scale) - (this.target.offset().left / scale) + n.outerWidth(!1), height: 30 }); }, t.prototype.syncRowGrips = function () { @@ -7699,7 +7737,7 @@ var hiprint = function (t) { opened: !1, name: "webSockets", host: "http://localhost:17521/", - token: null, + token: 'vue-plugin-hiprint', reconnectTimeout: 6e4, reconnectWindowSetTimeout: null, reconnectDelay: 2e3, @@ -7716,6 +7754,39 @@ var hiprint = function (t) { console.log("send data error:" + (t || "") + JSON.stringify(e)); } }, + sendByFragments: function(content) { + try { + const { + fragmentSize = 50000, // 单片字符长度 + sendInterval = 10, // 分批传输间隔 + html, + generateHTMLInterval, // 不需要传给client,取出字段 + printByFragments, // 不需要传给client,取出字段 + ...otherFields + } = content + const contentToSplit = content.html + // 字符总数 + const charsCount = contentToSplit.length + // 片段总数 + const fragmentsCount = Math.ceil(charsCount / fragmentSize) + Array.apply(undefined, { length: fragmentsCount }).forEach((item, index) => { + const startIndex = index * fragmentSize + // 字符结束索引 + const endIndex = index + 1 === fragmentSize ? charsCount : (index + 1) * fragmentSize + // socket分段发送内容 + setTimeout(() => { + this.socket.emit('printByFragments', { + ...otherFields, + index, + total: fragmentsCount, + htmlFragment: html.slice(startIndex, endIndex) + }); + }, sendInterval * index); + }) + } catch (e) { + console.log("send data fragment error:" + (content || "") + JSON.stringify(e)); + } + }, getPrinterList: function getPrinterList() { return this.printerList; }, @@ -7790,7 +7861,8 @@ var hiprint = function (t) { token: this.token } }), this.socket.on("connect", function (e) { - t.opened = !0, console.log("Websocket opened."), _this.socket.on("successs", function (t) { + t.opened = !0, console.log("Websocket opened."), + _this.socket.on("success", function (t) { hinnn.event.trigger("printSuccess_" + t.templateId, t); }), _this.socket.on("error", function (t) { hinnn.event.trigger("printError_" + t.templateId, t); @@ -8276,7 +8348,7 @@ var hiprint = function (t) { var e = this; this.text = t.text, this.field = t.field, this.fields = t.fields, this.title = t.title, this.tid = t.tid, this.data = t.data, this.styler = t.styler, this.formatter = t.formatter, this.type = t.type, this.options = t.options, this.editable = t.editable != void 0 ? t.editable : !0, this.columnDisplayEditable = t.columnDisplayEditable != void 0 ? t.columnDisplayEditable : !0, this.columnDisplayIndexEditable = t.columnDisplayIndexEditable != void 0 ? t.columnDisplayIndexEditable : !0, this.columnTitleEditable = t.columnTitleEditable != void 0 ? t.columnTitleEditable : !0, this.columnResizable = t.columnResizable != void 0 ? t.columnResizable : !0, this.columnAlignEditable = t.columnAlignEditable != void 0 ? t.columnAlignEditable : !0, this.columns = [], (t.columns || []).forEach(function (t, n) { e.columns.push(e.createTableColumnArray(t)); - }), this.rowStyler = t.rowStyler, this.striped = t.striped, this.groupFields = t.groupFields || [], this.groupFormatter = t.groupFormatter, this.groupFooterFormatter = t.groupFooterFormatter, this.footerFormatter = t.footerFormatter, this.rowsColumnsMerge = t.rowsColumnsMerge, this.rowsColumnsMergeClean = t.rowsColumnsMergeClean, this.gridColumnsFooterFormatter = t.gridColumnsFooterFormatter, + }), this.rowStyler = t.rowStyler, this.striped = t.striped, this.groupFields = t.groupFields || [], this.groupFormatter = t.groupFormatter, this.groupFooterFormatter = t.groupFooterFormatter, this.footerFormatter = t.footerFormatter, this.rowsColumnsMerge = t.rowsColumnsMerge, this.rowsColumnsMergeClean = t.rowsColumnsMergeClean, this.groupSequenceContinue = t.groupSequenceContinue, this.gridColumnsFooterFormatter = t.gridColumnsFooterFormatter, this.isEnableEditField = t.isEnableEditField != void 0 ? t.isEnableEditField : !0, this.isEnableContextMenu = t.isEnableContextMenu != void 0 ? t.isEnableContextMenu : !0, this.isEnableInsertRow = t.isEnableInsertRow != void 0 ? t.isEnableInsertRow : !0, this.isEnableDeleteRow = t.isEnableDeleteRow != void 0 ? t.isEnableDeleteRow : !0, this.isEnableInsertColumn = t.isEnableInsertColumn != void 0 ? t.isEnableInsertColumn : !0, this.isEnableDeleteColumn = t.isEnableDeleteColumn != void 0 ? t.isEnableDeleteColumn : !0, this.isEnableMergeCell = t.isEnableMergeCell != void 0 ? t.isEnableMergeCell : !0, this.columnObj = this.makeColumnObj(); } @@ -8823,6 +8895,8 @@ var hiprint = function (t) { return (null == this.fontSize ? this.defaultOptions.fontSize : this.fontSize) || 9; }, e.prototype.getbarcodeMode = function () { return (null == this.barcodeMode ? this.defaultOptions.barcodeMode : this.barcodeMode) || "CODE128"; + }, e.prototype.getBarTextMode = function () { + return (null == this.barTextMode ? this.defaultOptions.barTextMode : this.barTextMode) || 'text'; }, e.prototype.getBarWidth = function () { return (null == this.barWidth ? this.defaultOptions.barWidth : this.barWidth) || 1; }, e.prototype.getBarAutoWidth = function () { @@ -8910,8 +8984,13 @@ var hiprint = function (t) { "display": "flex", "flex-direction": "column" }) + // 分离显示条形码文本 + var divMode = this.options.getBarTextMode() == 'text'; // pub-beta 0.0.57-beta22 移除插件通过 div 添加的文本元素,默认使用 JsBarcode 生成条形码文本 a.html(''); + if (divMode) { + a.append(`
`); + } try { n ? (JsBarcode(a.find(".hibarcode_imgcode")[0], n, { format: this.options.getbarcodeMode(), @@ -8920,8 +8999,9 @@ var hiprint = function (t) { lineColor: this.options.color || "#000000", margin: 0, height: parseInt(o.a.pt.toPx(this.options.getHeight() || 10).toString()), - displayValue: !this.options.hideTitle, - }), a.find(".hibarcode_imgcode").attr("height", "100%"), a.find(".hibarcode_imgcode").attr("width", "100%")) : a.html(""); + displayValue: divMode ? false : !this.options.hideTitle, + }), a.find(".hibarcode_imgcode").attr("height", "100%"), a.find(".hibarcode_imgcode").attr("width", "100%"), + divMode && (this.options.hideTitle || a.find(".hibarcode_displayValue").html(n))): a.html(""); // pub-beta 0.0.57-beta22 解决条形码自动宽度问题 let svgWidth = a.find(".hibarcode_imgcode rect")[0].attributes.width.value svgWidth = Math.ceil(hinnn.px.toPt(svgWidth * 1.05)); @@ -9670,6 +9750,14 @@ var hiprint = function (t) { this.oddPaperFooter = t.oddPaperFooter, this.lastPaperFooter = t.lastPaperFooter, this.topOffset = t.topOffset, this.leftOffset = t.leftOffset; this.designPaper.setFooter(this.firstPaperFooter, this.evenPaperFooter, this.oddPaperFooter, this.lastPaperFooter), this.designPaper.setOffset(this.leftOffset, this.topOffset); + // 宽高 + this.target.css("width", t.width + "mm"), + this.target.css("height", t.height - p.a.instance.paperHeightTrim + "mm"), + this.target.attr("original-height", t.height), + this.target.parent().css("width", t.width + "mm"), + this.target.parent().css("height", t.height - p.a.instance.paperHeightTrim + "mm"), + this.designPaper.target.css("width", t.width + "mm"), + this.designPaper.target.css("height", t.height - p.a.instance.paperHeightTrim + "mm"); var end = Date.now(); console.log('更新参数 end', end) console.log('更新参数 time:', end - start) @@ -9777,7 +9865,9 @@ var hiprint = function (t) { console.log('pasteJson success'); o.a.event.trigger("hiprintTemplateDataChanged_" + n.templateId, "复制"); // 点击克隆出来的元素 + ele.designTarget.trigger($.Event('blur')) a.designTarget.children('.resize-panel').trigger($.Event('click')); + a.designTarget.trigger($.Event('focus')) }) } catch (e) { console.error('pasteJson error', e); @@ -10262,7 +10352,7 @@ var hiprint = function (t) { var r; if (tabs.length) { r = $('
    '); - tabs.filter((e) => e.list.length > 0).forEach(function (tab) { + tabs.filter((e,idx) => e.list.length > 0 || (idx == 2 && o && o.length)).forEach(function (tab) { var item = $('
  • ' + i18n.__(tab.name) + '
  • ') r.find('.prop-tab-items').append(item) var options = $('
    ') @@ -10548,8 +10638,43 @@ var hiprint = function (t) { } }); return e && e.imgToBase64 && this.transformImg(i.find("img")), i; + }, t.prototype.getSimpleHtmlAsync = function (dataItemOrList, e) { + return new Promise(resolve => { + var that = this; + e || (e = {}); + let rootElement = $('
    '); + // 将数据转换成列表处理,简化代码 + const dataList = Array.isArray(dataItemOrList) ? dataItemOrList : [dataItemOrList] + // 生成参数列表,用于后续递归 + const paramsListToCreateHTML = [] + dataList.forEach(function (data, dataIndex) { + data && that.printPanels.forEach(function (panel, o) { + paramsListToCreateHTML.push([panel, data, e]) + }); + }); + + function appendElementByParamsList(paramsListToCreateHTML, onFinish) { + if (!paramsListToCreateHTML.length) return onFinish(); + const [panel, data, e] = paramsListToCreateHTML.shift(); + rootElement.append(panel.getHtml(data, e)); + // 每次生成Html之间留一些间隔,默认10,通过generateHTMLInterval字段控制 + console.log('e.generateHTMLInterval', e.generateHTMLInterval) + setTimeout(() => appendElementByParamsList(paramsListToCreateHTML, onFinish), e.generateHTMLInterval ?? 10) + } + + function onFinish() { + delete hinnn._paperList; + e && e.imgToBase64 && that.transformImg(rootElement.find("img")); + resolve(rootElement) + } + + appendElementByParamsList(paramsListToCreateHTML, onFinish); + }); }, t.prototype.getHtml = function (t, e) { return t || (t = {}), this.getSimpleHtml(t, e); + }, t.prototype.getHtmlAsync = function (t, e) { + // 分解生成HTML任务,留下空隙发送socket信息,避免断开连接 + return t || (t = {}), this.getSimpleHtmlAsync(t, e); }, t.prototype.getJointHtml = function (t, e, n) { var i = $('
    '), o = []; @@ -10672,9 +10797,19 @@ var hiprint = function (t) { }, t.prototype.sentToClient = function (t, e, n) { e || (e = {}); var i = $.extend({}, n || {}); - i.imgToBase64 = !0; - var o = t + this.getHtml(e, i)[0].outerHTML; - i.id = s.a.instance.guid(), i.html = o, i.templateId = this.id, hiwebSocket.send(i); + i.imgToBase64 = i.imgToBase64 ?? false; + if (i.printByFragments) { + // 分批打印 + this.getHtmlAsync(e, i) + .then(rootElement => { + var o = t + rootElement[0].outerHTML; + i.id = s.a.instance.guid(), i.html = o, i.templateId = this.id, hiwebSocket.sendByFragments(i, n); + }) + } else { + // 同步打印 + var o = t + this.getHtml(e, i)[0].outerHTML; + i.id = s.a.instance.guid(), i.html = o, i.templateId = this.id, hiwebSocket.send(i); + } }, t.prototype.printByHtml = function (t) { $(t).hiwprint(); }, t.prototype.printByHtml2 = function (t, e) { @@ -11052,7 +11187,8 @@ var hiprint = function (t) { } function ft(t, e, n) { - $.extend({}, t || {}).imgToBase64 = !0; + $.extend({}, t || {}); + t.imgToBase64 = t.imgToBase64 ?? false; var i = new ct({}); i.on("printSuccess", e), i.on("printError", n), i.printByHtml2(this.getHtml(t), t.options); } @@ -11061,7 +11197,7 @@ var hiprint = function (t) { var e = void 0; return t && t.templates.forEach(function (n, i) { var o = $.extend({}, n.options || {}); - t.imgToBase64 && (o.imgToBase64 = !0), e ? e.append(n.template.getHtml(n.data, o).html()) : e = n.template.getHtml(n.data, o); + t.imgToBase64 && (o.imgToBase64 = o.imgToBase64 ?? false), e ? e.append(n.template.getHtml(n.data, o).html()) : e = n.template.getHtml(n.data, o); }), e; } @@ -11083,6 +11219,10 @@ var hiprint = function (t) { } function cig(t) { + if (hiprint._config == void 0) { + hiprint._config = JSON.stringify(window.HIPRINT_CONFIG); + } + const oldConfig = JSON.parse(hiprint._config); if (t) { t && Object.keys(t).forEach(function (i) { if (i == "optionItems" && t.optionItems && t.optionItems.length) { @@ -11093,7 +11233,7 @@ var hiprint = function (t) { if (tab.replace) { $.extend(p.a.instance[i].tabs[idx], tab); } else { - var options = tab.options || [], list = p.a.instance[i].tabs[idx].options; + var options = tab.options || [], list = oldConfig[i].tabs[idx].options; options && options.forEach(function (o) { var idx = list.findIndex(function (e) { return e.name == o.name @@ -11117,7 +11257,7 @@ var hiprint = function (t) { delete t[i].tabs; } else if (t[i].supportOptions && t[i].supportOptions.length) { - var options = t[i].supportOptions, list = p.a.instance[i].supportOptions; + var options = t[i].supportOptions, list = oldConfig[i].supportOptions; options.forEach(function (o) { var idx = list.findIndex(function (e) { return e.name == o.name @@ -11138,13 +11278,13 @@ var hiprint = function (t) { var keyMap = {}; keyMap[i] = t[i]; if (t[i].tabs && t[i].tabs.length == 0) { - keyMap[i].supportOptions = p.a.instance[i].supportOptions; + keyMap[i].supportOptions = oldConfig[i].supportOptions; } $.extend(p.a.instance, keyMap); } }); } else { - $.extend(p.a.instance, HIPRINT_CONFIG); + $.extend(p.a.instance, JSON.parse(hiprint._config)); } } @@ -11166,7 +11306,7 @@ var hiprint = function (t) { function getClientInfo(c) { p.a.instance.clear("clientInfo"); - p.a.instance.on("getClientInfo", c); + p.a.instance.on("clientInfo", c); hiwebSocket.getClientInfo() } diff --git a/src/hiprint/hiprint.config.js b/src/hiprint/hiprint.config.js index 474d824c..9501cb93 100644 --- a/src/hiprint/hiprint.config.js +++ b/src/hiprint/hiprint.config.js @@ -228,6 +228,10 @@ name: 'barcodeMode', hidden: false }, + { + name: 'barTextMode', + hidden: false + }, { name: 'barWidth', hidden: false @@ -344,6 +348,10 @@ name: 'barcodeMode', hidden: false }, + { + name: 'barTextMode', + hidden: false + }, { name: 'barWidth', hidden: false @@ -1012,6 +1020,10 @@ name: 'rowsColumnsMergeClean', hidden: false }, + { + name: 'groupSequenceContinue', + hidden: false + }, { name: 'groupFieldsFormatter', hidden: false @@ -1160,6 +1172,14 @@ name: 'rowsColumnsMerge', hidden: false }, + { + name: 'rowsColumnsMergeClean', + hidden: false + }, + { + name: 'groupSequenceContinue', + hidden: false + }, { name: 'groupFieldsFormatter', hidden: false @@ -1810,7 +1830,7 @@ name: 'tableSummaryNumFormat', hidden: false }, - + { name: 'tableSummaryFormatter', hidden: false @@ -1819,7 +1839,7 @@ name: 'upperCase', hidden: false }, - + { name: 'renderFormatter', hidden: false @@ -1836,7 +1856,7 @@ name: 'stylerHeader', hidden: false }, - + ], default: { height: 90, diff --git a/src/hiprint/plugins/jquery.hiwprint.js b/src/hiprint/plugins/jquery.hiwprint.js index eb8b0bf2..3afd0048 100644 --- a/src/hiprint/plugins/jquery.hiwprint.js +++ b/src/hiprint/plugins/jquery.hiwprint.js @@ -1,5 +1,6 @@ (function ($) { $.fn.hiwprint = function (options) { + var hasLoaded = false; var usedFrame = document.getElementById('hiwprint_iframe'); if (usedFrame) usedFrame.parentNode.removeChild(usedFrame); var opt = $.extend({}, $.fn.hiwprint.defaults, options); @@ -23,6 +24,8 @@ $iframe[0].srcdoc = '' + css + ''; $iframe[0].onload = function () { + if (hasLoaded) return; + hasLoaded = true; var printDocument = $iframe[0].contentWindow || $iframe[0].contentDocument; if (printDocument.document) printDocument = printDocument.document; if (!$iframe.attr('srcdoc')) { diff --git a/vue.config.js b/vue.config.js index 81425834..8eff6da7 100644 --- a/vue.config.js +++ b/vue.config.js @@ -15,6 +15,7 @@ module.exports = { let pkg = fs.readFileSync(pkgPath); pkg.dependencies = { "ant-design-vue": "^1.7.8", + "bwip-js": "^4.0.0", "core-js": "^3.6.5", "vue": "^2.5.11", "concurrent-tasks": "^1.0.7", diff --git a/webpack.config.js b/webpack.config.js index 486d7423..004088f7 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -45,9 +45,11 @@ module.exports = { amd: "socket.io-client", root: "io", }, - html2canvas: "html2canvas", + "@wtto00/html2canvas": "html2canvas", canvg: 'canvg', jspdf: "jspdf", + "bwip-js": 'bwip-js', + "nzh": "Nzh", }, optimization:{ minimizer:[