etiquetas.js 1.0.0-alpha.2 → 1.0.0-alpha.20
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.
- package/README.md +130 -171
- package/dist/etiquetas.es.js +28 -27
- package/dist/etiquetas.umd.js +28 -28
- package/dist/etiquetas.umd.js.map +1 -1
- package/dist/{index-BmMBOPX1.js → index-DC5U961t.js} +46212 -958
- package/dist/index-DC5U961t.js.map +1 -0
- package/dist/{index.es-DzWoeylQ.js → index.es-CuEtNlNC.js} +2 -2
- package/dist/{index.es-DzWoeylQ.js.map → index.es-CuEtNlNC.js.map} +1 -1
- package/dist/templates-BJTs3UZW.js +40 -0
- package/dist/templates-BJTs3UZW.js.map +1 -0
- package/dist/usePrinterStore-C5x-akhy.js +114 -0
- package/dist/usePrinterStore-C5x-akhy.js.map +1 -0
- package/package.json +6 -14
- package/README.git.md +0 -121
- package/dist/index-BmMBOPX1.js.map +0 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { L as LabelsAPI } from "./index-DC5U961t.js";
|
|
22
|
+
function getTemplateById(templateId) {
|
|
23
|
+
return __async(this, null, function* () {
|
|
24
|
+
try {
|
|
25
|
+
const labelData = yield LabelsAPI.getLabel(templateId);
|
|
26
|
+
if (!labelData) {
|
|
27
|
+
throw new Error(`Template/etiqueta não encontrado com ID: ${templateId}`);
|
|
28
|
+
}
|
|
29
|
+
console.log("templateContent:", labelData);
|
|
30
|
+
return JSON.parse(labelData.label_content);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
console.error(`Erro ao buscar template: ${error.message}`);
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
getTemplateById
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=templates-BJTs3UZW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates-BJTs3UZW.js","sources":["../src/templates.js"],"sourcesContent":["/**\r\n * 🏷️ TEMPLATES DO SISTEMA DE ETIQUETAS\r\n * \r\n * Configurações e definições de templates para cada tipo de etiqueta\r\n */\r\n\r\nimport { templateVariables } from './constants.js';\r\n\r\nimport { LabelsAPI } from '../api/api.js';\r\n\r\n// ============================================================================\r\n// TEMPLATES DE PEÇAS\r\n// ============================================================================\r\n\r\n\r\n/**\r\n * Obtém um template pelo seu ID a partir da API de etiquetas\r\n * @param {number|string} templateId - ID do template/etiqueta a buscar\r\n * @returns {Promise<Object>} Template com dados da API\r\n */\r\nexport async function getTemplateById(templateId) {\r\n try {\r\n // Converte para número se for string numérica\r\n\r\n \r\n \r\n // Busca na API pelo ID\r\n const labelData = await LabelsAPI.getLabel(templateId);\r\n \r\n if (!labelData) {\r\n throw new Error(`Template/etiqueta não encontrado com ID: ${templateId}`);\r\n }\r\n \r\n \r\n \r\n \r\n // Retorna em formato de array conforme esperado pela função loadLabelTemplate\r\n console.log('templateContent:', labelData);\r\n return JSON.parse(labelData.label_content);\r\n } catch (error) {\r\n console.error(`Erro ao buscar template: ${error.message}`);\r\n throw error;\r\n }\r\n}\r\n\r\n/**\r\n * Obtém templates por tipo\r\n * @param {string} type - Tipo de etiqueta (parts, woodwork, inputs, scraps, volumes)\r\n * @returns {Array} Lista de templates do tipo especificado\r\n */\r\nexport function getTemplatesByType(type) {\r\n return Object.values(allTemplates).filter(template => template.type === type);\r\n}\r\n\r\n/**\r\n * Lista todos os IDs de templates disponíveis\r\n * @returns {Array} Lista de IDs de templates\r\n */\r\nexport function getTemplateIds() {\r\n return Object.keys(allTemplates);\r\n}\r\n\r\n/**\r\n * Valida se um template possui estrutura válida\r\n * @param {Object} template - Template a ser validado\r\n * @returns {boolean} True se válido, false caso contrário\r\n */\r\nexport function validateTemplate(template) {\r\n if (!template || typeof template !== 'object') return false;\r\n \r\n const requiredFields = ['id', 'name', 'type', 'pageWidth', 'pageHeight', 'elements'];\r\n \r\n for (const field of requiredFields) {\r\n if (!(field in template)) return false;\r\n }\r\n \r\n if (!Array.isArray(template.elements)) return false;\r\n \r\n return true;\r\n}\r\n\r\n/**\r\n * Obtém variáveis utilizadas em um template\r\n * @param {Object} template - Template a ser analisado\r\n * @returns {Array} Lista de variáveis encontradas\r\n */\r\nexport function getTemplateVariables(template) {\r\n if (!validateTemplate(template)) return [];\r\n \r\n const variables = new Set();\r\n const variableRegex = /\\{\\{([^}]+)\\}\\}/g;\r\n \r\n template.elements.forEach(element => {\r\n if (element.content) {\r\n let match;\r\n while ((match = variableRegex.exec(element.content)) !== null) {\r\n variables.add(match[1]);\r\n }\r\n }\r\n });\r\n \r\n return Array.from(variables);\r\n}\r\n\r\n/**\r\n * Substitui variáveis em um template com dados fornecidos\r\n * @param {Object} template - Template base\r\n * @param {Object} data - Dados para substituição\r\n * @returns {Object} Template com variáveis substituídas\r\n */\r\nexport function replaceTemplateVariables(template, data) {\r\n if (!validateTemplate(template)) return template;\r\n \r\n const processedTemplate = JSON.parse(JSON.stringify(template));\r\n \r\n processedTemplate.elements = processedTemplate.elements.map(element => {\r\n if (element.content) {\r\n element.content = element.content.replace(/\\{\\{([^}]+)\\}\\}/g, (match, variable) => {\r\n return data[variable] || match;\r\n });\r\n }\r\n return element;\r\n });\r\n \r\n return processedTemplate;\r\n}\r\n\r\n// ============================================================================\r\n// EXPORTAÇÃO PADRÃO\r\n// ============================================================================\r\n\r\nexport default {\r\n\r\n getTemplateById,\r\n getTemplatesByType,\r\n getTemplateIds,\r\n validateTemplate,\r\n getTemplateVariables,\r\n replaceTemplateVariables\r\n};"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoBO,SAAe,gBAAgB,YAAY;AAAA;AAChD,QAAI;AAMF,YAAM,YAAY,MAAM,UAAU,SAAS,UAAU;AAErD,UAAI,CAAC,WAAW;AACd,cAAM,IAAI,MAAM,4CAA4C,UAAU,EAAE;AAAA,MAC1E;AAMA,cAAQ,IAAI,oBAAoB,SAAS;AACzC,aAAO,KAAK,MAAM,UAAU,aAAa;AAAA,IAC3C,SAAS,OAAO;AACd,cAAQ,MAAM,4BAA4B,MAAM,OAAO,EAAE;AACzD,YAAM;AAAA,IACR;AAAA,EACF;AAAA;"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __spreadValues = (a, b) => {
|
|
7
|
+
for (var prop in b || (b = {}))
|
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
|
10
|
+
if (__getOwnPropSymbols)
|
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
+
if (__propIsEnum.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
}
|
|
15
|
+
return a;
|
|
16
|
+
};
|
|
17
|
+
import { c as create } from "./index-DC5U961t.js";
|
|
18
|
+
const createPrinterSlice = (set, get) => ({
|
|
19
|
+
printerStatus: {
|
|
20
|
+
name: "Aguardando...",
|
|
21
|
+
connected: false,
|
|
22
|
+
status: "disconnected",
|
|
23
|
+
hasDefaultPrinter: false,
|
|
24
|
+
message: "Conectando ao servidor...",
|
|
25
|
+
printer: null
|
|
26
|
+
},
|
|
27
|
+
setPrinterStatus: (status) => set(() => ({ printerStatus: status })),
|
|
28
|
+
updatePrinterStatus: (updates) => set((state) => ({
|
|
29
|
+
printerStatus: __spreadValues(__spreadValues({}, state.printerStatus), updates)
|
|
30
|
+
}))
|
|
31
|
+
});
|
|
32
|
+
const createSSESlice = (set, get) => ({
|
|
33
|
+
sseConnected: false,
|
|
34
|
+
eventSource: null,
|
|
35
|
+
setSseConnected: (connected) => set(() => ({ sseConnected: connected })),
|
|
36
|
+
setEventSource: (eventSource) => set(() => ({ eventSource })),
|
|
37
|
+
connectToSSE: () => {
|
|
38
|
+
const { eventSource, setSseConnected, updatePrinterStatus, setEventSource } = get();
|
|
39
|
+
if (typeof EventSource === "undefined") {
|
|
40
|
+
console.log("EventSource não disponível em ambiente Node.js");
|
|
41
|
+
setSseConnected(false);
|
|
42
|
+
updatePrinterStatus({ connected: false, status: "disconnected" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (eventSource) {
|
|
46
|
+
eventSource.close();
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const newEventSource = new EventSource("http://localhost:9999/printer/status/stream");
|
|
50
|
+
setEventSource(newEventSource);
|
|
51
|
+
newEventSource.onopen = () => {
|
|
52
|
+
console.log("Conexão SSE estabelecida com a impressora");
|
|
53
|
+
setSseConnected(true);
|
|
54
|
+
updatePrinterStatus({ status: "connecting" });
|
|
55
|
+
};
|
|
56
|
+
newEventSource.addEventListener("printer-status", (event) => {
|
|
57
|
+
var _a;
|
|
58
|
+
try {
|
|
59
|
+
const data = JSON.parse(event.data);
|
|
60
|
+
console.log("message =>>>>>>>>>", data);
|
|
61
|
+
let status = "disconnected";
|
|
62
|
+
let name = "Nenhuma impressora";
|
|
63
|
+
if (!data.hasDefaultPrinter) {
|
|
64
|
+
status = "no-printer";
|
|
65
|
+
name = "Sem impressora configurada";
|
|
66
|
+
} else if (data.isConnected && data.printer) {
|
|
67
|
+
status = "connected";
|
|
68
|
+
name = data.printer.name || "Impressora";
|
|
69
|
+
} else {
|
|
70
|
+
status = "disconnected";
|
|
71
|
+
name = ((_a = data.printer) == null ? void 0 : _a.name) || "Impressora";
|
|
72
|
+
}
|
|
73
|
+
updatePrinterStatus({
|
|
74
|
+
name,
|
|
75
|
+
connected: data.isConnected || false,
|
|
76
|
+
status,
|
|
77
|
+
hasDefaultPrinter: data.hasDefaultPrinter || false,
|
|
78
|
+
message: data.message || "",
|
|
79
|
+
printer: data.printer || null
|
|
80
|
+
});
|
|
81
|
+
} catch (error) {
|
|
82
|
+
console.warn("Erro ao processar dados da impressora:", error);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
newEventSource.onerror = (error) => {
|
|
86
|
+
console.error("Erro na conexão SSE:", error);
|
|
87
|
+
setSseConnected(false);
|
|
88
|
+
updatePrinterStatus({ connected: false, status: "disconnected" });
|
|
89
|
+
newEventSource.close();
|
|
90
|
+
setEventSource(null);
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
get().connectToSSE();
|
|
93
|
+
}, 5e3);
|
|
94
|
+
};
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Erro ao conectar SSE:", error);
|
|
97
|
+
setSseConnected(false);
|
|
98
|
+
updatePrinterStatus({ connected: false, status: "disconnected" });
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
disconnectSSE: () => {
|
|
102
|
+
const { eventSource, setSseConnected, setEventSource } = get();
|
|
103
|
+
if (eventSource) {
|
|
104
|
+
eventSource.close();
|
|
105
|
+
setEventSource(null);
|
|
106
|
+
}
|
|
107
|
+
setSseConnected(false);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const usePrinterStore = create((set, get) => __spreadValues(__spreadValues({}, createPrinterSlice(set)), createSSESlice(set, get)));
|
|
111
|
+
export {
|
|
112
|
+
usePrinterStore as default
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=usePrinterStore-C5x-akhy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrinterStore-C5x-akhy.js","sources":["../src/usePrinterStore.js"],"sourcesContent":["import { create } from 'zustand';\r\n\r\nconst createPrinterSlice = (set, get) => ({\r\n printerStatus: {\r\n name: 'Aguardando...',\r\n connected: false,\r\n status: 'disconnected',\r\n hasDefaultPrinter: false,\r\n message: 'Conectando ao servidor...',\r\n printer: null\r\n },\r\n setPrinterStatus: (status) => set(() => ({ printerStatus: status })),\r\n updatePrinterStatus: (updates) => set((state) => ({\r\n printerStatus: { ...state.printerStatus, ...updates }\r\n }))\r\n});\r\n\r\nconst createSSESlice = (set, get) => ({\r\n sseConnected: false,\r\n eventSource: null,\r\n setSseConnected: (connected) => set(() => ({ sseConnected: connected })),\r\n setEventSource: (eventSource) => set(() => ({ eventSource })),\r\n \r\n connectToSSE: () => {\r\n const { eventSource, setSseConnected, updatePrinterStatus, setEventSource } = get();\r\n \r\n // Verificar se estamos em ambiente browser\r\n if (typeof EventSource === 'undefined') {\r\n console.log('EventSource não disponível em ambiente Node.js');\r\n setSseConnected(false);\r\n updatePrinterStatus({ connected: false, status: 'disconnected' });\r\n return;\r\n }\r\n \r\n // Se já existe uma conexão, feche-a primeiro\r\n if (eventSource) {\r\n eventSource.close();\r\n }\r\n \r\n try {\r\n const newEventSource = new EventSource('http://localhost:9999/printer/status/stream');\r\n setEventSource(newEventSource);\r\n \r\n newEventSource.onopen = () => {\r\n console.log('Conexão SSE estabelecida com a impressora');\r\n setSseConnected(true);\r\n updatePrinterStatus({ status: 'connecting' });\r\n };\r\n \r\n newEventSource.addEventListener('printer-status', (event) => {\r\n try {\r\n const data = JSON.parse(event.data);\r\n console.log('message =>>>>>>>>>',data);\r\n let status = 'disconnected';\r\n let name = 'Nenhuma impressora';\r\n \r\n if (!data.hasDefaultPrinter) {\r\n status = 'no-printer';\r\n name = 'Sem impressora configurada';\r\n } else if (data.isConnected && data.printer) {\r\n status = 'connected';\r\n name = data.printer.name || 'Impressora';\r\n } else {\r\n status = 'disconnected';\r\n name = data.printer?.name || 'Impressora';\r\n }\r\n \r\n updatePrinterStatus({\r\n name,\r\n connected: data.isConnected || false,\r\n status,\r\n hasDefaultPrinter: data.hasDefaultPrinter || false,\r\n message: data.message || '',\r\n printer: data.printer || null\r\n });\r\n } catch (error) {\r\n console.warn('Erro ao processar dados da impressora:', error);\r\n }\r\n });\r\n \r\n newEventSource.onerror = (error) => {\r\n console.error('Erro na conexão SSE:', error);\r\n setSseConnected(false);\r\n updatePrinterStatus({ connected: false, status: 'disconnected' });\r\n newEventSource.close();\r\n setEventSource(null);\r\n \r\n // Tentar reconectar após 5 segundos\r\n setTimeout(() => {\r\n get().connectToSSE();\r\n }, 5000);\r\n };\r\n } catch (error) {\r\n console.error('Erro ao conectar SSE:', error);\r\n setSseConnected(false);\r\n updatePrinterStatus({ connected: false, status: 'disconnected' });\r\n }\r\n },\r\n \r\n disconnectSSE: () => {\r\n const { eventSource, setSseConnected, setEventSource } = get();\r\n if (eventSource) {\r\n eventSource.close();\r\n setEventSource(null);\r\n }\r\n setSseConnected(false);\r\n }\r\n});\r\n\r\nconst usePrinterStore = create((set, get) => ({\r\n ...createPrinterSlice(set, get),\r\n ...createSSESlice(set, get)\r\n}));\r\n\r\nexport default usePrinterStore;"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "etiquetas.js",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.20",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/etiquetas.umd.js",
|
|
6
6
|
"module": "dist/etiquetas.es.js",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"axios": "^1.6.0",
|
|
36
|
+
"bwip-js": "^4.7.0",
|
|
36
37
|
"html-to-image": "^1.11.11",
|
|
37
38
|
"html2canvas": "^1.4.1",
|
|
38
39
|
"jsbarcode": "^3.11.5",
|
|
@@ -41,12 +42,13 @@
|
|
|
41
42
|
"lodash": "^4.17.21",
|
|
42
43
|
"pako": "^2.1.0",
|
|
43
44
|
"pdfjs-dist": "^5.4.54",
|
|
45
|
+
"svg2pdf.js": "^2.5.0",
|
|
44
46
|
"zustand": "^4.4.1"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
49
|
"@types/node": "^20.0.0",
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
+
"terser": "^5.24.0",
|
|
51
|
+
"vite": "^5.0.0"
|
|
50
52
|
},
|
|
51
53
|
"peerDependencies": {
|
|
52
54
|
"axios": "^1.6.0"
|
|
@@ -62,15 +64,5 @@
|
|
|
62
64
|
],
|
|
63
65
|
"publishConfig": {
|
|
64
66
|
"access": "public"
|
|
65
|
-
}
|
|
66
|
-
"keywords": [
|
|
67
|
-
"labels",
|
|
68
|
-
"etiquetas",
|
|
69
|
-
"pdf",
|
|
70
|
-
"browser",
|
|
71
|
-
"marcenaria",
|
|
72
|
-
"woodworking",
|
|
73
|
-
"barcode",
|
|
74
|
-
"printing"
|
|
75
|
-
]
|
|
67
|
+
}
|
|
76
68
|
}
|
package/README.git.md
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
# 🏷️ Sistema de Etiquetas - Etiquetas.js
|
|
2
|
-
|
|
3
|
-
Sistema completo para geração de etiquetas de peças, tamponamentos, insumos, retalhos e volumes com suporte a impressão e download de PDFs.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
## 🚀 Instalação
|
|
8
|
-
|
|
9
|
-
```bash
|
|
10
|
-
npm install etiquetas-js
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## ⚙️ Configuração Inicial
|
|
14
|
-
|
|
15
|
-
```javascript
|
|
16
|
-
import etiquetas from 'etiquetas-js';
|
|
17
|
-
|
|
18
|
-
// Inicializar o sistema
|
|
19
|
-
etiquetas.init({
|
|
20
|
-
token: '<jwt-token>'
|
|
21
|
-
});
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
## 📚 API Principal
|
|
25
|
-
<jwt-token> é utilizado como authorization na api dinabox para obter os templates de etiqueta
|
|
26
|
-
### Inicialização e Configuração
|
|
27
|
-
|
|
28
|
-
```javascript
|
|
29
|
-
// Inicializar sistema
|
|
30
|
-
etiquetas.init(config);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// Verificar status da impressora
|
|
34
|
-
const status = await etiquetas.getPrinterStatus();
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Geração de Etiquetas
|
|
38
|
-
|
|
39
|
-
const labelData = [{variableProps: {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
```javascript
|
|
43
|
-
// Gerar etiqueta de peça
|
|
44
|
-
<all-variables>
|
|
45
|
-
}, specialProps: {
|
|
46
|
-
<all-specialprops>
|
|
47
|
-
}}]
|
|
48
|
-
O tamanho do array de labelData é a quantidade de etiquetas que serão geradas. Os dados <all-variables> e <all-specialprops>
|
|
49
|
-
|
|
50
|
-
const pdfPeca = await etiquetas.makeLabel({variableProps: {
|
|
51
|
-
PROJETO_ID:123
|
|
52
|
-
|
|
53
|
-
},specialProps: {
|
|
54
|
-
lamination: {
|
|
55
|
-
|
|
56
|
-
material_id:"123",
|
|
57
|
-
edges: {
|
|
58
|
-
left_id:"123",
|
|
59
|
-
right_id:null,
|
|
60
|
-
bottom_id:"123",
|
|
61
|
-
top_id:"245"
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
}}, <label-id>);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Saída e Impressão
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
```javascript
|
|
75
|
-
// Download de PDF
|
|
76
|
-
await etiquetas.downloadPDF(pdfBuffer, 'etiqueta.pdf');
|
|
77
|
-
|
|
78
|
-
// Enviar para impressora
|
|
79
|
-
await etiquetas.sendToPrinter(pdfBuffer);
|
|
80
|
-
|
|
81
|
-
// Envio inteligente (imprime se conectado, senão faz download)
|
|
82
|
-
await etiquetas.sendLabel(labelData, <label-id>);
|
|
83
|
-
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## 🎨 Templates
|
|
87
|
-
|
|
88
|
-
### Templates Disponíveis
|
|
89
|
-
Utilizando a API das labels busque o ID do template
|
|
90
|
-
|
|
91
|
-
Cada arquivo contém a definição de variáveis e propriedades especiais que podem ser usadas na geração das etiquetas correspondentes.
|
|
92
|
-
|
|
93
|
-
## 📑 Variáveis e SpecialProps dos Templates
|
|
94
|
-
|
|
95
|
-
Abaixo estão listadas todas as variáveis (`variableProps`) e propriedades especiais (`specialProps`) disponíveis para uso em qualquer template de etiqueta. Use-as conforme o tipo de etiqueta desejado.
|
|
96
|
-
|
|
97
|
-
### Lista universal de variableProps
|
|
98
|
-
|
|
99
|
-
- {{PROJETO_NOME}}, {{PROJETO_ID}}, {{LOTE_ID}}, {{CLIENTE_NOME}}, {{MODULO_NOME}}, {{MODULO_QTD}}, {{MODULO_REF}}, {{MODULO_OBS}}, {{PECA_ID}}, {{PECA_CODIGO}}, {{PECA_REF}}, {{PECA_INDICE}}, {{PECA_INDICE2}}, {{PECA_NOME}}, {{PECA_OBS}}, {{LARGURA}}, {{ALTURA}}, {{ESPESSURA}}, {{MN}}, {{MA}}, {{ML}}, {{FURO_A}}, {{FURO_A2}}, {{FURO_B}}, {{FURO_B2}}, {{FE}}, {{FD}}, {{FS}}, {{FI}}, {{PECA_TIPO}}, {{MATERIAL_NOME}}, {{TAMPONAMENTO_ID}}, {{TAMPONAMENTO_REF}}, {{TAMPONAMENTO_QT}}, {{TAMPONAMENTO_PESO}}, {{TAMPONAMENTO_NOME}}, {{INSUMO_NOME}}, {{INSUMO_ID}}, {{INSUMO_DIMENSOES}}, {{INSUMO_QTD}}, {{INSUMO_PESO}}, {{INSUMO_REF}}, {{INSUMO_MARCA}}, {{INSUMO_CATEGORIA}}, {{INSUMO_FABRICANTE}}, {{RETALHO_ID}}, {{DATA_CRIACAO}}, {{RETALHO_INDICE}}, {{LADO_USINAGEM}}, {{RETALHO_NOME}}, {{RETALHO_QT}}, {{RETALHO_PESO}}, {{RETALHO_DIMENSOES}}, {{RETALHO_MATERIAL}}, {{RETALHO_ORIGEM}}, {{CODIGO_A}}, {{CODIGO_B}}, {{FURO_A_SD}}, {{FURO_B_SD}}, {{FURO_TOPO}}, {{VOLUME_ID}}, {{VOLUME_NOME}}, {{VOLUME_PESO}}, {{VOLUME_DATA}}, {{VOLUME_DESCRICAO}}, {{VOLUME_PECAS}}, {{VOLUME_DIMENSOES}}
|
|
100
|
-
|
|
101
|
-
> **Observação:** Você pode usar qualquer combinação dessas variáveis em qualquer template, desde que o template utilize o campo correspondente.
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
### Lista universal de specialProps
|
|
106
|
-
|
|
107
|
-
- **rect**: Retângulo. Dados necessários: já vem no template.
|
|
108
|
-
- **lamination**: Desenha bordas de laminação conforme materiais. Dados necessários: informações de borda e material (edge_left_id, material_id, etc).
|
|
109
|
-
- **enhancedLamination**: Laminação detalhada, com indicação visual de materiais e furos. Dados necessários: dados de peça, bordas e furos (holes_diagram, width, height, etc).
|
|
110
|
-
- **identifierByProject**: Gera um identificador visual (preto e branco) para o projeto. Dados necessários: project_id, numberByProject.
|
|
111
|
-
- **colorfulIdentifierByProject**: Igual ao anterior, mas colorido. Dados necessários: project_id, numberByProject, color.
|
|
112
|
-
- **barCode**: Gera um código de barras. Dados necessários: código a ser convertido (originBarcode, customBarcode, code_a, code_b, etc).
|
|
113
|
-
- **miniSheet**: Miniatura da chapa. Dados necessários: lista de partes (parts), dimensões da chapa (height, width).
|
|
114
|
-
- **miniPartA**: Miniatura da peça (lado A). Dados necessários: dados da peça (width, height, index).
|
|
115
|
-
- **miniPartB**: Miniatura da peça (lado B). Dados necessários: dados da peça (width, height, index).
|
|
116
|
-
- **Image**: Imagem. Dados necessários: já vem no template.
|
|
117
|
-
- **text**: Texto estático. Dados necessários: já vem no template.
|
|
118
|
-
- **volumeContent**: Gera uma tabela de itens do volume. Dados necessários: itemList (array de itens do volume).
|
|
119
|
-
|
|
120
|
-
> **Observação:** Você pode usar qualquer combinação dessas specialProps em qualquer template, desde que o template utilize o campo correspondente.
|
|
121
|
-
|