label.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. <template>
  2. <view>
  3. <radio-group @change="radioChange">
  4. <label class="uni-list-cell uni-list-cell-pd">
  5. <label class="radio">
  6. <radio value="rbBT2" checked="true" />BT2.0
  7. </label>
  8. <uni-data-select v-model="udsBT2Value" :localdata="udsBT2Range"></uni-data-select>
  9. </label>
  10. <label class="uni-list-cell uni-list-cell-pd">
  11. <label class="radio">
  12. <radio value="rbNET" />NET
  13. </label>
  14. <uni-data-select v-model="udsNETValue" :localdata="udsNETRange"></uni-data-select>
  15. </label>
  16. <label class="uni-list-cell uni-list-cell-pd">
  17. <label class="radio">
  18. <radio value="rbUSB" />USB
  19. </label>
  20. <uni-data-select v-model="udsUSBValue" :localdata="udsUSBRange"></uni-data-select>
  21. </label>
  22. <label class="uni-list-cell uni-list-cell-pd">
  23. <label class="radio">
  24. <radio value="rbCOM" />COM
  25. </label>
  26. <uni-data-select v-model="udsCOMValue" :localdata="udsCOMRange"></uni-data-select>
  27. <uni-data-select v-model="udsCOMBaudrateValue" :localdata="udsCOMBaudrateRange"></uni-data-select>
  28. <uni-data-select v-model="udsCOMFlowControlValue" :localdata="udsCOMFlowControlRange"></uni-data-select>
  29. </label>
  30. </radio-group>
  31. <view class="uni-flex uni-row">
  32. <button type="default" @click="enumPort">Enum Port</button>
  33. <button type="default" @click="openPort" :disabled="btnOpenPortDisabled">Open Port</button>
  34. <button type="default" @click="closePort" :disabled="btnClosePortDisabled">Close Port</button>
  35. </view>
  36. <view>
  37. <button type="primary" @click="Test_Label_SampleTicket_58MM_1">Test_Label_SampleTicket_58MM_1</button>
  38. <button type="primary" @click="Test_Label_SampleTicket_80MM_1">Test_Label_SampleTicket_80MM_1</button>
  39. <button type="primary" @click="GetPrinterResolutionInfo">GetPrinterResolutionInfo</button>
  40. <button type="primary" @click="GetPrinterFirmwareVersion">GetPrinterFirmwareVersion</button>
  41. <button type="primary" @click="GetPrinterStatusInfo">GetPrinterStatusInfo</button>
  42. <button type="primary" @click="CP_Pos_KickOutDrawer">CP_Pos_KickOutDrawer</button>
  43. <button type="primary" @click="CP_Pos_Beep">CP_Pos_Beep</button>
  44. <button type="primary" @click="CP_Pos_PrintSelfTestPage">CP_Pos_PrintSelfTestPage</button>
  45. <button type="primary" @click="CP_Pos_ResetPrinter">CP_Pos_ResetPrinter</button>
  46. <button type="primary" @click="CP_Pos_SetPrintSpeed_100">CP_Pos_SetPrintSpeed_100</button>
  47. <button type="primary" @click="CP_Pos_SetPrintSpeed_150">CP_Pos_SetPrintSpeed_150</button>
  48. <button type="primary" @click="CP_Pos_SetPrintDensity_7">CP_Pos_SetPrintDensity_7</button>
  49. <button type="primary" @click="CP_Pos_SetPrintDensity_15">CP_Pos_SetPrintDensity_15</button>
  50. <button type="primary" @click="CP_Label_EnableLabelMode">CP_Label_EnableLabelMode</button>
  51. <button type="primary" @click="CP_Label_DisableLabelMode">CP_Label_DisableLabelMode</button>
  52. <button type="primary" @click="CP_Label_CalibrateLabel">CP_Label_CalibrateLabel</button>
  53. <button type="primary" @click="CP_Label_FeedLabel">CP_Label_FeedLabel</button>
  54. <button type="primary" @click="CP_Label_PageBegin">CP_Label_PageBegin</button>
  55. <button type="primary" @click="CP_Label_PagePrint">CP_Label_PagePrint</button>
  56. <button type="primary" @click="CP_Label_DrawText">CP_Label_DrawText</button>
  57. <button type="primary" @click="CP_Label_DrawTextInUTF8">CP_Label_DrawTextInUTF8</button>
  58. <button type="primary" @click="CP_Label_DrawTextInGBK">CP_Label_DrawTextInGBK</button>
  59. <button type="primary" @click="CP_Label_DrawBarcode">CP_Label_DrawBarcode</button>
  60. <button type="primary" @click="CP_Label_DrawQRCode">CP_Label_DrawQRCode</button>
  61. <button type="primary" @click="CP_Label_DrawPDF417Code">CP_Label_DrawPDF417Code</button>
  62. <button type="primary" @click="CP_Label_DrawImageFromFile">CP_Label_DrawImageFromFile</button>
  63. <button type="primary" @click="CP_Label_DrawImageFromPixels">CP_Label_DrawImageFromPixels</button>
  64. <button type="primary" @click="CP_Label_DrawLine">CP_Label_DrawLine</button>
  65. <button type="primary" @click="CP_Label_DrawRect">CP_Label_DrawRect</button>
  66. <button type="primary" @click="CP_Label_DrawBox">CP_Label_DrawBox</button>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. const modal = uni.requireNativePlugin('modal');
  72. var AutoReplyPrintUniModule = uni.requireNativePlugin("AutoReplyPrintUniModule");
  73. var hPrinter = 0;
  74. var isEnumeratingBT2 = false;
  75. var isEnumeratingNET = false;
  76. var selectedPortType = 'rbBT2';
  77. export default {
  78. data() {
  79. return {
  80. udsBT2Value: 0,
  81. udsBT2Range: [],
  82. udsNETValue: 0,
  83. udsNETRange: [],
  84. udsUSBValue: 0,
  85. udsUSBRange: [],
  86. udsCOMValue: 0,
  87. udsCOMRange: [],
  88. udsCOMBaudrateValue: 9600,
  89. udsCOMBaudrateRange: [{
  90. text: '9600',
  91. value: 9600
  92. },
  93. {
  94. text: '19200',
  95. value: 19200
  96. },
  97. {
  98. text: '38400',
  99. value: 38400
  100. },
  101. {
  102. text: '57600',
  103. value: 57600
  104. },
  105. {
  106. text: '115200',
  107. value: 115200
  108. },
  109. {
  110. text: '230400',
  111. value: 230400
  112. },
  113. {
  114. text: '256000',
  115. value: 256000
  116. },
  117. {
  118. text: '500000',
  119. value: 500000
  120. },
  121. ],
  122. udsCOMFlowControlValue: 0,
  123. udsCOMFlowControlRange: [{
  124. text: 'NoFlowControl',
  125. value: 0
  126. },
  127. {
  128. text: 'Hardware',
  129. value: 2
  130. },
  131. ],
  132. btnOpenPortDisabled: false,
  133. btnClosePortDisabled: true,
  134. }
  135. },
  136. onLoad() {
  137. uni.setNavigationBarTitle({
  138. title: 'SampleLabel ' + AutoReplyPrintUniModule.CP_Library_Version()
  139. });
  140. },
  141. onReady() {
  142. //要做到第一次进入界面的时候,自动搜索一次。这样用不行。
  143. //enumPort();
  144. },
  145. methods: {
  146. radioChange: function(evt) {
  147. selectedPortType = evt.detail.value;
  148. },
  149. enumPort() {
  150. var newComRange = new Array();
  151. var comNameList = AutoReplyPrintUniModule.CP_Port_EnumCom();
  152. if (comNameList != null) {
  153. for (var i = 0; i < comNameList.length; i++) {
  154. var tmp = {
  155. text: comNameList[i],
  156. value: i
  157. };
  158. console.log(tmp);
  159. newComRange.push(tmp);
  160. }
  161. }
  162. this.udsCOMRange = newComRange;
  163. var newUsbRange = new Array();
  164. var usbNameList = AutoReplyPrintUniModule.CP_Port_EnumUsb();
  165. if (usbNameList != null) {
  166. for (var i = 0; i < usbNameList.length; i++) {
  167. var tmp = {
  168. text: usbNameList[i],
  169. value: i
  170. };
  171. console.log(tmp);
  172. newUsbRange.push(tmp);
  173. }
  174. }
  175. this.udsUSBRange = newUsbRange;
  176. if (!isEnumeratingBT2) {
  177. isEnumeratingBT2 = true;
  178. console.log('isEnumeratingBT2');
  179. AutoReplyPrintUniModule.CP_Port_EnumBtDevice(
  180. 12000,
  181. (ret) => {
  182. //console.log(ret);
  183. var text = ret.device_address + '(' + ret.device_name + ')';
  184. for (var i = 0; i < this.udsBT2Range.length; i++) {
  185. if (this.udsBT2Range[i].text == text) {
  186. return;
  187. }
  188. }
  189. var tmp = {
  190. text: text,
  191. value: this.udsBT2Range.length
  192. };
  193. console.log(tmp);
  194. this.udsBT2Range.push(tmp);
  195. },
  196. (ret) => {
  197. isEnumeratingBT2 = false;
  198. console.log('finishedEnumeratingBT2');
  199. }
  200. );
  201. }
  202. if (!isEnumeratingNET) {
  203. isEnumeratingNET = true;
  204. console.log('isEnumeratingNET');
  205. AutoReplyPrintUniModule.CP_Port_EnumNetPrinter(
  206. 12000,
  207. (ret) => {
  208. //console.log(ret);
  209. var text = ret.discovered_ip + '(' + ret.discovered_name + ')';
  210. for (var i = 0; i < this.udsNETRange.length; i++) {
  211. if (this.udsNETRange[i].text == text) {
  212. return;
  213. }
  214. }
  215. var tmp = {
  216. text: text,
  217. value: this.udsNETRange.length
  218. };
  219. console.log(tmp);
  220. this.udsNETRange.push(tmp);
  221. },
  222. (ret) => {
  223. isEnumeratingNET = false;
  224. console.log('finishedEnumeratingNET');
  225. }
  226. );
  227. }
  228. },
  229. openPort() {
  230. if (hPrinter == 0) {
  231. if (selectedPortType == 'rbBT2') {
  232. var text = this.udsBT2Range[this.udsBT2Value].text;
  233. var btAddress = text.substring(0, text.indexOf('('));
  234. modal.toast({
  235. message: 'Connecting: ' + btAddress + ' ......',
  236. duration: 1.5
  237. });
  238. console.log('Connecting: ' + btAddress + ' ......');
  239. hPrinter = AutoReplyPrintUniModule.CP_Port_OpenBtSpp(btAddress, 1);
  240. console.log('hPrinter: ' + hPrinter);
  241. } else if (selectedPortType == 'rbNET') {
  242. var text = this.udsNETRange[this.udsNETValue].text;
  243. var ipAddress = text.substring(0, text.indexOf('('));
  244. modal.toast({
  245. message: 'Connecting: ' + ipAddress + ' ......',
  246. duration: 1.5
  247. });
  248. console.log('Connecting: ' + ipAddress + ' ......');
  249. hPrinter = AutoReplyPrintUniModule.CP_Port_OpenTcp(null, ipAddress, 9100, 5000, 1);
  250. console.log('hPrinter: ' + hPrinter);
  251. } else if (selectedPortType == 'rbUSB') {
  252. var usbName = this.udsUSBRange[this.udsUSBValue].text;
  253. modal.toast({
  254. message: 'Connecting: ' + usbName + ' ......',
  255. duration: 1.5
  256. });
  257. console.log('Connecting: ' + usbName + ' ......');
  258. hPrinter = AutoReplyPrintUniModule.CP_Port_OpenUsb(usbName, 1);
  259. console.log('hPrinter: ' + hPrinter);
  260. } else if (selectedPortType == 'rbCOM') {
  261. var comName = this.udsCOMRange[this.udsCOMValue].text;
  262. var comBaudrate = this.udsCOMBaudrateValue;
  263. var comFlowControl = this.udsCOMFlowControlValue;
  264. modal.toast({
  265. message: 'Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl +
  266. ' ......',
  267. duration: 1.5
  268. });
  269. console.log('Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl + '......');
  270. hPrinter = AutoReplyPrintUniModule.CP_Port_OpenCom(comName, comBaudrate, 8, 0, 0, comFlowControl,
  271. 1);
  272. console.log('hPrinter: ' + hPrinter);
  273. }
  274. modal.toast({
  275. message: (hPrinter != 0) ? 'Connected' : 'Failed',
  276. duration: 1.5
  277. });
  278. }
  279. this.btnOpenPortDisabled = (hPrinter != 0);
  280. this.btnClosePortDisabled = (hPrinter == 0);
  281. },
  282. closePort() {
  283. if (hPrinter != 0) {
  284. AutoReplyPrintUniModule.CP_Port_Close(hPrinter);
  285. hPrinter = 0;
  286. }
  287. this.btnOpenPortDisabled = (hPrinter != 0);
  288. this.btnClosePortDisabled = (hPrinter == 0);
  289. },
  290. Test_Label_SampleTicket_58MM_1() {
  291. AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
  292. AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
  293. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 240, 0);
  294. AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号:P58A+");
  295. AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG :00");
  296. AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 2, 0, "No.123456");
  297. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  298. //AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
  299. //AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);
  300. var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
  301. modal.toast({
  302. message: printResult ? 'Print Success' : 'Print Failed',
  303. duration: 1.5
  304. });
  305. },
  306. Test_Label_SampleTicket_80MM_1() {
  307. AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
  308. AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
  309. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 576, 240, 0);
  310. AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号:P80A+");
  311. AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG :00");
  312. AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 4, 0, "No.123456");
  313. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  314. //AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
  315. //AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);
  316. var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
  317. modal.toast({
  318. message: printResult ? 'Print Success' : 'Print Failed',
  319. duration: 1.5
  320. });
  321. },
  322. GetPrinterResolutionInfo() {
  323. var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterResolutionInfo(hPrinter);
  324. modal.toast({
  325. message: ret,
  326. duration: 1.5
  327. });
  328. },
  329. GetPrinterFirmwareVersion() {
  330. var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterFirmwareVersion(hPrinter);
  331. modal.toast({
  332. message: ret,
  333. duration: 1.5
  334. });
  335. },
  336. GetPrinterStatusInfo() {
  337. var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterStatusInfo(hPrinter);
  338. var status_time = new Date(ret.timestamp_ms);
  339. var printer_error_status = ret.printer_error_status;
  340. var status_str = '';
  341. if (printer_error_status != 0) {
  342. status_str += 'ERROR_OCCURED\n'; //错误状态非零表示出错了
  343. if ((printer_error_status & 0x01) != 0) {
  344. status_str += 'ERROR_CUTTER\n'; //(切刀出错)
  345. }
  346. if ((printer_error_status & 0x02) != 0) {
  347. status_str += 'ERROR_FLASH\n'; //(FLASH 异常)
  348. }
  349. if ((printer_error_status & 0x04) != 0) {
  350. status_str += 'ERROR_NOPAPER\n'; //(缺纸)
  351. }
  352. if ((printer_error_status & 0x08) != 0) {
  353. status_str += 'ERROR_VOLTAGE\n'; //(电压异常)
  354. }
  355. if ((printer_error_status & 0x10) != 0) {
  356. status_str += 'ERROR_MARKER\n'; //(缝标或黑标定位异常)
  357. }
  358. if ((printer_error_status & 0x20) != 0) {
  359. status_str += 'ERROR_ENGINE\n'; //(机芯异常)
  360. }
  361. if ((printer_error_status & 0x40) != 0) {
  362. status_str += 'ERROR_OVERHEAT\n'; //(过热)
  363. }
  364. if ((printer_error_status & 0x80) != 0) {
  365. status_str += 'ERROR_COVERUP\n'; //(纸仓盖被打开了)
  366. }
  367. if ((printer_error_status & 0x100) != 0) {
  368. status_str += 'ERROR_MOTOR\n'; //(马达异常)
  369. }
  370. } else {
  371. status_str += 'Status OK\n';
  372. }
  373. modal.toast({
  374. message: '' + status_time + '\n' + status_str,
  375. duration: 1.5
  376. });
  377. },
  378. CP_Pos_KickOutDrawer() {
  379. var ret = AutoReplyPrintUniModule.CP_Pos_KickOutDrawer(hPrinter, 0, 100, 100);
  380. modal.toast({
  381. message: ret,
  382. duration: 1.5
  383. });
  384. },
  385. CP_Pos_Beep() {
  386. var ret = AutoReplyPrintUniModule.CP_Pos_Beep(hPrinter, 3, 500);
  387. modal.toast({
  388. message: ret,
  389. duration: 1.5
  390. });
  391. },
  392. CP_Pos_PrintSelfTestPage() {
  393. var ret = AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
  394. modal.toast({
  395. message: ret,
  396. duration: 1.5
  397. });
  398. },
  399. CP_Pos_ResetPrinter() {
  400. var ret = AutoReplyPrintUniModule.CP_Pos_ResetPrinter(hPrinter);
  401. modal.toast({
  402. message: ret,
  403. duration: 1.5
  404. });
  405. },
  406. CP_Pos_SetPrintSpeed_100() {
  407. var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 100);
  408. AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
  409. modal.toast({
  410. message: ret,
  411. duration: 1.5
  412. });
  413. },
  414. CP_Pos_SetPrintSpeed_150() {
  415. var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 150);
  416. AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
  417. modal.toast({
  418. message: ret,
  419. duration: 1.5
  420. });
  421. },
  422. CP_Pos_SetPrintDensity_7() {
  423. var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 7);
  424. AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
  425. modal.toast({
  426. message: ret,
  427. duration: 1.5
  428. });
  429. },
  430. CP_Pos_SetPrintDensity_15() {
  431. var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 15);
  432. AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
  433. modal.toast({
  434. message: ret,
  435. duration: 1.5
  436. });
  437. },
  438. CP_Label_EnableLabelMode() {
  439. var ret = AutoReplyPrintUniModule.CP_Label_EnableLabelMode(hPrinter);
  440. modal.toast({
  441. message: ret,
  442. duration: 1.5
  443. });
  444. },
  445. CP_Label_DisableLabelMode() {
  446. var ret = AutoReplyPrintUniModule.CP_Label_DisableLabelMode(hPrinter);
  447. modal.toast({
  448. message: ret,
  449. duration: 1.5
  450. });
  451. },
  452. CP_Label_CalibrateLabel() {
  453. var ret = AutoReplyPrintUniModule.CP_Label_CalibrateLabel(hPrinter);
  454. modal.toast({
  455. message: ret,
  456. duration: 1.5
  457. });
  458. },
  459. CP_Label_FeedLabel() {
  460. var ret = AutoReplyPrintUniModule.CP_Label_FeedLabel(hPrinter);
  461. modal.toast({
  462. message: ret,
  463. duration: 1.5
  464. });
  465. },
  466. CP_Label_PageBegin() {
  467. var ret = AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  468. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  469. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  470. modal.toast({
  471. message: ret,
  472. duration: 1.5
  473. });
  474. },
  475. CP_Label_PagePrint() {
  476. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  477. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  478. var ret = AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  479. modal.toast({
  480. message: ret,
  481. duration: 1.5
  482. });
  483. },
  484. CP_Label_DrawText() {
  485. var str = "$$$123哈哈哈";
  486. AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
  487. AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
  488. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  489. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  490. var ret = AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, str);
  491. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  492. modal.toast({
  493. message: ret,
  494. duration: 1.5
  495. });
  496. },
  497. CP_Label_DrawTextInUTF8() {
  498. var str = "$$$123哈哈哈";
  499. AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
  500. AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
  501. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  502. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  503. var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInUTF8(hPrinter, 10, 10, 24, 0, str);
  504. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  505. modal.toast({
  506. message: ret,
  507. duration: 1.5
  508. });
  509. },
  510. CP_Label_DrawTextInGBK() {
  511. var str = "$$$123哈哈哈";
  512. AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
  513. AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 0);
  514. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  515. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  516. var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInGBK(hPrinter, 10, 10, 24, 0, str);
  517. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  518. modal.toast({
  519. message: ret,
  520. duration: 1.5
  521. });
  522. },
  523. CP_Label_DrawBarcode() {
  524. var str = "01234567890";
  525. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  526. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  527. var ret = AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 10, 0, 2, 60, 2, 0, str);
  528. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  529. modal.toast({
  530. message: ret,
  531. duration: 1.5
  532. });
  533. },
  534. CP_Label_DrawQRCode() {
  535. var str = "Hello 你好";
  536. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  537. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  538. var ret = AutoReplyPrintUniModule.CP_Label_DrawQRCode(hPrinter, 10, 10, 0, 1, 8, 0, str);
  539. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  540. modal.toast({
  541. message: ret,
  542. duration: 1.5
  543. });
  544. },
  545. CP_Label_DrawPDF417Code() {
  546. var str = "Hello 你好";
  547. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  548. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  549. var ret = AutoReplyPrintUniModule.CP_Label_DrawPDF417Code(hPrinter, 10, 10, 3, 3, 0, 3, 0, str);
  550. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  551. modal.toast({
  552. message: ret,
  553. duration: 1.5
  554. });
  555. },
  556. CP_Label_DrawImageFromFile() {
  557. uni.chooseImage({
  558. count: 1, //默认9
  559. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  560. sourceType: ['album'], //从相册选择
  561. success: function(res) {
  562. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  563. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  564. var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromFile(hPrinter, 0, 0, 384, 0,
  565. res.tempFilePaths[0], 2, 0);
  566. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  567. modal.toast({
  568. message: ret,
  569. duration: 1.5
  570. });
  571. }
  572. });
  573. },
  574. CP_Label_DrawImageFromPixels() {
  575. var image_width = 100;
  576. var image_height = 100;
  577. var image_pixels_array = new Uint8Array(image_width * image_height * 4);
  578. for (let y = 0; y < image_height; ++y) {
  579. for (let x = 0; x < image_width; ++x) {
  580. var offset = y * image_width * 4 + x * 4;
  581. if (x == y) {
  582. image_pixels_array[offset] = 0x00;
  583. image_pixels_array[offset + 1] = 0x00;
  584. image_pixels_array[offset + 2] = 0x00;
  585. image_pixels_array[offset + 3] = 0xff;
  586. } else {
  587. image_pixels_array[offset] = 0xff;
  588. image_pixels_array[offset + 1] = 0xff;
  589. image_pixels_array[offset + 2] = 0xff;
  590. image_pixels_array[offset + 3] = 0xff;
  591. }
  592. }
  593. }
  594. var image_pixels_base64 = uni.arrayBufferToBase64(image_pixels_array);
  595. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  596. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  597. var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromPixels(hPrinter, 0, 0, image_pixels_base64,
  598. image_width, image_height, image_width * 4, 7, 2, 0);
  599. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  600. modal.toast({
  601. message: ret,
  602. duration: 1.5
  603. });
  604. },
  605. CP_Label_DrawLine() {
  606. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  607. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  608. var ret = AutoReplyPrintUniModule.CP_Label_DrawLine(hPrinter, 20, 20, 100, 300, 1, 1);
  609. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  610. modal.toast({
  611. message: ret,
  612. duration: 1.5
  613. });
  614. },
  615. CP_Label_DrawRect() {
  616. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  617. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  618. var ret = AutoReplyPrintUniModule.CP_Label_DrawRect(hPrinter, 20, 20, 200, 10, 1);
  619. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  620. modal.toast({
  621. message: ret,
  622. duration: 1.5
  623. });
  624. },
  625. CP_Label_DrawBox() {
  626. AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
  627. AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
  628. var ret = AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 30, 30, 300, 200, 1, 1);
  629. AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
  630. modal.toast({
  631. message: ret,
  632. duration: 1.5
  633. });
  634. },
  635. }
  636. }
  637. </script>
  638. <style>
  639. </style>