alsey / wxbarcode

微信小程序条码、二维码生成模块

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

最后一位是下划线

chenbin2015 opened this issue · comments

扫作者贴出的条形码,最后一位是下划线,另外自己生成的条形码,最后一位也是下划线 @alsey

commented

原因是code128C是纯数字条码,但是必须是偶数位。当出现奇数位是,需要在最后一位前用code128B进行转码声明,也就是作者在最后一位前插入了shifter(shifter=100),这样shifter后面的那一位应该是code128B对应的1,也就是19,但是上文中却错误的插入了chr2也就是-1对应的codeValue:62,也就是code128B中62对应的码字_,导致出现奇数位最后一位的错误。
[code=javascript]//ok some type of shift is nessecary if (shifter != -1) { result.push(shifter); result.push(codeValue(chr1));//把这里的chr2改成chr1即可。 }[/code]

楼上改法有用吗?我试了下没用。我这么改的。
function perhapsCodeC(bytes, codeset) { for (var i = 0; i < bytes.length; i++) { var b = bytes[i] if ((b < 48 || b > 57) && b != CHAR_TILDE) return codeset; } if (bytes.length % 2 == 0) return CODESET.C; else return CODESET.A; }

@qihb 有效 谢谢了

commented

@qihb 解决了 多谢

作者应该维护一下这个BUG。二楼的方法能解决问题

为何不开个分支 维护下呢?

不管用啊

不管用啊

wxbarcode+1.0.2.patch

diff --git a/node_modules/wxbarcode/demo/utils/barcode.js b/node_modules/wxbarcode/demo/utils/barcode.js
index 0838c8e..1a7cb90 100644
--- a/node_modules/wxbarcode/demo/utils/barcode.js
+++ b/node_modules/wxbarcode/demo/utils/barcode.js
@@ -197,7 +197,7 @@ function stringToCode128(text) {
         //ok some type of shift is nessecary
         if (shifter != -1) {
             result.push(shifter);
-            result.push(codeValue(chr2));
+            result.push(codeValue(chr1));
         }
         else {
             if (currcs == CODESET.C) {