vue-plugin-hiprint使用教程【1】

2023-12-23 22:20

本文主要是介绍vue-plugin-hiprint使用教程【1】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

前言:
1、本文档适合新手
2、文档仅限于基本的使用,更深的高级应用请查阅相关资料
3、文档编写时相应功能都有测试过
4、教程文字代码有点多,CSDN无法一篇文章发布,所以拆分成若干篇
5、默默吐槽一句:CSDN无法承载太大的篇幅。所以我把教程导出为markdown文件,有需要的各位自行下载。
https://cloud.189.cn/t/FviyyijY3uyu (访问码:2gvs)

*、编写教程时的一些环境

// 编写教程时的软件环境
node:12.22.12
@vue/cli: 5.0.8
vue:3.2.36
// 参考资料
在线演示:https://ccsimple.gitee.io/vue-plugin-hiprint/
微信文档:https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzUyMzg5NDU0Mg==&action=getalbum&album_id=2779135389855956995&scene=173&subscene=&sessionid=svr_95b1d3bfd09&enterid=1703059529&from_msgid=2247484532&from_itemidx=1&count=3&nolastread=1#wechat_redirect
gitee地址:https://gitee.com/CcSimple/vue-plugin-hiprint#vuevue3-%E5%85%A8%E5%B1%80%E5%BC%95%E5%85%A5

1、安装

// 编写此文档时版本为:0.0.56
npm install vue-plugin-hiprint

2、移植print-lock.css。

1、 安装完之后,从目录node_modules/vue-plugin-hiprint/dist下将print-lock.css复制一份
2、 将复制的css文件放在index.html同级目录下。文件名称建议不要更改,保持默认:print-lock.css
3、在index中引入第二步创建的文件

3、编写基本界面和实现基本打印功能

这里仅介绍最基本的一些功能,其余功能看官方文档:

https://mp.weixin.qq.com/s?__biz=MzUyMzg5NDU0Mg==&mid=2247484604&idx=1&sn=a26f606cea93307fb533af45558c1b65&chksm=fa34eeddcd4367cbb7b28fed888d735cd6b9b26e79c2cb460021896f5c6ece2dc1ca0c5ea581&cur_album_id=2779135389654630403&scene=189#wechat_redirect

3.1、创建拖拽区域

<!--基本代码 class必须加上ep-draggable-item,用于后续ts代码识别;tid是唯一编码。其中defaultModule开头的为默认的拖拽元素--->
<template><div class="component" ref="componentRef"><el-row><el-col :span="6"><div class="ep-draggable-item" tid="defaultModule.barcode">条形码</div><div class="ep-draggable-item" tid="defaultModule.text">文本</div></el-col></el-row></div>
</template>
<script lang="ts" setup>
//@ts-ignore
import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint";
import {onMounted, ref} from "vue";
const componentRef = ref();
const fullHeight = ref();
hiprint.init({providers: [defaultElementTypeProvider()], // 声明拖拽元素,否则无法正确识别HTML里编写的拖拽元素
});
onMounted(() => {buildLeftElement();// 需要再onMounted里调用,防止带有ep-draggable-item的HTML元素还未渲染完成
});
const buildLeftElement = () => {// @ts-ignorehiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));// 这里就是上面的class。
};
</script>
// 完整demo代码
<template><div class="component" ref="componentRef"><el-row><el-col :span="6"><div class="ep-draggable-item" tid="defaultModule.barcode">条形码</div><div class="ep-draggable-item" tid="defaultModule.text">文本</div></el-col></el-row></div>
</template>
<script lang="ts" setup>
//@ts-ignore
import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint";
import {onMounted, ref} from "vue";const componentRef = ref();
const fullHeight = ref();hiprint.init({providers: [defaultElementTypeProvider()],
});
onMounted(() => {buildLeftElement();
});
const buildLeftElement = () => {// @ts-ignorehiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
};</script>
<style scoped lang="scss"></style>

3.2、编写设计区域(包括画布区域以及配置区域)

下面的代码已经完成了最基础的拖拽设计和属性配置

<!--完整代码-->
<template><div class="component" ref="componentRef"><el-row><el-col :span="6"><!-- 拖拽区域 --><div class="ep-draggable-item" tid="defaultModule.barcode">条形码</div><div class="ep-draggable-item" tid="defaultModule.text">文本</div></el-col><el-col :span="12" :style="'border: 1px solid #f0f0f0; padding: 20px;max-height: '+fullHeight+'px;overflow: auto;'" ><!-- 画布区域 --><div id="design-content"></div></el-col><el-col :span="6"><!-- 设计元素属性配置区域 --><div id="design-element-option-set"></div></el-col></el-row></div>
</template>
<script lang="ts" setup>
//@ts-ignore
import { hiprint, defaultElementTypeProvider } from "vue-plugin-hiprint";
import {onMounted, ref} from "vue";const componentRef = ref();
const fullHeight = ref();let  _printDesignObj:any; // 无需响应式声明hiprint.init({providers: [defaultElementTypeProvider()],
});
onMounted(() => {fullHeight.value = componentRef.value.clientHeight;buildLeftElement(); // 构建拖拽元素buildDesigner(); // 构建画布和属性
});
const buildLeftElement = () => {// @ts-ignorehiprint.PrintElementTypeManager.buildByHtml($(".ep-draggable-item"));
};
const buildDesigner = () => {$("#hiprint-printTemplate").empty();_printDesignObj = new hiprint.PrintTemplate({settingContainer: "#design-element-option-set", // 设计元素属性配置区域});_printDesignObj.design("#design-content"); // 画布区域
}</script>
<style scoped lang="scss"></style>

3.3、尝试打印

// 在HTML中增加一个button,并将@click指向print事件
// 操作逻辑如下:从拖拽区域拖拽文本到设计区域,点击设计区域的文本元素,在右侧属性区域:基本选项卡下,将字段名称改成print函数中的name。然后click一下button,就可以看到效果function print() {// 打印数据,key 对应 元素的 字段名let printData = {name:'CcSimple'};
// 参数: 打印时设置 左偏移量,上偏移量let options = {leftOffset:-1,topOffset:-1}
// 扩展let ext = {callback: () => {console.log('浏览器打印窗口已打开')},styleHandler: () => {// 重写 文本 打印样式return'<style>.hiprint-printElement-text{color:red !important;}</style>'}}
// 调用浏览器打印_printDesignObj.print(printData,options,ext);
}

这篇关于vue-plugin-hiprint使用教程【1】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/529672

相关文章

使用Docker构建Python Flask程序的详细教程

《使用Docker构建PythonFlask程序的详细教程》在当今的软件开发领域,容器化技术正变得越来越流行,而Docker无疑是其中的佼佼者,本文我们就来聊聊如何使用Docker构建一个简单的Py... 目录引言一、准备工作二、创建 Flask 应用程序三、创建 dockerfile四、构建 Docker

Python使用vllm处理多模态数据的预处理技巧

《Python使用vllm处理多模态数据的预处理技巧》本文深入探讨了在Python环境下使用vLLM处理多模态数据的预处理技巧,我们将从基础概念出发,详细讲解文本、图像、音频等多模态数据的预处理方法,... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

Python使用python-can实现合并BLF文件

《Python使用python-can实现合并BLF文件》python-can库是Python生态中专注于CAN总线通信与数据处理的强大工具,本文将使用python-can为BLF文件合并提供高效灵活... 目录一、python-can 库:CAN 数据处理的利器二、BLF 文件合并核心代码解析1. 基础合

Python使用OpenCV实现获取视频时长的小工具

《Python使用OpenCV实现获取视频时长的小工具》在处理视频数据时,获取视频的时长是一项常见且基础的需求,本文将详细介绍如何使用Python和OpenCV获取视频时长,并对每一行代码进行深入解析... 目录一、代码实现二、代码解析1. 导入 OpenCV 库2. 定义获取视频时长的函数3. 打开视频文

Spring IoC 容器的使用详解(最新整理)

《SpringIoC容器的使用详解(最新整理)》文章介绍了Spring框架中的应用分层思想与IoC容器原理,通过分层解耦业务逻辑、数据访问等模块,IoC容器利用@Component注解管理Bean... 目录1. 应用分层2. IoC 的介绍3. IoC 容器的使用3.1. bean 的存储3.2. 方法注

Python内置函数之classmethod函数使用详解

《Python内置函数之classmethod函数使用详解》:本文主要介绍Python内置函数之classmethod函数使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录1. 类方法定义与基本语法2. 类方法 vs 实例方法 vs 静态方法3. 核心特性与用法(1编程客