|
@@ -0,0 +1,122 @@
|
|
|
+
|
|
|
+ * cpcl 命令打印工具类
|
|
|
+ * 2021.04.26 uni-app版本
|
|
|
+ * @auth boolTrue
|
|
|
+ */
|
|
|
+var gbk = require("./printUtil-GBK.js");
|
|
|
+var jpPrinter = {
|
|
|
+ createNew: function() {
|
|
|
+ var jpPrinter = {};
|
|
|
+ var data = "";
|
|
|
+ var command = []
|
|
|
+ var rawCommand = ''
|
|
|
+
|
|
|
+ jpPrinter.name = "标签模式";
|
|
|
+
|
|
|
+ jpPrinter.addCommand = function(content) {
|
|
|
+ rawCommand += content
|
|
|
+ }
|
|
|
+
|
|
|
+ jpPrinter.init = function(width, height, printNum, rotation = 0, offset = 0) {
|
|
|
+ var strCmd = '! ' + offset + ' 200 200 ' + height + ' ' + printNum + '\n';
|
|
|
+ strCmd += "PAGE-WIDTH " + width + '\n';
|
|
|
+ if (rotation == 1)
|
|
|
+ strCmd += "ZPROTATE90\n";
|
|
|
+ else if (rotation == 2)
|
|
|
+ strCmd += "ZPROTATE180\n";
|
|
|
+ else if (rotation == 3)
|
|
|
+ strCmd += "ZPROTATE270\n";
|
|
|
+ else
|
|
|
+ strCmd += "ZPROTATE0\n";
|
|
|
+ jpPrinter.addCommand(strCmd)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setText = function(x, y, font, xsize, ysize, str) {
|
|
|
+ data = "T " + "4" + " " + xsize + " " + x + " " + y + " " + str + "\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setGap = function(pageWidth) {
|
|
|
+ data = "GAP-SENSE" + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setSpeed = function(printSpeed) {
|
|
|
+ data = "SPEED " + printSpeed + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setDensity = function(printDensity) {
|
|
|
+ data = "CONTRAST " + printDensity + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setMag = function(w,h) {
|
|
|
+ data = "SETMAG " + w + " " + h + "\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setLine = function(x0, y0, x1, y1, width) {
|
|
|
+ data = "LINE " + x0 + " " + y0 + " " + x1 + " " + y1 + " " + width + "\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setBox = function(x_start, y_start, x_end, y_end, thickness) {
|
|
|
+ data = "BOX " + x_start + " " + y_start + " " + x_end + " " + y_end + " " + thickness + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setFeed = function(feed) {
|
|
|
+ data = "PREFEED " + feed + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setQR = function(x, y, level, ver, scale, content) {
|
|
|
+ var strCmd = 'B QR ' + x + ' ' + y + ' M ' + ver + ' U ' + scale + '\n' + level + 'A,' + content + '\n';
|
|
|
+ strCmd += 'ENDQR\n';
|
|
|
+ jpPrinter.addCommand(strCmd)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setBar = function(type, width, ratio, height, x, y, content) {
|
|
|
+ data = "BARCODE " + type + " " + width + " " + ratio + " " + height + " " + x + " " + y + " " + content + "\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setSound = function(interval) {
|
|
|
+ data = "BEEP " + interval + "\n";
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setPageForm = function() {
|
|
|
+ data = "FORM "+"\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.setPagePrint = function() {
|
|
|
+ data = "PRINT "+"\n"
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ jpPrinter.RawCommand = function(data) {
|
|
|
+ jpPrinter.addCommand(data)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ jpPrinter.getData = function() {
|
|
|
+ let buffer = gbk.strToGBKByte(rawCommand)
|
|
|
+ return buffer;
|
|
|
+ };
|
|
|
+
|
|
|
+ jpPrinter.getRawData = function() {
|
|
|
+ return rawCommand;
|
|
|
+ };
|
|
|
+ jpPrinter.clearCommand = function() {
|
|
|
+ rawCommand = ''
|
|
|
+ };
|
|
|
+
|
|
|
+ return jpPrinter;
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+module.exports.jpPrinter = jpPrinter;
|