@pisell/utils 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -66,35 +66,47 @@ EscPosPrinter.prototype.clear = function () {
|
|
|
66
66
|
|
|
67
67
|
// Print the order data.
|
|
68
68
|
EscPosPrinter.prototype.print = function (host, sn, copies) {
|
|
69
|
+
var that = this;
|
|
69
70
|
return new Promise(function (resolve, reject) {
|
|
70
71
|
var xmlobj = new XMLHttpRequest();
|
|
71
|
-
|
|
72
|
+
xmlobj.timeout = 10000;
|
|
73
|
+
var url = "https://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
|
|
72
74
|
xmlobj.open("POST", url, true);
|
|
73
75
|
xmlobj.onreadystatechange = function () {
|
|
74
76
|
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
78
|
+
var re = /task_id: (\d+)/;
|
|
79
|
+
var matches = re.exec(xmlobj.responseText);
|
|
80
|
+
resolve(matches[1] || "");
|
|
81
|
+
} else {
|
|
82
|
+
reject(xmlobj.responseText);
|
|
83
|
+
}
|
|
79
84
|
}
|
|
80
85
|
};
|
|
81
86
|
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
82
|
-
xmlobj.send(
|
|
87
|
+
xmlobj.send(that.orderData);
|
|
83
88
|
});
|
|
84
89
|
};
|
|
85
90
|
|
|
86
91
|
// Query print status.
|
|
87
92
|
EscPosPrinter.prototype.queryStatus = function (host, sn, task_id) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
return new Promise(function (resolve, reject) {
|
|
94
|
+
var xmlobj = new XMLHttpRequest();
|
|
95
|
+
xmlobj.timeout = 10000;
|
|
96
|
+
var url = "https://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
|
|
97
|
+
xmlobj.open("POST", url, true);
|
|
98
|
+
xmlobj.onreadystatechange = function () {
|
|
99
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
100
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
101
|
+
resolve(xmlobj.responseText);
|
|
102
|
+
} else {
|
|
103
|
+
reject(xmlobj.responseText);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
108
|
+
xmlobj.send();
|
|
109
|
+
});
|
|
98
110
|
};
|
|
99
111
|
|
|
100
112
|
//////////////////////////////////////////////////
|
|
@@ -88,37 +88,45 @@ EscPosPrinter.prototype.clear = function() {
|
|
|
88
88
|
this.orderData = "";
|
|
89
89
|
};
|
|
90
90
|
EscPosPrinter.prototype.print = function(host, sn, copies) {
|
|
91
|
+
var that = this;
|
|
91
92
|
return new Promise(function(resolve, reject) {
|
|
92
93
|
var xmlobj = new XMLHttpRequest();
|
|
93
|
-
|
|
94
|
+
xmlobj.timeout = 1e4;
|
|
95
|
+
var url = "https://" + host + "/cgi-bin/print.cgi?sn=" + sn + "&copies=" + copies;
|
|
94
96
|
xmlobj.open("POST", url, true);
|
|
95
97
|
xmlobj.onreadystatechange = function() {
|
|
96
98
|
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
100
|
+
var re = /task_id: (\d+)/;
|
|
101
|
+
var matches = re.exec(xmlobj.responseText);
|
|
102
|
+
resolve(matches[1] || "");
|
|
103
|
+
} else {
|
|
104
|
+
reject(xmlobj.responseText);
|
|
105
|
+
}
|
|
103
106
|
}
|
|
104
107
|
};
|
|
105
108
|
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
106
|
-
xmlobj.send(
|
|
109
|
+
xmlobj.send(that.orderData);
|
|
107
110
|
});
|
|
108
111
|
};
|
|
109
112
|
EscPosPrinter.prototype.queryStatus = function(host, sn, task_id) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
113
|
+
return new Promise(function(resolve, reject) {
|
|
114
|
+
var xmlobj = new XMLHttpRequest();
|
|
115
|
+
xmlobj.timeout = 1e4;
|
|
116
|
+
var url = "https://" + host + "/cgi-bin/status.cgi?sn=" + sn + "&task_id=" + task_id;
|
|
117
|
+
xmlobj.open("POST", url, true);
|
|
118
|
+
xmlobj.onreadystatechange = function() {
|
|
119
|
+
if (xmlobj.readyState === XMLHttpRequest.DONE) {
|
|
120
|
+
if (xmlobj.status.toString(10) === "200") {
|
|
121
|
+
resolve(xmlobj.responseText);
|
|
122
|
+
} else {
|
|
123
|
+
reject(xmlobj.responseText);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
xmlobj.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
|
|
128
|
+
xmlobj.send();
|
|
129
|
+
});
|
|
122
130
|
};
|
|
123
131
|
EscPosPrinter.prototype.appendText = function(str) {
|
|
124
132
|
for (var i = 0; i < str.length; i++)
|