| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- var app = getApp();
- // var encode = require("./encoding.js");
- import encode from '@/unit/CHITEN_SDK_APP/encoding.js'
- var dlabelPrinter = {
- createNew: function() {
- var dlabelPrinter = {};
- var data = "";
- var command = []
- dlabelPrinter.name = "蓝牙打印机";
- dlabelPrinter.init = function() {};
- dlabelPrinter.addCommand = function(content) {
- var textencode = encode._this.TextEncoder(
- 'gb18030', {
- NONSTANDARD_allowLegacyEncoding: true
- });
- var code = textencode.encode(content);
- for (var i = 0; i < code.length; ++i) {
- command.push(code[i])
- }
- };
- dlabelPrinter.setSize = function(pageWidght, pageHeight) {
- data = "SIZE " + pageWidght.toString() + " mm" + "," + pageHeight.toString() + " mm" + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setGap = function(printGap) {
- data = "GAP " + printGap.toString() + " mm,0 mm\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setBline = function(printBline) {
- data = "BLINE " + printBline.toString() + " mm,0 mm\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setOffset = function(offset) {
- data = "OFFSET " + offset.toString() + " mm,0 mm\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setSpeed = function(printSpeed) {
- data = "SPEED " + printSpeed.toString() + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setDensity = function(printDensity) {
- data = "DENSITY " + printDensity.toString() + "\r\n";
- dlabelPrinter.addCommand(data)
- }
- dlabelPrinter.setDirection = function(direction) {
- data = "DIRECTION " + direction + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setReference = function(x, y) {
- data = "REFERENCE " + x + "," + y + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setShift = function(n) {
- data = "SHIFT " + n + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setCountry = function(country) {
- data = "COUNTRY " + country + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setCodepage = function(codepage) {
- data = "CODEPAGE " + codepage + "\r\n";
- dlabelPrinter.addCommand(data)
- }
- dlabelPrinter.setCls = function() {
- data = "CLS\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setFeed = function(feed) {
- data = "FEED " + feed + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setBackFeed = function(backup) {
- data = "BACKFEED " + backup + "\r\n";
- dlabelPrinter.addCommand(data)
- }
- dlabelPrinter.setFromfeed = function() {
- data = "FORMFEED\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setHome = function() {
- data = "HOME\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setPagePrint = function() {
- data = "PRINT 1,1\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setPrint = function(n) {
- data = "PRINT " + n + ",1\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setSound = function(level, interval) {
- data = "SOUND " + level + "," + interval + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setLimitfeed = function(limit) {
- data = "LIMITFEED " + limit + "mm\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setSelfTest = function() {
- data = "SELFTEST\r\n";
- dlabelPrinter.addCommand(data)
- }
- dlabelPrinter.setBar = function(x, y, width, height) {
- data = "BAR " + x + "," + y + "," + width + "," + height + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setBox = function(x_start, y_start, x_end, y_end, thickness) {
- data = "BOX " + x_start + "," + y_start + "," + x_end + "," + y_end + "," + thickness + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setBarCode = function(x, y, codetype, height, readable, rotation, narrow, wide, content) {
- data = "BARCODE " + x + "," + y + ",\"" + codetype + "\"," + height + "," + readable + "," +
- rotation + "," + narrow + "," + wide + ",\"" + content + "\"\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setBitmap = function(x, y, mode, res) {
- console.log(res)
- var w = res.width;
- var h = res.height;
- var bitw = parseInt((w + 7) / 8) * 8;
- var pitch = parseInt(bitw / 8);
- var bits = new Uint8Array(h * pitch);
- console.log("w=" + w + ", h=" + h + ", bitw=" + bitw + ", pitch=" + pitch + ", bits=" + bits
- .length);
- var cmd = "BITMAP " + x + "," + y + "," + pitch + "," + h + "," + mode + ",";
- console.log("add cmd: " + cmd);
- dlabelPrinter.addCommand(cmd);
- for (y = 0; y < h; y++) {
- for (x = 0; x < w; x++) {
- var color = res.data[(y * w + x) * 4 + 1];
- if (color <= 128) {
- bits[parseInt(y * pitch + x / 8)] |= (0x80 >> (x % 8));
- }
- }
- }
- for (var i = 0; i < bits.length; i++) {
- command.push((~bits[i]) & 0xFF);
- }
- console.log(command);
- };
- dlabelPrinter.setErase = function(x_start, y_start, x_width, y_height) {
- data = "ERASE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setReverse = function(x_start, y_start, x_width, y_height) {
- data = "REVERSE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setText = function(x, y, font, rotation, x_, y_, str) {
- data = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + x_ + "," + y_ + "," +
- "\"" + str + "\"\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setQrcode = function(x, y, level, width, mode, content) {
- data = "QRCODE " + x + "," + y + "," + level + "," + width + "," + mode + "," + 0 + ",\"" +
- content + "\"\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setKey1 = function(n) {
- data = "SET KYE1 " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setKey2 = function(n) {
- data = "SET KYE2 " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setPeel = function(n) {
- data = "SET PEEL " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setTear = function(n) {
- data = "SET TEAR " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setStripper = function(n) {
- data = "SET STRIPPER " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setHead = function(n) {
- data = "SET HEAD " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setReprint = function(n) {
- data = "SET REPRINT " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setRibbon = function(n) {
- data = "SET RIBBON " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.setCut = function(n) {
- data = "SET CUTTER " + n.toString + "\r\n"
- dlabelPrinter.addCommand(data)
- };
- dlabelPrinter.getData = function() {
- return command;
- };
- return dlabelPrinter;
- }
- };
- export default {
- dlabelPrinter
- }
- // module.exports.dlabelPrinter = dlabelPrinter;
|