code128.js 725 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function getCode128(val) {
  2. // 开始位为固定格式 str.charCodeAt()
  3. let code128A = [0x7B, 0x41]
  4. let code128B = [0x7B, 0x42]
  5. let code128C = [0x7B, 0x43]
  6. let ret = [];
  7. let n67 = 0;
  8. for (let i = 0; i < val.length; i += 2) {
  9. let tmp = val.substr(i, 2);
  10. if (tmp == '00') {
  11. if(i==0){
  12. ret.push(123);
  13. ret.push(66);
  14. n67 = 66;
  15. }else if(n67==67){
  16. ret.push(123);
  17. ret.push(66);
  18. n67 = 66;
  19. }
  20. ret.push(48);
  21. ret.push(48);
  22. } else {
  23. if(i==0){
  24. ret.push(123);
  25. ret.push(67);
  26. n67 = 67;
  27. }else if(n67==66){
  28. ret.push(123);
  29. ret.push(67);
  30. n67 = 67;
  31. }
  32. ret.push(parseInt(tmp));
  33. }
  34. }
  35. ret.unshift(ret.length)
  36. return ret;
  37. }
  38. module.exports = getCode128;