Refactor multiple JavaScript classes to use ES6 syntax, including Download, Pdf, Printer, PrinterPos, PoleDisplay, and Simulator. Update method names for consistency and improve error handling. Modify AJAX requests to enhance functionality and user experience.
This commit is contained in:
@@ -30,10 +30,10 @@ class PoleDisplay {
|
||||
qz.serial.openPort(this.port, this.options)
|
||||
.then(() => {
|
||||
this.pole = this.port;
|
||||
this.cd_Error(`${this.port} opened`);
|
||||
this._conerr(`${this.port} opened`);
|
||||
return qz.serial.sendData(this.pole, { type: 'HEX', data: 'x1Bx40' }, this.options);
|
||||
})
|
||||
.catch(this.cd_Error);
|
||||
.catch(this._conerr);
|
||||
}
|
||||
|
||||
Close() {
|
||||
@@ -42,9 +42,9 @@ class PoleDisplay {
|
||||
qz.serial.closePort(this.port)
|
||||
.then(() => {
|
||||
this.pole = '';
|
||||
this.cd_Error(`${this.port} closed`);
|
||||
this._conerr(`${this.port} closed`);
|
||||
})
|
||||
.catch(this.cd_Error);
|
||||
.catch(this._conerr);
|
||||
}
|
||||
|
||||
Send(txt) {
|
||||
@@ -57,15 +57,15 @@ class PoleDisplay {
|
||||
|
||||
let textToSend = txt;
|
||||
if (Array.isArray(txt)) {
|
||||
textToSend = txt.map(ele => this.cd_Text(ele.t, ele.a)).join('');
|
||||
textToSend = txt.map(ele => this._aligntext(ele.t, ele.a)).join('');
|
||||
}
|
||||
|
||||
const hexData = `x10C${asciiToHex(textToSend)}`;
|
||||
qz.serial.sendData(this.pole, { type: 'HEX', data: hexData }, this.options)
|
||||
.catch(this.cd_Error);
|
||||
.catch(this._conerr);
|
||||
}
|
||||
|
||||
cd_Text(text, align = 'L') {
|
||||
_aligntext(text, align = 'L') {
|
||||
const totWidth = 20;
|
||||
if (text.length >= totWidth) return text.substring(0, totWidth);
|
||||
|
||||
@@ -83,7 +83,7 @@ class PoleDisplay {
|
||||
return ' '.repeat(lPadding) + text + ' '.repeat(rPadding);
|
||||
}
|
||||
|
||||
cd_Error(err) {
|
||||
_conerr(err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user