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


    以下代码有问题,亲测会报error, 看了下make 函数的括号都没有对上。

    正确做法,到以下官网上去下载一个最新版的文件就可以了。

     https://github.com/KeeeX/qrcodejs

    ============================================================================

    近日在开发过程中需要为页面动态生成一个二维码信息,由于这个二维码中包含了很多文字,字母以及符号,测试过程中发现有些二维码会报错,因为二维码内容太多了,没办法显示。后来在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();
    };

    出自: https://www.cnblogs.com/Miracle-ZLZ/p/7723857.html

  • 相关阅读:
    Yii2的View中JS代码添加
    Yii2命名规则
    Yii2 Redis的使用
    win7下php5.6安装redis扩展
    Ubuntu安装cuda
    Ubuntu 安装显卡驱动
    TensorFlow 图片resize方法
    anaconda的kernel对jupyter可见
    cuda和显卡驱动版本
    jupyter修改根目录
  • 原文地址:https://www.cnblogs.com/wonder223/p/15792827.html
Copyright © 2020-2023  润新知