# vue-plugin-hiprint **Repository Path**: hx321/vue-plugin-hiprint ## Basic Information - **Project Name**: vue-plugin-hiprint - **Description**: hiprint for vue2.0 - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 1218 - **Created**: 2021-12-31 - **Last Updated**: 2023-05-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README
[![npm][npm]][npm-url] [![node][node]][node-url] [![size][size]][size-url] # vue-plugin-hiprint > hiprint for vue2.0 ## 参与/预览 ```console git clone https://github.com/CcSimple/vue-plugin-hiprint.git // or git clone https://gitee.com/CcSimple/vue-plugin-hiprint.git // init cd vue-plugin-hiprint npm i // 调试预览 npm run serve // 打包 npm run build ``` ## 演示/截个图咯~
![image](./res/img.png) ![image](./res/img_1.png)
## 状态/调整/优化 - [x] `vue 插件` 发布npm包,方便直接使用 - [x] `Ant Design Vue` 默认demo - [x] `优化删除元素功能` 支持 backSpace/delete 按键删除 - [x] `优化拖动功能` fix 元素拖出窗口外的问题 - [x] `优化框选功能` fix 原只能从上往下框选问题 - [x] `支持修改默认直接打印主机` window.hiwebSocket.setHost("xxx:17521") ### 咳咳.. 第一次写插件(webpack打包这些都不太了解),不合理的地方欢迎指正issues。 简单的修改了下`hiprint.bundle.js`引入了相关资源,然后`export hiprint,defaultElementTypeProvider` #### 详见源码vue-plugin-hiprint #### 呃呃.. 记录一下处理过程 > webpack 配置 ```javascript { // 引用本地资源, 一些源码中 require('xxx') 需要处理 resolve: { alias: { 'vue$': 'vue/dist/vue.esm.js', 'jquery$': path.resolve(__dirname, "./src/hiprint/plugins/jq-3.31.js"), // 这两个资源在 plugins/jspdf/canvg.min.js 中的需要 'rgbcolor$': path.resolve(__dirname, "./src/hiprint/plugins/jspdf/rgbcolor.js"), 'stackblur-canvas$': path.resolve(__dirname, "./src/hiprint/plugins/jspdf/stackblur-canvas.js"), } }, // 全局jQuery问题 plugins: [ new webpack.ProvidePlugin({ jQuery: "jquery", $: "jquery" }), ], // 资源处理 module: { rules: [ // url-loader 处理 jquery.minicolors.png, 转成base64 { test: /\.(png|jpg|gif|svg)$/, loader: 'url-loader', options: { name: '[name].[ext]' } } ] } } ``` ## Install ```console npm install vue-plugin-hiprint ``` ## Global use ```javascript import {hiPrintPlugin} from 'vue-plugin-hiprint' Vue.use(hiPrintPlugin, '$pluginName') // then use this.$pluginName // for example 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({}); ``` ## Custom design ```javascript import {hiprint,defaultElementTypeProvider} from 'vue-plugin-hiprint' hiprint.init({ providers: [new defaultElementTypeProvider()] }) hiprint.PrintElementTypeManager.buildByHtml($('.ep-draggable-item')); hiprintTemplate = new hiprint.PrintTemplate({ template: {}, settingContainer: '#PrintElementOptionSetting', paginationContainer: '.hiprint-printPagination' }); hiprintTemplate.design('#hiprint-printTemplate'); ``` ## Questions > design时怎么修改默认图片? ```javascript ``` [npm]: https://img.shields.io/npm/v/vue-plugin-hiprint.svg [npm-url]: https://npmjs.com/package/vue-plugin-hiprint [node]: https://img.shields.io/node/v/vue-plugin-hiprint.svg [node-url]: https://nodejs.org [size]: https://packagephobia.now.sh/badge?p=vue-plugin-hiprint [size-url]: https://packagephobia.now.sh/result?p=vue-plugin-hiprint