当前位置: 首页 > news >正文

前端页面生成条形码,借助layui打印标签

借助JsBarcode生成条形码
官网:https://lindell.me/JsBarcode/
github: https://github.com/lindell/JsBarcode

<div class="table-div" style="display: block;width: 300px; height: 241px; margin: auto;"><table border="1" cellspacing="0" cellpadding="3" style=" width: 300px; height: 230px;"><tr><td colspan="2" height="80px"><div style="text-align: center"><img id="barcode"/></div></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">开发员:${logistics_id}</span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">SQE工程师:${logistics_id}</span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px"> 取样类型:${logistics_id} </span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px"> 收货地址:${work_address} </span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">建资料流水号:${logistics_id}</span></td></tr></table>
</div>
<script src="https://unpkg.com/jsbarcode@latest/dist/JsBarcode.all.min.js"></script>
<script>JsBarcode("#barcode", "212313");let test = document.getElementById('barcode').getAttribute('src')console.log(test)
</script>

打印代码,使用 window.print() 打印页面上局部的数据

<script>
function print_labels(developer, sqe_person, sampling_type_display, work_address, pid) {layui.use(['form', 'layer', 'laydate', 'table', 'laytpl', 'element'], function () {var form = layui.form,layer = layui.layer,$ = layui.jquery,laydate = layui.laydate,laytpl = layui.laytpl,element = layui.element,table = layui.table,formSelects = layui.formSelects;let logistics_id = $('input[name="logistics_id"]').val()if(!logistics_id){layer.msg("请先填写物流单号!");}else{JsBarcode("#barcode", logistics_id);let barcode_res = $('#barcode').attr('src')console.log(barcode_res)var headstr = "<html><head></head><body>";var footstr = "</body>";//获得 print_div   里的所有 html 数据(把要打印的数据嵌套在 一个 div 里,获得 div)//var printData = document.getElementById("print").innerHTML;var printData = `<div class="table-div" style="display: block;width: 300px; height: 241px; margin: auto;"><table border="1" cellspacing="0" cellpadding="3" style=" width: 300px; height: 230px;"><tr><td colspan="2" height="80px"><div style="text-align: center"><img id="barcode" src="${barcode_res}"/></div></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">开发员:${developer}</span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">SQE工程师:${sqe_person}</span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px"> 取样类型:${sampling_type_display} </span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px"> 收货地址:${work_address} </span></td></tr><tr><td colspan="2" height="25px"><span style="float: left;position: relative;left:3px;font-size: 16px">建资料流水号:${pid}</span></td></tr></table></div>`//获取当前页面的htmlvar oldstr = document.body.innerHTML;//把 headstr+printData+footstr 里的数据 复制给 body 的 html 数据 ,相当于重置了 整个页面的 内容document.body.innerHTML = headstr + printData + footstr;//使用方法为 window.print() 打印页面上局部的数据window.print();document.body.innerHTML = oldstr;setTimeout("parent.layer.closeAll(\"iframe\")", 1000);// parent.layer.closeAll("iframe");}});}
</script>
http://www.lryc.cn/news/304797.html

相关文章:

  • 第1~8章 综合复习
  • 转运机器人,AGV底盘小车:打造高效、精准的汽车电子生产线
  • Spring Boot 的参数校验方案
  • 第N3周:Pytorch文本分类入门
  • 宝塔面板安装了mysql5.7和phpMyadmin,但是访问phpMyadmin时提示502 Bad Gateway
  • K8S—Pod详解
  • 深度学习中数据的转换
  • 如何系统地自学 Python?
  • 【软考】传输层协议之UDP
  • 微服务-微服务链路追踪组件Skywalking实战
  • Stream、Collections、Collectors用法
  • Jetson Xavier NX 与笔记本网线连接 ,网络共享,ssh连接到vscode
  • 利用netty手写rpc框架
  • js+views 压缩上传的图片
  • 【安卓基础5】中级控件
  • Arthas—【学习篇】
  • css pointer-events 多层鼠标点击事件
  • k8s中基于alpine的pod无法解析域名问题
  • 缩小ppt文件大小的办法
  • vue3中使用 tui-image-editor进行图片处理,并上传
  • 18.贪心算法
  • [AI]部署安装有道QanyThing
  • NLP_BERT与GPT争锋
  • 放一个还看得过去的后台模板设置模块css样式框架
  • 关于信号强度单位dB和dBm区别
  • 华清远见作业第四十二天——Qt(第四天)
  • vue2和vue3区别 浅析
  • GIT使用和简介
  • HTTPS(超文本传输安全协议)被恶意请求该如何处理。
  • QT-模拟电梯上下楼