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.
43 lines
726 B
43 lines
726 B
|
1 week ago
|
|
||
|
|
function getCode128(val) {
|
||
|
|
// 开始位为固定格式 str.charCodeAt()
|
||
|
|
let code128A = [0x7B, 0x41]
|
||
|
|
let code128B = [0x7B, 0x42]
|
||
|
|
let code128C = [0x7B, 0x43]
|
||
|
|
let ret = [];
|
||
|
|
let n67 = 0;
|
||
|
|
for (let i = 0; i < val.length; i += 2) {
|
||
|
|
let tmp = val.substr(i, 2);
|
||
|
|
if (tmp == '00') {
|
||
|
|
if(i==0){
|
||
|
|
ret.push(123);
|
||
|
|
ret.push(66);
|
||
|
|
n67 = 66;
|
||
|
|
}else if(n67==67){
|
||
|
|
ret.push(123);
|
||
|
|
ret.push(66);
|
||
|
|
n67 = 66;
|
||
|
|
}
|
||
|
|
|
||
|
|
ret.push(48);
|
||
|
|
ret.push(48);
|
||
|
|
} else {
|
||
|
|
if(i==0){
|
||
|
|
ret.push(123);
|
||
|
|
ret.push(67);
|
||
|
|
n67 = 67;
|
||
|
|
}else if(n67==66){
|
||
|
|
ret.push(123);
|
||
|
|
ret.push(67);
|
||
|
|
n67 = 67;
|
||
|
|
}
|
||
|
|
ret.push(parseInt(tmp));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
ret.unshift(ret.length)
|
||
|
|
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = getCode128;
|