UNPKG

@abrazasoft/thermal_printer_vuejs

Version:

print on thermal printer from vuejs

82 lines (70 loc) 2.32 kB
class Operacion { constructor(accion, datos) { this.accion = accion + ""; this.datos = datos + ""; } } class printer_plugin { static obtenerImpresoras() { //if (ruta) connetor_plugin.URL_PLUGIN_POR_DEFECTO = ruta; return fetch("http://localhost:4567" + "/getprinters") .then(r => r.json()); } constructor() { this.operaciones = []; return this; } text(text) { this.operaciones.push(new Operacion("text", text)); return this; } qr(text) { this.operaciones.push(new Operacion("qr", text)); return this; } fontsize(text) { this.operaciones.push(new Operacion("fontsize", text)); return this; } feed(text) { this.operaciones.push(new Operacion("feed", text)); return this; } textaling(text) { this.operaciones.push(new Operacion("textaling", text)); return this; } barcode_ean13(text) { this.operaciones.push(new Operacion("barcode_ean13", text)); return this; } barcode_39(text) { this.operaciones.push(new Operacion("barcode_39", text)); return this; } barcode_128(text) { this.operaciones.push(new Operacion("barcode_128", text)); return this; } img_url(text) { this.operaciones.push(new Operacion("img_url", text)); return this; } cut(text) { this.operaciones.push(new Operacion("cut", text)); return this; } async imprimir(nombreImpresora, api_key) { const payload = { operaciones: this.operaciones, nombre_impresora: nombreImpresora, api_key: api_key }; const respuestaRaw = await fetch('http://localhost:4567' + "/imprimir", { method: "POST", body: JSON.stringify(payload), }); return await respuestaRaw.json(); } } module.exports = printer_plugin;