tsc.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. var app = getApp();
  2. // var encode = require("./encoding.js");
  3. import encode from '@/unit/CHITEN_SDK_APP/encoding.js'
  4. var dlabelPrinter = {
  5. createNew: function() {
  6. var dlabelPrinter = {};
  7. var data = "";
  8. var command = []
  9. dlabelPrinter.name = "蓝牙打印机";
  10. dlabelPrinter.init = function() {};
  11. dlabelPrinter.addCommand = function(content) {
  12. var textencode = encode._this.TextEncoder(
  13. 'gb18030', {
  14. NONSTANDARD_allowLegacyEncoding: true
  15. });
  16. var code = textencode.encode(content);
  17. for (var i = 0; i < code.length; ++i) {
  18. command.push(code[i])
  19. }
  20. };
  21. dlabelPrinter.setSize = function(pageWidght, pageHeight) {
  22. data = "SIZE " + pageWidght.toString() + " mm" + "," + pageHeight.toString() + " mm" + "\r\n";
  23. dlabelPrinter.addCommand(data)
  24. };
  25. dlabelPrinter.setGap = function(printGap) {
  26. data = "GAP " + printGap.toString() + " mm,0 mm\r\n";
  27. dlabelPrinter.addCommand(data)
  28. };
  29. dlabelPrinter.setBline = function(printBline) {
  30. data = "BLINE " + printBline.toString() + " mm,0 mm\r\n";
  31. dlabelPrinter.addCommand(data)
  32. };
  33. dlabelPrinter.setOffset = function(offset) {
  34. data = "OFFSET " + offset.toString() + " mm,0 mm\r\n";
  35. dlabelPrinter.addCommand(data)
  36. };
  37. dlabelPrinter.setSpeed = function(printSpeed) {
  38. data = "SPEED " + printSpeed.toString() + "\r\n";
  39. dlabelPrinter.addCommand(data)
  40. };
  41. dlabelPrinter.setDensity = function(printDensity) {
  42. data = "DENSITY " + printDensity.toString() + "\r\n";
  43. dlabelPrinter.addCommand(data)
  44. }
  45. dlabelPrinter.setDirection = function(direction) {
  46. data = "DIRECTION " + direction + "\r\n";
  47. dlabelPrinter.addCommand(data)
  48. };
  49. dlabelPrinter.setReference = function(x, y) {
  50. data = "REFERENCE " + x + "," + y + "\r\n";
  51. dlabelPrinter.addCommand(data)
  52. };
  53. dlabelPrinter.setShift = function(n) {
  54. data = "SHIFT " + n + "\r\n";
  55. dlabelPrinter.addCommand(data)
  56. };
  57. dlabelPrinter.setCountry = function(country) {
  58. data = "COUNTRY " + country + "\r\n";
  59. dlabelPrinter.addCommand(data)
  60. };
  61. dlabelPrinter.setCodepage = function(codepage) {
  62. data = "CODEPAGE " + codepage + "\r\n";
  63. dlabelPrinter.addCommand(data)
  64. }
  65. dlabelPrinter.setCls = function() {
  66. data = "CLS\r\n";
  67. dlabelPrinter.addCommand(data)
  68. };
  69. dlabelPrinter.setFeed = function(feed) {
  70. data = "FEED " + feed + "\r\n";
  71. dlabelPrinter.addCommand(data)
  72. };
  73. dlabelPrinter.setBackFeed = function(backup) {
  74. data = "BACKFEED " + backup + "\r\n";
  75. dlabelPrinter.addCommand(data)
  76. }
  77. dlabelPrinter.setFromfeed = function() {
  78. data = "FORMFEED\r\n";
  79. dlabelPrinter.addCommand(data)
  80. };
  81. dlabelPrinter.setHome = function() {
  82. data = "HOME\r\n";
  83. dlabelPrinter.addCommand(data)
  84. };
  85. dlabelPrinter.setPagePrint = function() {
  86. data = "PRINT 1,1\r\n"
  87. dlabelPrinter.addCommand(data)
  88. };
  89. dlabelPrinter.setPrint = function(n) {
  90. data = "PRINT " + n + ",1\r\n"
  91. dlabelPrinter.addCommand(data)
  92. };
  93. dlabelPrinter.setSound = function(level, interval) {
  94. data = "SOUND " + level + "," + interval + "\r\n";
  95. dlabelPrinter.addCommand(data)
  96. };
  97. dlabelPrinter.setLimitfeed = function(limit) {
  98. data = "LIMITFEED " + limit + "mm\r\n";
  99. dlabelPrinter.addCommand(data)
  100. };
  101. dlabelPrinter.setSelfTest = function() {
  102. data = "SELFTEST\r\n";
  103. dlabelPrinter.addCommand(data)
  104. }
  105. dlabelPrinter.setBar = function(x, y, width, height) {
  106. data = "BAR " + x + "," + y + "," + width + "," + height + "\r\n"
  107. dlabelPrinter.addCommand(data)
  108. };
  109. dlabelPrinter.setBox = function(x_start, y_start, x_end, y_end, thickness) {
  110. data = "BOX " + x_start + "," + y_start + "," + x_end + "," + y_end + "," + thickness + "\r\n";
  111. dlabelPrinter.addCommand(data)
  112. };
  113. dlabelPrinter.setBarCode = function(x, y, codetype, height, readable, rotation, narrow, wide, content) {
  114. data = "BARCODE " + x + "," + y + ",\"" + codetype + "\"," + height + "," + readable + "," +
  115. rotation + "," + narrow + "," + wide + ",\"" + content + "\"\r\n"
  116. dlabelPrinter.addCommand(data)
  117. };
  118. dlabelPrinter.setBitmap = function(x, y, mode, res) {
  119. console.log(res)
  120. var w = res.width;
  121. var h = res.height;
  122. var bitw = parseInt((w + 7) / 8) * 8;
  123. var pitch = parseInt(bitw / 8);
  124. var bits = new Uint8Array(h * pitch);
  125. console.log("w=" + w + ", h=" + h + ", bitw=" + bitw + ", pitch=" + pitch + ", bits=" + bits
  126. .length);
  127. var cmd = "BITMAP " + x + "," + y + "," + pitch + "," + h + "," + mode + ",";
  128. console.log("add cmd: " + cmd);
  129. dlabelPrinter.addCommand(cmd);
  130. for (y = 0; y < h; y++) {
  131. for (x = 0; x < w; x++) {
  132. var color = res.data[(y * w + x) * 4 + 1];
  133. if (color <= 128) {
  134. bits[parseInt(y * pitch + x / 8)] |= (0x80 >> (x % 8));
  135. }
  136. }
  137. }
  138. for (var i = 0; i < bits.length; i++) {
  139. command.push((~bits[i]) & 0xFF);
  140. }
  141. console.log(command);
  142. };
  143. dlabelPrinter.setErase = function(x_start, y_start, x_width, y_height) {
  144. data = "ERASE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
  145. dlabelPrinter.addCommand(data)
  146. };
  147. dlabelPrinter.setReverse = function(x_start, y_start, x_width, y_height) {
  148. data = "REVERSE " + x_start + "," + y_start + "," + x_width + "," + y_height + "\r\n";
  149. dlabelPrinter.addCommand(data)
  150. };
  151. dlabelPrinter.setText = function(x, y, font, rotation, x_, y_, str) {
  152. data = "TEXT " + x + "," + y + ",\"" + font + "\"," + rotation + "," + x_ + "," + y_ + "," +
  153. "\"" + str + "\"\r\n"
  154. dlabelPrinter.addCommand(data)
  155. };
  156. dlabelPrinter.setQrcode = function(x, y, level, width, mode, content) {
  157. data = "QRCODE " + x + "," + y + "," + level + "," + width + "," + mode + "," + 0 + ",\"" +
  158. content + "\"\r\n"
  159. dlabelPrinter.addCommand(data)
  160. };
  161. dlabelPrinter.setKey1 = function(n) {
  162. data = "SET KYE1 " + n.toString + "\r\n"
  163. dlabelPrinter.addCommand(data)
  164. };
  165. dlabelPrinter.setKey2 = function(n) {
  166. data = "SET KYE2 " + n.toString + "\r\n"
  167. dlabelPrinter.addCommand(data)
  168. };
  169. dlabelPrinter.setPeel = function(n) {
  170. data = "SET PEEL " + n.toString + "\r\n"
  171. dlabelPrinter.addCommand(data)
  172. };
  173. dlabelPrinter.setTear = function(n) {
  174. data = "SET TEAR " + n.toString + "\r\n"
  175. dlabelPrinter.addCommand(data)
  176. };
  177. dlabelPrinter.setStripper = function(n) {
  178. data = "SET STRIPPER " + n.toString + "\r\n"
  179. dlabelPrinter.addCommand(data)
  180. };
  181. dlabelPrinter.setHead = function(n) {
  182. data = "SET HEAD " + n.toString + "\r\n"
  183. dlabelPrinter.addCommand(data)
  184. };
  185. dlabelPrinter.setReprint = function(n) {
  186. data = "SET REPRINT " + n.toString + "\r\n"
  187. dlabelPrinter.addCommand(data)
  188. };
  189. dlabelPrinter.setRibbon = function(n) {
  190. data = "SET RIBBON " + n.toString + "\r\n"
  191. dlabelPrinter.addCommand(data)
  192. };
  193. dlabelPrinter.setCut = function(n) {
  194. data = "SET CUTTER " + n.toString + "\r\n"
  195. dlabelPrinter.addCommand(data)
  196. };
  197. dlabelPrinter.getData = function() {
  198. return command;
  199. };
  200. return dlabelPrinter;
  201. }
  202. };
  203. export default {
  204. dlabelPrinter
  205. }
  206. // module.exports.dlabelPrinter = dlabelPrinter;