123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686 |
- <template>
- <view>
- <radio-group @change="radioChange">
- <label class="uni-list-cell uni-list-cell-pd">
- <label class="radio">
- <radio value="rbBT2" checked="true" />BT2.0
- </label>
- <uni-data-select v-model="udsBT2Value" :localdata="udsBT2Range"></uni-data-select>
- </label>
- <label class="uni-list-cell uni-list-cell-pd">
- <label class="radio">
- <radio value="rbNET" />NET
- </label>
- <uni-data-select v-model="udsNETValue" :localdata="udsNETRange"></uni-data-select>
- </label>
- <label class="uni-list-cell uni-list-cell-pd">
- <label class="radio">
- <radio value="rbUSB" />USB
- </label>
- <uni-data-select v-model="udsUSBValue" :localdata="udsUSBRange"></uni-data-select>
- </label>
- <label class="uni-list-cell uni-list-cell-pd">
- <label class="radio">
- <radio value="rbCOM" />COM
- </label>
- <uni-data-select v-model="udsCOMValue" :localdata="udsCOMRange"></uni-data-select>
- <uni-data-select v-model="udsCOMBaudrateValue" :localdata="udsCOMBaudrateRange"></uni-data-select>
- <uni-data-select v-model="udsCOMFlowControlValue" :localdata="udsCOMFlowControlRange"></uni-data-select>
- </label>
- </radio-group>
- <view class="uni-flex uni-row">
- <button type="default" @click="enumPort">Enum Port</button>
- <button type="default" @click="openPort" :disabled="btnOpenPortDisabled">Open Port</button>
- <button type="default" @click="closePort" :disabled="btnClosePortDisabled">Close Port</button>
- </view>
- <view>
- <button type="primary" @click="Test_Label_SampleTicket_58MM_1">Test_Label_SampleTicket_58MM_1</button>
- <button type="primary" @click="Test_Label_SampleTicket_80MM_1">Test_Label_SampleTicket_80MM_1</button>
- <button type="primary" @click="GetPrinterResolutionInfo">GetPrinterResolutionInfo</button>
- <button type="primary" @click="GetPrinterFirmwareVersion">GetPrinterFirmwareVersion</button>
- <button type="primary" @click="GetPrinterStatusInfo">GetPrinterStatusInfo</button>
- <button type="primary" @click="CP_Pos_KickOutDrawer">CP_Pos_KickOutDrawer</button>
- <button type="primary" @click="CP_Pos_Beep">CP_Pos_Beep</button>
- <button type="primary" @click="CP_Pos_PrintSelfTestPage">CP_Pos_PrintSelfTestPage</button>
- <button type="primary" @click="CP_Pos_ResetPrinter">CP_Pos_ResetPrinter</button>
- <button type="primary" @click="CP_Pos_SetPrintSpeed_100">CP_Pos_SetPrintSpeed_100</button>
- <button type="primary" @click="CP_Pos_SetPrintSpeed_150">CP_Pos_SetPrintSpeed_150</button>
- <button type="primary" @click="CP_Pos_SetPrintDensity_7">CP_Pos_SetPrintDensity_7</button>
- <button type="primary" @click="CP_Pos_SetPrintDensity_15">CP_Pos_SetPrintDensity_15</button>
- <button type="primary" @click="CP_Label_EnableLabelMode">CP_Label_EnableLabelMode</button>
- <button type="primary" @click="CP_Label_DisableLabelMode">CP_Label_DisableLabelMode</button>
- <button type="primary" @click="CP_Label_CalibrateLabel">CP_Label_CalibrateLabel</button>
- <button type="primary" @click="CP_Label_FeedLabel">CP_Label_FeedLabel</button>
- <button type="primary" @click="CP_Label_PageBegin">CP_Label_PageBegin</button>
- <button type="primary" @click="CP_Label_PagePrint">CP_Label_PagePrint</button>
- <button type="primary" @click="CP_Label_DrawText">CP_Label_DrawText</button>
- <button type="primary" @click="CP_Label_DrawTextInUTF8">CP_Label_DrawTextInUTF8</button>
- <button type="primary" @click="CP_Label_DrawTextInGBK">CP_Label_DrawTextInGBK</button>
- <button type="primary" @click="CP_Label_DrawBarcode">CP_Label_DrawBarcode</button>
- <button type="primary" @click="CP_Label_DrawQRCode">CP_Label_DrawQRCode</button>
- <button type="primary" @click="CP_Label_DrawPDF417Code">CP_Label_DrawPDF417Code</button>
- <button type="primary" @click="CP_Label_DrawImageFromFile">CP_Label_DrawImageFromFile</button>
- <button type="primary" @click="CP_Label_DrawImageFromPixels">CP_Label_DrawImageFromPixels</button>
- <button type="primary" @click="CP_Label_DrawLine">CP_Label_DrawLine</button>
- <button type="primary" @click="CP_Label_DrawRect">CP_Label_DrawRect</button>
- <button type="primary" @click="CP_Label_DrawBox">CP_Label_DrawBox</button>
- </view>
- </view>
- </template>
- <script>
- const modal = uni.requireNativePlugin('modal');
- var AutoReplyPrintUniModule = uni.requireNativePlugin("AutoReplyPrintUniModule");
- var hPrinter = 0;
- var isEnumeratingBT2 = false;
- var isEnumeratingNET = false;
- var selectedPortType = 'rbBT2';
- export default {
- data() {
- return {
- udsBT2Value: 0,
- udsBT2Range: [],
- udsNETValue: 0,
- udsNETRange: [],
- udsUSBValue: 0,
- udsUSBRange: [],
- udsCOMValue: 0,
- udsCOMRange: [],
- udsCOMBaudrateValue: 9600,
- udsCOMBaudrateRange: [{
- text: '9600',
- value: 9600
- },
- {
- text: '19200',
- value: 19200
- },
- {
- text: '38400',
- value: 38400
- },
- {
- text: '57600',
- value: 57600
- },
- {
- text: '115200',
- value: 115200
- },
- {
- text: '230400',
- value: 230400
- },
- {
- text: '256000',
- value: 256000
- },
- {
- text: '500000',
- value: 500000
- },
- ],
- udsCOMFlowControlValue: 0,
- udsCOMFlowControlRange: [{
- text: 'NoFlowControl',
- value: 0
- },
- {
- text: 'Hardware',
- value: 2
- },
- ],
- btnOpenPortDisabled: false,
- btnClosePortDisabled: true,
- }
- },
- onLoad() {
- uni.setNavigationBarTitle({
- title: 'SampleLabel ' + AutoReplyPrintUniModule.CP_Library_Version()
- });
- },
- onReady() {
- //要做到第一次进入界面的时候,自动搜索一次。这样用不行。
- //enumPort();
- },
- methods: {
- radioChange: function(evt) {
- selectedPortType = evt.detail.value;
- },
- enumPort() {
- var newComRange = new Array();
- var comNameList = AutoReplyPrintUniModule.CP_Port_EnumCom();
- if (comNameList != null) {
- for (var i = 0; i < comNameList.length; i++) {
- var tmp = {
- text: comNameList[i],
- value: i
- };
- console.log(tmp);
- newComRange.push(tmp);
- }
- }
- this.udsCOMRange = newComRange;
- var newUsbRange = new Array();
- var usbNameList = AutoReplyPrintUniModule.CP_Port_EnumUsb();
- if (usbNameList != null) {
- for (var i = 0; i < usbNameList.length; i++) {
- var tmp = {
- text: usbNameList[i],
- value: i
- };
- console.log(tmp);
- newUsbRange.push(tmp);
- }
- }
- this.udsUSBRange = newUsbRange;
- if (!isEnumeratingBT2) {
- isEnumeratingBT2 = true;
- console.log('isEnumeratingBT2');
- AutoReplyPrintUniModule.CP_Port_EnumBtDevice(
- 12000,
- (ret) => {
- //console.log(ret);
- var text = ret.device_address + '(' + ret.device_name + ')';
- for (var i = 0; i < this.udsBT2Range.length; i++) {
- if (this.udsBT2Range[i].text == text) {
- return;
- }
- }
- var tmp = {
- text: text,
- value: this.udsBT2Range.length
- };
- console.log(tmp);
- this.udsBT2Range.push(tmp);
- },
- (ret) => {
- isEnumeratingBT2 = false;
- console.log('finishedEnumeratingBT2');
- }
- );
- }
- if (!isEnumeratingNET) {
- isEnumeratingNET = true;
- console.log('isEnumeratingNET');
- AutoReplyPrintUniModule.CP_Port_EnumNetPrinter(
- 12000,
- (ret) => {
- //console.log(ret);
- var text = ret.discovered_ip + '(' + ret.discovered_name + ')';
- for (var i = 0; i < this.udsNETRange.length; i++) {
- if (this.udsNETRange[i].text == text) {
- return;
- }
- }
- var tmp = {
- text: text,
- value: this.udsNETRange.length
- };
- console.log(tmp);
- this.udsNETRange.push(tmp);
- },
- (ret) => {
- isEnumeratingNET = false;
- console.log('finishedEnumeratingNET');
- }
- );
- }
- },
- openPort() {
- if (hPrinter == 0) {
- if (selectedPortType == 'rbBT2') {
- var text = this.udsBT2Range[this.udsBT2Value].text;
- var btAddress = text.substring(0, text.indexOf('('));
- modal.toast({
- message: 'Connecting: ' + btAddress + ' ......',
- duration: 1.5
- });
- console.log('Connecting: ' + btAddress + ' ......');
- hPrinter = AutoReplyPrintUniModule.CP_Port_OpenBtSpp(btAddress, 1);
- console.log('hPrinter: ' + hPrinter);
- } else if (selectedPortType == 'rbNET') {
- var text = this.udsNETRange[this.udsNETValue].text;
- var ipAddress = text.substring(0, text.indexOf('('));
- modal.toast({
- message: 'Connecting: ' + ipAddress + ' ......',
- duration: 1.5
- });
- console.log('Connecting: ' + ipAddress + ' ......');
- hPrinter = AutoReplyPrintUniModule.CP_Port_OpenTcp(null, ipAddress, 9100, 5000, 1);
- console.log('hPrinter: ' + hPrinter);
- } else if (selectedPortType == 'rbUSB') {
- var usbName = this.udsUSBRange[this.udsUSBValue].text;
- modal.toast({
- message: 'Connecting: ' + usbName + ' ......',
- duration: 1.5
- });
- console.log('Connecting: ' + usbName + ' ......');
- hPrinter = AutoReplyPrintUniModule.CP_Port_OpenUsb(usbName, 1);
- console.log('hPrinter: ' + hPrinter);
- } else if (selectedPortType == 'rbCOM') {
- var comName = this.udsCOMRange[this.udsCOMValue].text;
- var comBaudrate = this.udsCOMBaudrateValue;
- var comFlowControl = this.udsCOMFlowControlValue;
- modal.toast({
- message: 'Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl +
- ' ......',
- duration: 1.5
- });
- console.log('Connecting: ' + comName + ',' + comBaudrate + ',' + comFlowControl + '......');
- hPrinter = AutoReplyPrintUniModule.CP_Port_OpenCom(comName, comBaudrate, 8, 0, 0, comFlowControl,
- 1);
- console.log('hPrinter: ' + hPrinter);
- }
- modal.toast({
- message: (hPrinter != 0) ? 'Connected' : 'Failed',
- duration: 1.5
- });
- }
- this.btnOpenPortDisabled = (hPrinter != 0);
- this.btnClosePortDisabled = (hPrinter == 0);
- },
- closePort() {
- if (hPrinter != 0) {
- AutoReplyPrintUniModule.CP_Port_Close(hPrinter);
- hPrinter = 0;
- }
- this.btnOpenPortDisabled = (hPrinter != 0);
- this.btnClosePortDisabled = (hPrinter == 0);
- },
- Test_Label_SampleTicket_58MM_1() {
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 240, 0);
- AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号:P58A+");
- AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG :00");
- AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 2, 0, "No.123456");
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- //AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
- //AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);
- var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
- modal.toast({
- message: printResult ? 'Print Success' : 'Print Failed',
- duration: 1.5
- });
- },
- Test_Label_SampleTicket_80MM_1() {
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 576, 240, 0);
- AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, "型号:P80A+");
- AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 40, 24, 0, "MFG :00");
- AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 70, 8, 2, 60, 4, 0, "No.123456");
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- //AutoReplyPrintUniModule.CP_Pos_HalfCutPaper(hPrinter);
- //AutoReplyPrintUniModule.CP_Pos_FullCutPaper(hPrinter);
- var printResult = AutoReplyPrintUniModule.CP_Pos_QueryPrintResult(hPrinter, 10000);
- modal.toast({
- message: printResult ? 'Print Success' : 'Print Failed',
- duration: 1.5
- });
- },
- GetPrinterResolutionInfo() {
- var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterResolutionInfo(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- GetPrinterFirmwareVersion() {
- var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterFirmwareVersion(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- GetPrinterStatusInfo() {
- var ret = AutoReplyPrintUniModule.CP_Printer_GetPrinterStatusInfo(hPrinter);
- var status_time = new Date(ret.timestamp_ms);
- var printer_error_status = ret.printer_error_status;
- var status_str = '';
- if (printer_error_status != 0) {
- status_str += 'ERROR_OCCURED\n'; //错误状态非零表示出错了
- if ((printer_error_status & 0x01) != 0) {
- status_str += 'ERROR_CUTTER\n'; //(切刀出错)
- }
- if ((printer_error_status & 0x02) != 0) {
- status_str += 'ERROR_FLASH\n'; //(FLASH 异常)
- }
- if ((printer_error_status & 0x04) != 0) {
- status_str += 'ERROR_NOPAPER\n'; //(缺纸)
- }
- if ((printer_error_status & 0x08) != 0) {
- status_str += 'ERROR_VOLTAGE\n'; //(电压异常)
- }
- if ((printer_error_status & 0x10) != 0) {
- status_str += 'ERROR_MARKER\n'; //(缝标或黑标定位异常)
- }
- if ((printer_error_status & 0x20) != 0) {
- status_str += 'ERROR_ENGINE\n'; //(机芯异常)
- }
- if ((printer_error_status & 0x40) != 0) {
- status_str += 'ERROR_OVERHEAT\n'; //(过热)
- }
- if ((printer_error_status & 0x80) != 0) {
- status_str += 'ERROR_COVERUP\n'; //(纸仓盖被打开了)
- }
- if ((printer_error_status & 0x100) != 0) {
- status_str += 'ERROR_MOTOR\n'; //(马达异常)
- }
- } else {
- status_str += 'Status OK\n';
- }
- modal.toast({
- message: '' + status_time + '\n' + status_str,
- duration: 1.5
- });
- },
- CP_Pos_KickOutDrawer() {
- var ret = AutoReplyPrintUniModule.CP_Pos_KickOutDrawer(hPrinter, 0, 100, 100);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_Beep() {
- var ret = AutoReplyPrintUniModule.CP_Pos_Beep(hPrinter, 3, 500);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_PrintSelfTestPage() {
- var ret = AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_ResetPrinter() {
- var ret = AutoReplyPrintUniModule.CP_Pos_ResetPrinter(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_SetPrintSpeed_100() {
- var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 100);
- AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_SetPrintSpeed_150() {
- var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintSpeed(hPrinter, 150);
- AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_SetPrintDensity_7() {
- var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 7);
- AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Pos_SetPrintDensity_15() {
- var ret = AutoReplyPrintUniModule.CP_Pos_SetPrintDensity(hPrinter, 15);
- AutoReplyPrintUniModule.CP_Pos_PrintSelfTestPage(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_EnableLabelMode() {
- var ret = AutoReplyPrintUniModule.CP_Label_EnableLabelMode(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DisableLabelMode() {
- var ret = AutoReplyPrintUniModule.CP_Label_DisableLabelMode(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_CalibrateLabel() {
- var ret = AutoReplyPrintUniModule.CP_Label_CalibrateLabel(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_FeedLabel() {
- var ret = AutoReplyPrintUniModule.CP_Label_FeedLabel(hPrinter);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_PageBegin() {
- var ret = AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_PagePrint() {
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawText() {
- var str = "$$$123哈哈哈";
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawText(hPrinter, 10, 10, 24, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawTextInUTF8() {
- var str = "$$$123哈哈哈";
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 1);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInUTF8(hPrinter, 10, 10, 24, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawTextInGBK() {
- var str = "$$$123哈哈哈";
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteMode(hPrinter);
- AutoReplyPrintUniModule.CP_Pos_SetMultiByteEncoding(hPrinter, 0);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawTextInGBK(hPrinter, 10, 10, 24, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawBarcode() {
- var str = "01234567890";
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawBarcode(hPrinter, 10, 10, 0, 2, 60, 2, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawQRCode() {
- var str = "Hello 你好";
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawQRCode(hPrinter, 10, 10, 0, 1, 8, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawPDF417Code() {
- var str = "Hello 你好";
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawPDF417Code(hPrinter, 10, 10, 3, 3, 0, 3, 0, str);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawImageFromFile() {
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], //从相册选择
- success: function(res) {
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromFile(hPrinter, 0, 0, 384, 0,
- res.tempFilePaths[0], 2, 0);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- }
- });
- },
- CP_Label_DrawImageFromPixels() {
- var image_width = 100;
- var image_height = 100;
- var image_pixels_array = new Uint8Array(image_width * image_height * 4);
- for (let y = 0; y < image_height; ++y) {
- for (let x = 0; x < image_width; ++x) {
- var offset = y * image_width * 4 + x * 4;
- if (x == y) {
- image_pixels_array[offset] = 0x00;
- image_pixels_array[offset + 1] = 0x00;
- image_pixels_array[offset + 2] = 0x00;
- image_pixels_array[offset + 3] = 0xff;
- } else {
- image_pixels_array[offset] = 0xff;
- image_pixels_array[offset + 1] = 0xff;
- image_pixels_array[offset + 2] = 0xff;
- image_pixels_array[offset + 3] = 0xff;
- }
- }
- }
- var image_pixels_base64 = uni.arrayBufferToBase64(image_pixels_array);
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawImageFromPixels(hPrinter, 0, 0, image_pixels_base64,
- image_width, image_height, image_width * 4, 7, 2, 0);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawLine() {
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawLine(hPrinter, 20, 20, 100, 300, 1, 1);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawRect() {
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawRect(hPrinter, 20, 20, 200, 10, 1);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- CP_Label_DrawBox() {
- AutoReplyPrintUniModule.CP_Label_PageBegin(hPrinter, 0, 0, 384, 400, 0);
- AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 0, 0, 383, 399, 1, 1);
- var ret = AutoReplyPrintUniModule.CP_Label_DrawBox(hPrinter, 30, 30, 300, 200, 1, 1);
- AutoReplyPrintUniModule.CP_Label_PagePrint(hPrinter, 1);
- modal.toast({
- message: ret,
- duration: 1.5
- });
- },
- }
- }
- </script>
- <style>
- </style>
|