|
|
@@ -0,0 +1,405 @@
|
|
|
+<template>
|
|
|
+<view class="app-content">
|
|
|
+ <view class="content">
|
|
|
+ <view>
|
|
|
+ <button @click="openDefault" >连接</button>
|
|
|
+ <!-- <button @click="open" >打开自定义蓝牙搜索页面</button>
|
|
|
+ <button @click="connectIP" >端口ip连接标签机</button>
|
|
|
+ <button @click="connectUSB" >USB 连接标签机</button> -->
|
|
|
+ <!-- <button @click="printer" >打印小票</button> -->
|
|
|
+ <!-- <button @click="printerLable" >打印样签</button> -->
|
|
|
+ <!-- <button @click="writePDFToTsc" >标签打印PDF</button>
|
|
|
+ <button @click="writePDFToEsc" >小票打印PDF</button>
|
|
|
+ <button @click="writeTSC" >tsc指令打印</button> -->
|
|
|
+ <!-- <button @click="state" >标签机状态</button> -->
|
|
|
+ <button @click="dis" >断开</button>
|
|
|
+ <text>{{tip}}</text>
|
|
|
+ </view>
|
|
|
+ </view>
|
|
|
+</view>
|
|
|
+</template>
|
|
|
+<script>
|
|
|
+const plug= uni.requireNativePlugin('Html5app-Gprinter');
|
|
|
+export default {
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ tip: ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ openDefault()
|
|
|
+ {
|
|
|
+ //蓝牙连接标签机
|
|
|
+ const that=this;
|
|
|
+ plug.BluetoothPort({setBackgroundColor:"#2088d2"},result=>{
|
|
|
+ if(result.code == 3){
|
|
|
+ that.$msg('连接成功')
|
|
|
+ setTimeout(function(){
|
|
|
+ uni.navigateBack()
|
|
|
+ },2000)
|
|
|
+ that.tip=''
|
|
|
+ }else{
|
|
|
+ that.tip=JSON.stringify(result)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ open(){
|
|
|
+ uni.navigateTo({ "url":"./Bluetooth" })
|
|
|
+ },
|
|
|
+ connectIP()
|
|
|
+ {
|
|
|
+ //端口网络连接
|
|
|
+ let that=this;
|
|
|
+ plug.connectIP({},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ connectUSB()
|
|
|
+ {
|
|
|
+ //USB网络连接
|
|
|
+ let that=this;
|
|
|
+ plug.connectUSB({setBackgroundColor:"#2088d2"},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ state(){
|
|
|
+ //查询标签机状态
|
|
|
+ let that=this;
|
|
|
+ plug.state({},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret.msg)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ dis()
|
|
|
+ {
|
|
|
+ //断开标签机
|
|
|
+ let that=this;
|
|
|
+ plug.disconnect({},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret.msg)
|
|
|
+ });
|
|
|
+ },
|
|
|
+ printer(){
|
|
|
+ //标签机小票
|
|
|
+ const that=this;
|
|
|
+ plug.printer({"ESC":that.setDate()},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ printerLable(){
|
|
|
+ //打印标签
|
|
|
+ const that=this;
|
|
|
+ plug.printer({"TSC":that.OrderLable('粉红雪山','11054')},ret=>{
|
|
|
+ that.tip=JSON.stringify(ret);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ writePDFToTsc()
|
|
|
+ {
|
|
|
+ //打印pdf 档标签文件
|
|
|
+ let filePath=plus.io.convertLocalFileSystemURL("static/pdfFile.pdf");
|
|
|
+ plug.writePDFToTsc({filePath:filePath,width:400},ret=>{
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ writePDFToEsc()
|
|
|
+ {
|
|
|
+ //打印pdf 档小票文件
|
|
|
+ let filePath=plus.io.convertLocalFileSystemURL("static/pdfFile.pdf");
|
|
|
+ plug.writePDFToEsc({filePath:filePath,width:400},ret=>{
|
|
|
+
|
|
|
+ });
|
|
|
+ },
|
|
|
+ writeTSC()
|
|
|
+ {
|
|
|
+ //打印图片和文字
|
|
|
+ let image=plus.io.convertLocalFileSystemURL("static/gprinter.png");
|
|
|
+
|
|
|
+ //图片指令,BITMAP x,y,宽度,图片路径 ,四个参数组成
|
|
|
+
|
|
|
+ const that=this;
|
|
|
+ let str="SIZE 40 mm,15 mm \n";
|
|
|
+ str+="GAP 2 mm,0 mm \n";
|
|
|
+ str+"SET RESPONSE NO \n";
|
|
|
+ str+="CLS \n";
|
|
|
+ str+="TEXT 50,50,\"3\",0,1,1,\"DEMO FOR TEXT\" \n";
|
|
|
+ str+="BITMAP 20,20,100,"+image+" \n";
|
|
|
+ str+=" PRINT 1 \n";
|
|
|
+
|
|
|
+ plug.writeTSC({"tsc":str},function(e){
|
|
|
+ that.tip=JSON.stringify(e);
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+ setDate()
|
|
|
+ {
|
|
|
+ //打印小票
|
|
|
+ const that=this;
|
|
|
+
|
|
|
+ //制作小票格式,
|
|
|
+ var data=[]; //定义一个数组
|
|
|
+ var line={}; //每添加一个,代表一行字
|
|
|
+
|
|
|
+ var filePath=plus.io.convertLocalFileSystemURL("static/gprinter.png");
|
|
|
+ //加入logo图片
|
|
|
+ var Path=filePath;
|
|
|
+ line.image=Path;
|
|
|
+ line.width="350";
|
|
|
+ line.center="center";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="万达广场欢迎您";
|
|
|
+ line.center="center";
|
|
|
+ line.font="max";
|
|
|
+ line.bottom="3";
|
|
|
+ data.push(line); //每添加一个,代表一行字
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="收银员:00056";
|
|
|
+ line.center="left";
|
|
|
+ line.font="bold";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="单号:00256933";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="业务日期:2019-05-30 18:15:25";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="------------------------------";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ //商品列表,示例
|
|
|
+ for(let i=0;i<4;i++)
|
|
|
+ {
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="商品名称:小黑瓶眼霜";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.title=["数量:1","单价:305","金额:305"];
|
|
|
+ line.left=[0,30,60];
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ line={}; //清空一下
|
|
|
+
|
|
|
+ line.text="------------------------------";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="数量:4 ,金额:¥1220.00";
|
|
|
+ line.center="left";
|
|
|
+ line.font="bold";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="实收金额:¥1220.00";
|
|
|
+ line.center="left";
|
|
|
+ line.font="bold";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="活动期间满500送100";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+ line={};
|
|
|
+ line.text="折让金额500";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="1";
|
|
|
+ data.push(line);
|
|
|
+ line={};
|
|
|
+ line.text="折后金额2029";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="3";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ line={};
|
|
|
+ line.text="30天内可凭小票换开发票";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+ line={};
|
|
|
+ line.text="活动商品,不退不换";
|
|
|
+ line.center="left";
|
|
|
+ line.font="normal";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ //加入条型码
|
|
|
+ line={};
|
|
|
+ line.barcode="2019563352660";
|
|
|
+ line.type="CODE128";
|
|
|
+ line.height="100";
|
|
|
+ line.position="BELOW";
|
|
|
+ line.width="2";
|
|
|
+ line.center="center";
|
|
|
+ line.bottom="2";
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+
|
|
|
+ //加入二维码
|
|
|
+ line={};
|
|
|
+ line.qrcode="d68242b5e540aa7f21173c2d65b2c5ad";
|
|
|
+ line.size="10";
|
|
|
+ line.center="center";
|
|
|
+ line.bottom="0";
|
|
|
+ line.errorlevel="L";
|
|
|
+
|
|
|
+
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ // line={};
|
|
|
+ // //加入图片
|
|
|
+ // line.image="http://www.html5-app.com/uploads/file/20190307/20190307172436572807.png";
|
|
|
+ // line.width="150";
|
|
|
+ // line.center="center";
|
|
|
+ // line.bottom="3";
|
|
|
+ // data.push(line);
|
|
|
+
|
|
|
+ return data;
|
|
|
+
|
|
|
+ },
|
|
|
+ OrderLable(itemName,itemId){
|
|
|
+
|
|
|
+ //制作标签格式,
|
|
|
+ var data=[]; //定义一个数组
|
|
|
+ var line={}; //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //设置标签纸大小
|
|
|
+ line={};
|
|
|
+ line.width=30; //mm
|
|
|
+ line.height=20; //mm
|
|
|
+ line.gap=2; //标签纸之间,间隙长度 mm
|
|
|
+ line.page=1; //打印几份
|
|
|
+ data.push(line); //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //添加文字
|
|
|
+ line={};
|
|
|
+ line.text= itemName;
|
|
|
+ line.rotation=0;
|
|
|
+ line.x=35;
|
|
|
+ line.y=20;
|
|
|
+ line.xscal=1;
|
|
|
+ line.yscal=1;
|
|
|
+ data.push(line); //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //添加条型码
|
|
|
+ line={};
|
|
|
+ line.barcode=itemId;
|
|
|
+ line.x=35;
|
|
|
+ line.y=55;
|
|
|
+ line.type="CODE128";
|
|
|
+ line.height=50;
|
|
|
+ line.readable=true;
|
|
|
+ line.rotation=0;
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ return data;
|
|
|
+ },
|
|
|
+ Lable(){
|
|
|
+
|
|
|
+ //制作标签格式,
|
|
|
+ var data=[]; //定义一个数组
|
|
|
+ var line={}; //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //设置标签纸大小
|
|
|
+ line={};
|
|
|
+ line.width=40; //mm
|
|
|
+ line.height=30; //mm
|
|
|
+ line.gap=3; //标签纸之间,间隙长度 mm
|
|
|
+ line.page=1; //打印几份
|
|
|
+ data.push(line); //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //添加图片
|
|
|
+ line={};
|
|
|
+ line.image="http://www.html5-app.com/gprinter.png";
|
|
|
+ line.x=30;
|
|
|
+ line.y=20;
|
|
|
+ line.width=70;
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+
|
|
|
+ //添加文字
|
|
|
+ line={};
|
|
|
+ line.text="HTML5+混合APP开发社区";
|
|
|
+ line.rotation=0;
|
|
|
+ line.x=30;
|
|
|
+ line.y=90;
|
|
|
+ line.xscal=1;
|
|
|
+ line.yscal=1;
|
|
|
+ data.push(line); //每添加一个,代表一行字
|
|
|
+
|
|
|
+ //添加条型码
|
|
|
+ line={};
|
|
|
+ line.barcode="2019563352660";
|
|
|
+ line.x=30;
|
|
|
+ line.y=130;
|
|
|
+ line.type="CODE128";
|
|
|
+ line.height=50;
|
|
|
+ line.readable=true;
|
|
|
+ line.rotation=0;
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ //加入二维码
|
|
|
+ line={};
|
|
|
+ line.qrcode="1234566";
|
|
|
+ line.x=190;
|
|
|
+ line.y=20;
|
|
|
+ line.width=3
|
|
|
+ line.rotation=0;
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ //添加黑块
|
|
|
+ line={};
|
|
|
+ line.addBar={x:25,y:2,width:300,height:3};
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ //添加方框
|
|
|
+ line={};
|
|
|
+ line.addBox={x:25,y:15,xend:300,yend:120,thickness:2};
|
|
|
+ data.push(line);
|
|
|
+
|
|
|
+ return data;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+<style>
|
|
|
+ .content {
|
|
|
+ margin: 10px;
|
|
|
+ margin-top:30px;
|
|
|
+ }
|
|
|
+ button{ margin-bottom: 25px;}
|
|
|
+</style>
|