• qrcode length overflow (1632>1056)--qrcode.js使用过程中二维码长度溢出解决办法


      近日在开发过程中需要为页面动态生成一个二维码信息,由于这个二维码中包含了很多文字,字母以及符号,测试过程中发现有些二维码会报错,因为二维码内容太多了,没办法显示。后来在GitHub中找到了解决办法。

    这是源码中修改前的内容:

    make:function(){this.makeImpl(false,this.getBestMaskPattern());}

    QRCode.prototype.makeCode = function (sText) { this._oQRCode = new QRCodeModel(_getTypeNumber(sText, this._htOption.correctLevel), this._htOption.correctLevel); this._oQRCode.addData(sText); this._oQRCode.make(); this._el.title = sText; this._oDrawing.draw(this._oQRCode); this.makeImage(); };

    这是修改后的内容:

    make:function(){
    if(this.typeNumber<1){
    var typeNumber = 1;
    for (typeNumber = 1;typeNumber<40;typeNumber++){
    var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel);
    var buffer = new QRBitBuffer();var totalDataCount = 0;
    for(var i=0;i<rsBlocks.length;i++) {
      totalDataCount+=rsBlocks[i].dataCount;
    }
    for (var i = 0; i < this.dataList.length; i++) {
      var data = this.dataList[i];
      buffer.put(data.mode, 4);
      buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber));
      data.write(buffer);}
    if (buffer.getLengthInBits() <= totalDataCount * 8)break;}
      this.typeNumber = typeNumber;
    }



    QRCode.prototype.makeCode = function (sText) {
    this._oQRCode = new QRCodeModel(-1, this._htOption.correctLevel);
    this._oQRCode.addData(sText);
    this._oQRCode.make();
    this._el.title = sText;
    this._oDrawing.draw(this._oQRCode);
    this.makeImage();
    };
  • 相关阅读:
    Jquery 跨域请求JSON数据问题
    js定时器实现图片轮播
    Redis数据一致性
    Redis缓存击穿、缓存穿透、缓存雪崩
    数据库连接池druid连接mysql数据库‘链路断开’问题
    Mysql启动错误: Can’t create test file xxx lower-test
    DB2-表空间
    DB2-Schema
    DB2-数据库
    DB2-实例
  • 原文地址:https://www.cnblogs.com/Miracle-ZLZ/p/7723857.html
Copyright © 2020-2023  润新知