You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

8 months ago
  1. export function generateZPL(elements,zplHOrP) {
  2. const zpl = ['^XA'];
  3. //zpl.push('^POI');
  4. zpl.push(zplHOrP)
  5. elements.forEach(el => {
  6. const x = Math.round(el.y * 1.3);
  7. const y = Math.round((750-el.x) * 1.5); // 你之前的转换比例保持不变
  8. switch (el.type) {
  9. case 'text':
  10. zpl.push(`^CI28^LH0,^JUS^CWJ,E:SIMSUN.FNT^CFJ,${el.fontSize},${el.fontSize}`);
  11. zpl.push(el.newline
  12. ? `^FO${x},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  13. : `^FO${x},${y}^FD${el.data}^FS`);
  14. if (el.bold) {
  15. zpl.push(el.newline
  16. ? `^FO${x+1},${y}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  17. : `^FO${x+1},${y}^FD${el.data}^FS`);
  18. zpl.push(el.newline
  19. ? `^FO${x},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  20. : `^FO${x},${y+1}^FD${el.data}^FS`);
  21. zpl.push(el.newline
  22. ? `^FO${x+1},${y+1}^FB${el.lineWidth},${el.lineRows},0^CFJ,${el.fontSize}^FD${el.data}^FS`
  23. : `^FO${x+1},${y+1}^FD${el.data}^FS`);
  24. }
  25. break;
  26. case 'barcode':
  27. zpl.push(`^FO${x},${y}^BY${el.width}^BCB,${el.height},Y,N,N^FD${el.data}^FS`);
  28. break;
  29. case 'qrcode':
  30. zpl.push(`^FO${x},${y}^BQB,2,${el.height},^FDLA,${el.data}^FS`);
  31. break;
  32. case 'onecode':
  33. zpl.push(`^FO${x},${y}^BY${el.width}^BCB,${el.height},^FD${el.data}^FS`);
  34. break;
  35. case 'pic':
  36. if (el.data) {
  37. zpl.push(`^FO${x},${y}^GFA,${el.data}`);
  38. }
  39. break;
  40. case 'hLine':
  41. const y1 = Math.round(1200-el.x)-el.width;
  42. zpl.push(`^FO${x},${y1}^FWR^GB${el.height},${el.width},3,B^FS`);
  43. break;
  44. case 'vLine':
  45. zpl.push(`^FO${x},${y}^FWR^GB${el.height},${el.width},3,B^FS`);
  46. break;
  47. }
  48. });
  49. zpl.push('^XZ');
  50. return zpl.join('\n');
  51. }