From f26f29d84e0a68831a6af14dab3eec5500496d2e Mon Sep 17 00:00:00 2001 From: spring <2396852758@qq.com> Date: 星期三, 28 五月 2025 16:48:52 +0800 Subject: [PATCH] 初始化项目 --- pages/product/outputRegister/printProductOutLabel.vue | 495 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 495 insertions(+), 0 deletions(-) diff --git a/pages/product/outputRegister/printProductOutLabel.vue b/pages/product/outputRegister/printProductOutLabel.vue new file mode 100644 index 0000000..75b1dbc --- /dev/null +++ b/pages/product/outputRegister/printProductOutLabel.vue @@ -0,0 +1,495 @@ +<template> + <view class="content"> + <view class="body"> + <view> + <textarea class="result" v-model="returnResult"></textarea> + </view> + <textarea class="input" @input="inputEvent" /> + <button type="primary" @tap="sendData">鍙戦��(绁ㄦ嵁鍙娇鐢�)</button> + + <view style='margin-top:4%;display: flex;flex-direction: row;'> + <button type='primary' @tap='receiptTest' :loading='isReceiptSend' :disabled='isReceiptSend'>绁ㄦ嵁娴嬭瘯</button> + <button type='primary' @tap='labelTest' :loading='isLabelSend' :disabled='isLabelSend'>鏍囩娴嬭瘯</button> + </view> + + <view style='margin-top:4%;display: flex;flex-direction: row;'> + <!-- hidden='true' --> + <canvas canvas-id='edit_area_canvas' :style="{width:canvasWidth+'px',height:canvasHeight+'px'}"></canvas> + </view> + + <picker style='margin:20px' mode='selector' :range='buffSize' :value='buffIndex' @change='buffBindChange'> + 褰撳墠姣忔鍙戦�佸瓧鑺傛暟涓�(鐐瑰嚮鍙洿鎹�)锛歿{buffSize[buffIndex]}} + </picker> + + <picker style='margin:20px' mode='selector' :range='printNum' :value='printNumIndex' @change='printNumBindChange'> + 褰撳墠鎵撳嵃浠芥暟(鐐瑰嚮鍙洿鎹�)锛歿{printNum[printNumIndex]}} + </picker> + + </view> + </view> +</template> + +<script> + var tsc = require("../../../util/ble/tsc.js"); + var esc = require("../../../util/ble/esc.js"); + var encode = require("../../../util/ble/encoding.js"); + import { + mapState + } from 'vuex'; + export default { + data() { + return { + sendContent: "", + looptime: 0, + currentTime: 1, + lastData: 0, + oneTimeData: 0, + returnResult: "", + canvasWidth: 180, + canvasHeight: 180, + imageSrc: '../../static/img/abc_ic_star_black_16dp.png', + buffSize: [], + buffIndex: 0, + printNum: [], + printNumIndex: 0, + printerNum: 1, + currentPrint: 1, + isReceiptSend: false, + isLabelSend: false, + printData:null + }; + }, + computed: mapState(['sysinfo', 'Bluetooth']), + onLoad(params) { + let that = this; + let { + BLEInformation + } = that.Bluetooth; + if (params.data) { + that.printData =JSON.parse(params.data); + } + // uni.notifyBLECharacteristicValueChange({ + // deviceId: BLEInformation.deviceId, + // serviceId: BLEInformation.notifyServiceId, + // characteristicId: BLEInformation.notifyCharaterId, + // state: true, + // success(res) { + // uni.onBLECharacteristicValueChange(function(r) { + // console.log(`characteristic ${r.characteristicId} has changed, now is ${r}`) + // }) + // }, + // fail: function(e) { + // console.log(e) + // }, + // complete: function(e) { + // console.log(e) + // } + // }) + }, + onReady(){ + let list = [] + let numList = [] + let j = 0 + for (let i = 20; i < 200; i += 10) { + list[j] = i; + j++ + } + for (let i = 1; i < 10; i++) { + numList[i - 1] = i + } + this.buffSize = list; + this.oneTimeData = list[0]; + this.printNum = numList; + this.printerNum = numList[0]; + }, + onShow(){ + let that = this; + let width; + let height; + uni.getImageInfo({ + src: that.imageSrc, + success(res) { + console.log(res.width) + console.log(res.height) + width = res.width + height = res.height + that.canvasWidth = res.width; + that.canvasHeight = res.height; + } + }) + const ctx = uni.createCanvasContext("edit_area_canvas", this); + // if (app.globalData.platform == "android") { + // ctx.translate(width, height) + // ctx.rotate(180 * Math.PI / 180) + // } + ctx.drawImage(this.imageSrc, 0, 0, width, height); + ctx.draw(); + }, + onUnload() { + let that = this; + let { + BLEInformation + } = that.Bluetooth; + // uni.closeBLEConnection({ + // deviceId: BLEInformation.deviceId, + // success: function(res) { + // console.log("鍏抽棴钃濈墮鎴愬姛") + // }, + // }) + }, + methods:{ + //鑾峰彇杈撳叆鍐呭 + inputEvent(e){ + this.sendContent = e.detail.value; + }, + //杈撳叆妗嗙偣鍑诲彂閫� + sendData(){ + let data = this.sendContent + "\n" + this.looptime = 0; + var content = new encode.TextEncoder( + 'gb18030', { + NONSTANDARD_allowLegacyEncoding: true + }).encode(data); + + this.prepareSend(content); + }, + //鏍囩娴嬭瘯 + labelTest(){ + let that = this; + let canvasWidth = that.canvasWidth + let canvasHeight = that.canvasHeight + let command = tsc.jpPrinter.createNew() + command.setSize(48, 48) + command.setGap(0) + command.setCls() + command.setQR(0, 32, "L", 5, "A", "www.smarnet.cc浣冲崥鏅烘眹") + command.setText(0, 64, "TSS24.BF2", 1, 1, "瀹㈡埛璁㈠崟鍙�") + command.setText(64, 64, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 64, "TSS24.BF2", 1, 1, "瀹㈡埛鍚嶇О") + command.setText(192, 64, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 104, "TSS24.BF2", 1, 1, "宸ュ簭锛�") + command.setText(192, 104, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(256, 104, "TSS24.BF2", 1, 1, "宸ヤ綔绔欙細") + command.setText(320, 104, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 144, "TSS24.BF2", 1, 1, "闆朵欢鎻忚堪锛�") + command.setText(192, 144, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(256, 144, "TSS24.BF2", 1, 1, "SN鍙凤細") + command.setText(320, 144, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 184, "TSS24.BF2", 1, 1, "鐢熶骇鏁伴噺锛�") + command.setText(192, 184, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(256, 184, "TSS24.BF2", 1, 1, "杞藉叿缂栧彿锛�") + command.setText(320, 184, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 224, "TSS24.BF2", 1, 1, "鐢熶骇鏃ユ湡锛�") + command.setText(192, 224, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(256, 224, "TSS24.BF2", 1, 1, "鐢熶骇浜哄憳锛�") + command.setText(320, 224, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(0, 264, "TSS24.BF2", 1, 1, "妫�楠岀粨璁猴細") + command.setText(64, 264, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(128, 264, "TSS24.BF2", 1, 1, "妫�娴嬩汉鍛橈細") + command.setText(192, 264, "TSS24.BF2", 1, 1, "xxxxxxx") + command.setText(256, 264, "TSS24.BF2", 1, 1, "妫�娴嬫椂闂达細") + command.setText(320, 264, "TSS24.BF2", 1, 1, "xxxxxxx") + command.setText(0, 304, "TSS24.BF2", 1, 1, "鎵撳嵃鏃堕棿锛�") + command.setText(64, 304, "TSS24.BF2", 1, 1, "xxxxxx") + command.setText(0, 344, "TSS24.BF2", 1, 1, "澶囨敞锛�") + command.setText(64, 344, "TSS24.BF2", 1, 1, "") + command.setBarCode(0, 104, "EAN8", 64, 1, 3, 3, "1234567") + uni.canvasGetImageData({ + canvasId: 'edit_area_canvas', + x: 0, + y: 0, + width: canvasWidth, + height: canvasHeight, + success: function(res) { + command.setBitmap(60, 0, 1, res) + }, + complete: function() { + command.setPagePrint() + that.isLabelSend = true; + that.prepareSend(command.getData()) + } + }) + }, + + //绁ㄦ嵁娴嬭瘯 + receiptTest(){ + var that = this; + var canvasWidth = that.canvasWidth + var canvasHeight = that.canvasHeight + var command = esc.jpPrinter.createNew() + command.init() + // 鏍囬 + command.bold(1);//鍔犵矖 + command.setFontSize(16);//瀛椾綋澶у皬 + command.setSelectJustification(1)//灞呬腑 + command.rowSpace(100); + command.setText("鏉窞鎬诲簵"); + command.setPrint(); + command.rowSpace(60); + + command.bold(0);//鍙栨秷鍔犵矖 + command.setFontSize(0);//姝e父瀛椾綋 + //鏃堕棿 + command.setSelectJustification(0);//灞呭乏 + command.setText("鏃堕棿锛�2019-11-11 12:10:30"); + command.setPrint(); + //缂栧彿 + command.setSelectJustification(0);//灞呭乏 + command.setText("缂栧彿锛歋D10000000000000000"); + command.setPrintAndFeed(80);//鎵撳嵃骞惰蛋绾竑eed涓崟浣� + //鍒楄〃 + command.rowSpace(80);//闂磋窛 + command.bold(5);//鍔犵矖 + command.setText("璐у彿"); + command.setAbsolutePrintPosition(100); + command.setText("棰滆壊"); + command.setAbsolutePrintPosition(180); + command.setText("灏虹爜"); + command.setAbsolutePrintPosition(270); + command.setText("鍗曚环"); + command.setAbsolutePrintPosition(380); + command.setText("鏁伴噺"); + command.setAbsolutePrintPosition(480); + command.setText("閲戦"); + command.setPrint() + command.bold(0);//鍔犵矖 + // -------1 + command.setText("86001W"); + command.setAbsolutePrintPosition(100); + command.setText("榛勮壊"); + command.setAbsolutePrintPosition(180); + command.setText("鍧囩爜"); + command.setAbsolutePrintPosition(270); + command.setText("16947.92"); + command.setAbsolutePrintPosition(390); + command.setText("1"); + command.setAbsolutePrintPosition(480); + command.setText("19647.92"); + command.setPrint() + // ------2 + command.setText("86001W"); + command.setAbsolutePrintPosition(100); + command.setText("榛勮壊"); + command.setAbsolutePrintPosition(180); + command.setText("鍧囩爜"); + command.setAbsolutePrintPosition(270); + command.setText("16947.92"); + command.setAbsolutePrintPosition(390); + command.setText("1"); + command.setAbsolutePrintPosition(480); + command.setText("19647.92"); + command.setPrint() + // -------3 + command.setText("86001W"); + command.setAbsolutePrintPosition(100); + command.setText("榛勮壊"); + command.setAbsolutePrintPosition(180); + command.setText("鍧囩爜"); + command.setAbsolutePrintPosition(270); + command.setText("16947.92"); + command.setAbsolutePrintPosition(390); + command.setText("1"); + command.setAbsolutePrintPosition(480); + command.setText("19647.92"); + command.setPrint(); + + + //鍚堣 + command.bold(5);//鍔犵矖 + command.setAbsolutePrintPosition(120); + command.setText("鎬绘暟锛�10"); + command.setAbsolutePrintPosition(320); + command.setText("鍚堣锛�10000"); + command.setPrint(); + command.setAbsolutePrintPosition(120); + command.setText("瀹炴敹锛�10000"); + command.setAbsolutePrintPosition(320); + command.setText("鎵鹃浂锛�0"); + command.setPrint(); + // 鏀堕摱鍛� + command.rowSpace(120);//闂磋窛 + command.setAbsolutePrintPosition(120); + command.setText("搴楀憳锛氫綍涓�"); + command.setAbsolutePrintPosition(320); + command.setText("浼氬憳锛�1000000000"); + command.setPrint() + + //鎻愮ず + command.rowSpace(80);//闂磋窛 + command.bold(2);//鍔犵矖 + command.setSelectJustification(1);//灞呬腑 + command.setText("鍞嚭鍟嗗搧璐拱鍚�7澶╁唴,鍙嚟灏忕エ閫�鎹�"); + command.setPrint(); + command.setText("(娉細鍚婄墝鏈媶鍓�,鍟嗗搧鏈礂娑�)"); + command.setPrint(); + + //鐢佃瘽 + command.setSelectJustification(0);//灞呭乏 + command.setText("瀹㈡湇鐢佃瘽:(0571)86011123"); + command.setPrint(); + command.setText("鑱旂郴鍦板潃:娴欐睙鐪佽鏆ㄥ競鏆ㄩ槼琛楅亾鍋ュ悍璺�1-1鍙�"); + command.setPrint(); + + command.setPrintAndFeedRow(3); + + that.isReceiptSend = true; + that.prepareSend(command.getData()); + + + }, + + //鍑嗗鍙戦�侊紝鏍规嵁姣忔鍙戦�佸瓧鑺傛暟鏉ュ鐞嗗垎鍖呮暟閲� + prepareSend(buff){ + console.log(buff); + let that = this + let time = that.oneTimeData + let looptime = parseInt(buff.length / time); + let lastData = parseInt(buff.length % time); + console.log(looptime + "---" + lastData) + this.looptime = looptime + 1; + this.lastData = lastData; + this.currentTime = 1; + that.Send(buff) + }, + //鏌ヨ鎵撳嵃鏈虹姸鎬� + queryStatus(){ + let command = esc.jpPrinter.Query(); + command.getRealtimeStatusTransmission(1); + }, + //鍒嗗寘鍙戦�� + Send(buff){ + let that = this + let {currentTime,looptime:loopTime,lastData,oneTimeData:onTimeData,printerNum:printNum,currentPrint}=that; + let buf; + let dataView; + if (currentTime < loopTime) { + buf = new ArrayBuffer(onTimeData) + dataView = new DataView(buf) + for (var i = 0; i < onTimeData; ++i) { + dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i]) + } + } else { + buf = new ArrayBuffer(lastData) + dataView = new DataView(buf) + for (var i = 0; i < lastData; ++i) { + dataView.setUint8(i, buff[(currentTime - 1) * onTimeData + i]) + } + } + console.log("绗�" + currentTime + "娆″彂閫佹暟鎹ぇ灏忎负锛�" + buf.byteLength) + let { + BLEInformation + } = that.Bluetooth; + + plus.bluetooth.writeBLECharacteristicValue({ + deviceId: BLEInformation.deviceId, + serviceId: BLEInformation.writeServiceId, + characteristicId: BLEInformation.writeCharaterId, + value: buf, + success: function(res) { + console.log(res) + }, + fail: function(e) { + console.log(e) + }, + complete: function() { + currentTime++ + if (currentTime <= loopTime) { + that.currentTime = currentTime; + that.Send(buff) + } else { + uni.showToast({ + title: '宸叉墦鍗扮' + currentPrint + '寮�', + }) + if (currentPrint == printNum) { + that.looptime = 0; + that.lastData = 0; + that.currentTime = 1; + that.isReceiptSend = false; + that.isLabelSend = false; + that.currentPrint = 1; + } else { + currentPrint++; + that.currentPrint = currentPrint; + that.currentTime = 1; + that.Send(buff) + } + } + } + }) + }, + buffBindChange: function(res) { //鏇存敼鎵撳嵃瀛楄妭鏁� + let index = res.detail.value + let time = this.buffSize[index] + this.buffIndex = index; + this.oneTimeData = time; + }, + printNumBindChange: function(res) { //鏇存敼鎵撳嵃浠芥暟 + let index = res.detail.value + let num = this.printNum[index] + this.printNumIndex = index; + this.printerNum = num; + }, + } + } +</script> + +<style lang="less"> + .input{ + text-align: top; + width: 90%; + height: 150px; + margin-left: 4%; + margin-right: 4%; + margin-top: 10px; + margin-bottom: 12px; + border: 1px solid slategray; + } + .receiver_info_scroll_view{ + width: 90%; + height: 200px; + margin-left: 4%; + margin-right: 4%; + margin-top: 10px; + margin-bottom: 25px; + border: 1px solid black; + } + .result{ + width: 90%; + height: 150px; + border: 1px solid black; + margin-left: 4%; + margin-bottom: 4%; + margin-top: 5%; + } + button{ + width: 90%; + margin-left: 5%; + margin-right: 5%; + } + .switch{ + float: right; + margin-right: 20px; + margin-bottom: 16px; + } + text{ + color: #fff; + display: block; + } + input{ + color: gainsboro; + float: left; + } + .v_net_ssid{ + width: 100%; + background: #fff; + } + .v_net_passw{ + width: 100%; + background: antiquewhite; + } + .swiper{ + width: 100%; + height: 100%; + } + +</style> -- Gitblit v1.9.3