Commit e5b0f026a302133f22a0fec6b9973bfd93083c6f
Merge remote-tracking branch 'origin/branch' into branch
Showing
2 changed files
with
1471 additions
and
10 deletions
common/uqrcode.js
0 → 100644
| 1 | +// uqrcode.js | ||
| 2 | +//--------------------------------------------------------------------- | ||
| 3 | +// github https://github.com/Sansnn/uQRCode | ||
| 4 | +//--------------------------------------------------------------------- | ||
| 5 | + | ||
| 6 | +let uQRCode = {}; | ||
| 7 | + | ||
| 8 | +(function() { | ||
| 9 | + //--------------------------------------------------------------------- | ||
| 10 | + // QRCode for JavaScript | ||
| 11 | + // | ||
| 12 | + // Copyright (c) 2009 Kazuhiko Arase | ||
| 13 | + // | ||
| 14 | + // URL: http://www.d-project.com/ | ||
| 15 | + // | ||
| 16 | + // Licensed under the MIT license: | ||
| 17 | + // http://www.opensource.org/licenses/mit-license.php | ||
| 18 | + // | ||
| 19 | + // The word "QR Code" is registered trademark of | ||
| 20 | + // DENSO WAVE INCORPORATED | ||
| 21 | + // http://www.denso-wave.com/qrcode/faqpatent-e.html | ||
| 22 | + // | ||
| 23 | + //--------------------------------------------------------------------- | ||
| 24 | + | ||
| 25 | + //--------------------------------------------------------------------- | ||
| 26 | + // QR8bitByte | ||
| 27 | + //--------------------------------------------------------------------- | ||
| 28 | + | ||
| 29 | + function QR8bitByte(data) { | ||
| 30 | + this.mode = QRMode.MODE_8BIT_BYTE; | ||
| 31 | + this.data = data; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + QR8bitByte.prototype = { | ||
| 35 | + | ||
| 36 | + getLength: function(buffer) { | ||
| 37 | + return this.data.length; | ||
| 38 | + }, | ||
| 39 | + | ||
| 40 | + write: function(buffer) { | ||
| 41 | + for (var i = 0; i < this.data.length; i++) { | ||
| 42 | + // not JIS ... | ||
| 43 | + buffer.put(this.data.charCodeAt(i), 8); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + }; | ||
| 47 | + | ||
| 48 | + //--------------------------------------------------------------------- | ||
| 49 | + // QRCode | ||
| 50 | + //--------------------------------------------------------------------- | ||
| 51 | + | ||
| 52 | + function QRCode(typeNumber, errorCorrectLevel) { | ||
| 53 | + this.typeNumber = typeNumber; | ||
| 54 | + this.errorCorrectLevel = errorCorrectLevel; | ||
| 55 | + this.modules = null; | ||
| 56 | + this.moduleCount = 0; | ||
| 57 | + this.dataCache = null; | ||
| 58 | + this.dataList = new Array(); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + QRCode.prototype = { | ||
| 62 | + | ||
| 63 | + addData: function(data) { | ||
| 64 | + var newData = new QR8bitByte(data); | ||
| 65 | + this.dataList.push(newData); | ||
| 66 | + this.dataCache = null; | ||
| 67 | + }, | ||
| 68 | + | ||
| 69 | + isDark: function(row, col) { | ||
| 70 | + if (row < 0 || this.moduleCount <= row || col < 0 || this.moduleCount <= col) { | ||
| 71 | + throw new Error(row + "," + col); | ||
| 72 | + } | ||
| 73 | + return this.modules[row][col]; | ||
| 74 | + }, | ||
| 75 | + | ||
| 76 | + getModuleCount: function() { | ||
| 77 | + return this.moduleCount; | ||
| 78 | + }, | ||
| 79 | + | ||
| 80 | + make: function() { | ||
| 81 | + // Calculate automatically typeNumber if provided is < 1 | ||
| 82 | + if (this.typeNumber < 1) { | ||
| 83 | + var typeNumber = 1; | ||
| 84 | + for (typeNumber = 1; typeNumber < 40; typeNumber++) { | ||
| 85 | + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, this.errorCorrectLevel); | ||
| 86 | + | ||
| 87 | + var buffer = new QRBitBuffer(); | ||
| 88 | + var totalDataCount = 0; | ||
| 89 | + for (var i = 0; i < rsBlocks.length; i++) { | ||
| 90 | + totalDataCount += rsBlocks[i].dataCount; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + for (var i = 0; i < this.dataList.length; i++) { | ||
| 94 | + var data = this.dataList[i]; | ||
| 95 | + buffer.put(data.mode, 4); | ||
| 96 | + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); | ||
| 97 | + data.write(buffer); | ||
| 98 | + } | ||
| 99 | + if (buffer.getLengthInBits() <= totalDataCount * 8) | ||
| 100 | + break; | ||
| 101 | + } | ||
| 102 | + this.typeNumber = typeNumber; | ||
| 103 | + } | ||
| 104 | + this.makeImpl(false, this.getBestMaskPattern()); | ||
| 105 | + }, | ||
| 106 | + | ||
| 107 | + makeImpl: function(test, maskPattern) { | ||
| 108 | + | ||
| 109 | + this.moduleCount = this.typeNumber * 4 + 17; | ||
| 110 | + this.modules = new Array(this.moduleCount); | ||
| 111 | + | ||
| 112 | + for (var row = 0; row < this.moduleCount; row++) { | ||
| 113 | + | ||
| 114 | + this.modules[row] = new Array(this.moduleCount); | ||
| 115 | + | ||
| 116 | + for (var col = 0; col < this.moduleCount; col++) { | ||
| 117 | + this.modules[row][col] = null; //(col + row) % 3; | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + this.setupPositionProbePattern(0, 0); | ||
| 122 | + this.setupPositionProbePattern(this.moduleCount - 7, 0); | ||
| 123 | + this.setupPositionProbePattern(0, this.moduleCount - 7); | ||
| 124 | + this.setupPositionAdjustPattern(); | ||
| 125 | + this.setupTimingPattern(); | ||
| 126 | + this.setupTypeInfo(test, maskPattern); | ||
| 127 | + | ||
| 128 | + if (this.typeNumber >= 7) { | ||
| 129 | + this.setupTypeNumber(test); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + if (this.dataCache == null) { | ||
| 133 | + this.dataCache = QRCode.createData(this.typeNumber, this.errorCorrectLevel, this.dataList); | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + this.mapData(this.dataCache, maskPattern); | ||
| 137 | + }, | ||
| 138 | + | ||
| 139 | + setupPositionProbePattern: function(row, col) { | ||
| 140 | + | ||
| 141 | + for (var r = -1; r <= 7; r++) { | ||
| 142 | + | ||
| 143 | + if (row + r <= -1 || this.moduleCount <= row + r) continue; | ||
| 144 | + | ||
| 145 | + for (var c = -1; c <= 7; c++) { | ||
| 146 | + | ||
| 147 | + if (col + c <= -1 || this.moduleCount <= col + c) continue; | ||
| 148 | + | ||
| 149 | + if ((0 <= r && r <= 6 && (c == 0 || c == 6)) || | ||
| 150 | + (0 <= c && c <= 6 && (r == 0 || r == 6)) || | ||
| 151 | + (2 <= r && r <= 4 && 2 <= c && c <= 4)) { | ||
| 152 | + this.modules[row + r][col + c] = true; | ||
| 153 | + } else { | ||
| 154 | + this.modules[row + r][col + c] = false; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + } | ||
| 158 | + }, | ||
| 159 | + | ||
| 160 | + getBestMaskPattern: function() { | ||
| 161 | + | ||
| 162 | + var minLostPoint = 0; | ||
| 163 | + var pattern = 0; | ||
| 164 | + | ||
| 165 | + for (var i = 0; i < 8; i++) { | ||
| 166 | + | ||
| 167 | + this.makeImpl(true, i); | ||
| 168 | + | ||
| 169 | + var lostPoint = QRUtil.getLostPoint(this); | ||
| 170 | + | ||
| 171 | + if (i == 0 || minLostPoint > lostPoint) { | ||
| 172 | + minLostPoint = lostPoint; | ||
| 173 | + pattern = i; | ||
| 174 | + } | ||
| 175 | + } | ||
| 176 | + | ||
| 177 | + return pattern; | ||
| 178 | + }, | ||
| 179 | + | ||
| 180 | + createMovieClip: function(target_mc, instance_name, depth) { | ||
| 181 | + | ||
| 182 | + var qr_mc = target_mc.createEmptyMovieClip(instance_name, depth); | ||
| 183 | + var cs = 1; | ||
| 184 | + | ||
| 185 | + this.make(); | ||
| 186 | + | ||
| 187 | + for (var row = 0; row < this.modules.length; row++) { | ||
| 188 | + | ||
| 189 | + var y = row * cs; | ||
| 190 | + | ||
| 191 | + for (var col = 0; col < this.modules[row].length; col++) { | ||
| 192 | + | ||
| 193 | + var x = col * cs; | ||
| 194 | + var dark = this.modules[row][col]; | ||
| 195 | + | ||
| 196 | + if (dark) { | ||
| 197 | + qr_mc.beginFill(0, 100); | ||
| 198 | + qr_mc.moveTo(x, y); | ||
| 199 | + qr_mc.lineTo(x + cs, y); | ||
| 200 | + qr_mc.lineTo(x + cs, y + cs); | ||
| 201 | + qr_mc.lineTo(x, y + cs); | ||
| 202 | + qr_mc.endFill(); | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + return qr_mc; | ||
| 208 | + }, | ||
| 209 | + | ||
| 210 | + setupTimingPattern: function() { | ||
| 211 | + | ||
| 212 | + for (var r = 8; r < this.moduleCount - 8; r++) { | ||
| 213 | + if (this.modules[r][6] != null) { | ||
| 214 | + continue; | ||
| 215 | + } | ||
| 216 | + this.modules[r][6] = (r % 2 == 0); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + for (var c = 8; c < this.moduleCount - 8; c++) { | ||
| 220 | + if (this.modules[6][c] != null) { | ||
| 221 | + continue; | ||
| 222 | + } | ||
| 223 | + this.modules[6][c] = (c % 2 == 0); | ||
| 224 | + } | ||
| 225 | + }, | ||
| 226 | + | ||
| 227 | + setupPositionAdjustPattern: function() { | ||
| 228 | + | ||
| 229 | + var pos = QRUtil.getPatternPosition(this.typeNumber); | ||
| 230 | + | ||
| 231 | + for (var i = 0; i < pos.length; i++) { | ||
| 232 | + | ||
| 233 | + for (var j = 0; j < pos.length; j++) { | ||
| 234 | + | ||
| 235 | + var row = pos[i]; | ||
| 236 | + var col = pos[j]; | ||
| 237 | + | ||
| 238 | + if (this.modules[row][col] != null) { | ||
| 239 | + continue; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + for (var r = -2; r <= 2; r++) { | ||
| 243 | + | ||
| 244 | + for (var c = -2; c <= 2; c++) { | ||
| 245 | + | ||
| 246 | + if (r == -2 || r == 2 || c == -2 || c == 2 || | ||
| 247 | + (r == 0 && c == 0)) { | ||
| 248 | + this.modules[row + r][col + c] = true; | ||
| 249 | + } else { | ||
| 250 | + this.modules[row + r][col + c] = false; | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + } | ||
| 254 | + } | ||
| 255 | + } | ||
| 256 | + }, | ||
| 257 | + | ||
| 258 | + setupTypeNumber: function(test) { | ||
| 259 | + | ||
| 260 | + var bits = QRUtil.getBCHTypeNumber(this.typeNumber); | ||
| 261 | + | ||
| 262 | + for (var i = 0; i < 18; i++) { | ||
| 263 | + var mod = (!test && ((bits >> i) & 1) == 1); | ||
| 264 | + this.modules[Math.floor(i / 3)][i % 3 + this.moduleCount - 8 - 3] = mod; | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + for (var i = 0; i < 18; i++) { | ||
| 268 | + var mod = (!test && ((bits >> i) & 1) == 1); | ||
| 269 | + this.modules[i % 3 + this.moduleCount - 8 - 3][Math.floor(i / 3)] = mod; | ||
| 270 | + } | ||
| 271 | + }, | ||
| 272 | + | ||
| 273 | + setupTypeInfo: function(test, maskPattern) { | ||
| 274 | + | ||
| 275 | + var data = (this.errorCorrectLevel << 3) | maskPattern; | ||
| 276 | + var bits = QRUtil.getBCHTypeInfo(data); | ||
| 277 | + | ||
| 278 | + // vertical | ||
| 279 | + for (var i = 0; i < 15; i++) { | ||
| 280 | + | ||
| 281 | + var mod = (!test && ((bits >> i) & 1) == 1); | ||
| 282 | + | ||
| 283 | + if (i < 6) { | ||
| 284 | + this.modules[i][8] = mod; | ||
| 285 | + } else if (i < 8) { | ||
| 286 | + this.modules[i + 1][8] = mod; | ||
| 287 | + } else { | ||
| 288 | + this.modules[this.moduleCount - 15 + i][8] = mod; | ||
| 289 | + } | ||
| 290 | + } | ||
| 291 | + | ||
| 292 | + // horizontal | ||
| 293 | + for (var i = 0; i < 15; i++) { | ||
| 294 | + | ||
| 295 | + var mod = (!test && ((bits >> i) & 1) == 1); | ||
| 296 | + | ||
| 297 | + if (i < 8) { | ||
| 298 | + this.modules[8][this.moduleCount - i - 1] = mod; | ||
| 299 | + } else if (i < 9) { | ||
| 300 | + this.modules[8][15 - i - 1 + 1] = mod; | ||
| 301 | + } else { | ||
| 302 | + this.modules[8][15 - i - 1] = mod; | ||
| 303 | + } | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + // fixed module | ||
| 307 | + this.modules[this.moduleCount - 8][8] = (!test); | ||
| 308 | + | ||
| 309 | + }, | ||
| 310 | + | ||
| 311 | + mapData: function(data, maskPattern) { | ||
| 312 | + | ||
| 313 | + var inc = -1; | ||
| 314 | + var row = this.moduleCount - 1; | ||
| 315 | + var bitIndex = 7; | ||
| 316 | + var byteIndex = 0; | ||
| 317 | + | ||
| 318 | + for (var col = this.moduleCount - 1; col > 0; col -= 2) { | ||
| 319 | + | ||
| 320 | + if (col == 6) col--; | ||
| 321 | + | ||
| 322 | + while (true) { | ||
| 323 | + | ||
| 324 | + for (var c = 0; c < 2; c++) { | ||
| 325 | + | ||
| 326 | + if (this.modules[row][col - c] == null) { | ||
| 327 | + | ||
| 328 | + var dark = false; | ||
| 329 | + | ||
| 330 | + if (byteIndex < data.length) { | ||
| 331 | + dark = (((data[byteIndex] >>> bitIndex) & 1) == 1); | ||
| 332 | + } | ||
| 333 | + | ||
| 334 | + var mask = QRUtil.getMask(maskPattern, row, col - c); | ||
| 335 | + | ||
| 336 | + if (mask) { | ||
| 337 | + dark = !dark; | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + this.modules[row][col - c] = dark; | ||
| 341 | + bitIndex--; | ||
| 342 | + | ||
| 343 | + if (bitIndex == -1) { | ||
| 344 | + byteIndex++; | ||
| 345 | + bitIndex = 7; | ||
| 346 | + } | ||
| 347 | + } | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + row += inc; | ||
| 351 | + | ||
| 352 | + if (row < 0 || this.moduleCount <= row) { | ||
| 353 | + row -= inc; | ||
| 354 | + inc = -inc; | ||
| 355 | + break; | ||
| 356 | + } | ||
| 357 | + } | ||
| 358 | + } | ||
| 359 | + | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + }; | ||
| 363 | + | ||
| 364 | + QRCode.PAD0 = 0xEC; | ||
| 365 | + QRCode.PAD1 = 0x11; | ||
| 366 | + | ||
| 367 | + QRCode.createData = function(typeNumber, errorCorrectLevel, dataList) { | ||
| 368 | + | ||
| 369 | + var rsBlocks = QRRSBlock.getRSBlocks(typeNumber, errorCorrectLevel); | ||
| 370 | + | ||
| 371 | + var buffer = new QRBitBuffer(); | ||
| 372 | + | ||
| 373 | + for (var i = 0; i < dataList.length; i++) { | ||
| 374 | + var data = dataList[i]; | ||
| 375 | + buffer.put(data.mode, 4); | ||
| 376 | + buffer.put(data.getLength(), QRUtil.getLengthInBits(data.mode, typeNumber)); | ||
| 377 | + data.write(buffer); | ||
| 378 | + } | ||
| 379 | + | ||
| 380 | + // calc num max data. | ||
| 381 | + var totalDataCount = 0; | ||
| 382 | + for (var i = 0; i < rsBlocks.length; i++) { | ||
| 383 | + totalDataCount += rsBlocks[i].dataCount; | ||
| 384 | + } | ||
| 385 | + | ||
| 386 | + if (buffer.getLengthInBits() > totalDataCount * 8) { | ||
| 387 | + throw new Error("code length overflow. (" + | ||
| 388 | + buffer.getLengthInBits() + | ||
| 389 | + ">" + | ||
| 390 | + totalDataCount * 8 + | ||
| 391 | + ")"); | ||
| 392 | + } | ||
| 393 | + | ||
| 394 | + // end code | ||
| 395 | + if (buffer.getLengthInBits() + 4 <= totalDataCount * 8) { | ||
| 396 | + buffer.put(0, 4); | ||
| 397 | + } | ||
| 398 | + | ||
| 399 | + // padding | ||
| 400 | + while (buffer.getLengthInBits() % 8 != 0) { | ||
| 401 | + buffer.putBit(false); | ||
| 402 | + } | ||
| 403 | + | ||
| 404 | + // padding | ||
| 405 | + while (true) { | ||
| 406 | + | ||
| 407 | + if (buffer.getLengthInBits() >= totalDataCount * 8) { | ||
| 408 | + break; | ||
| 409 | + } | ||
| 410 | + buffer.put(QRCode.PAD0, 8); | ||
| 411 | + | ||
| 412 | + if (buffer.getLengthInBits() >= totalDataCount * 8) { | ||
| 413 | + break; | ||
| 414 | + } | ||
| 415 | + buffer.put(QRCode.PAD1, 8); | ||
| 416 | + } | ||
| 417 | + | ||
| 418 | + return QRCode.createBytes(buffer, rsBlocks); | ||
| 419 | + } | ||
| 420 | + | ||
| 421 | + QRCode.createBytes = function(buffer, rsBlocks) { | ||
| 422 | + | ||
| 423 | + var offset = 0; | ||
| 424 | + | ||
| 425 | + var maxDcCount = 0; | ||
| 426 | + var maxEcCount = 0; | ||
| 427 | + | ||
| 428 | + var dcdata = new Array(rsBlocks.length); | ||
| 429 | + var ecdata = new Array(rsBlocks.length); | ||
| 430 | + | ||
| 431 | + for (var r = 0; r < rsBlocks.length; r++) { | ||
| 432 | + | ||
| 433 | + var dcCount = rsBlocks[r].dataCount; | ||
| 434 | + var ecCount = rsBlocks[r].totalCount - dcCount; | ||
| 435 | + | ||
| 436 | + maxDcCount = Math.max(maxDcCount, dcCount); | ||
| 437 | + maxEcCount = Math.max(maxEcCount, ecCount); | ||
| 438 | + | ||
| 439 | + dcdata[r] = new Array(dcCount); | ||
| 440 | + | ||
| 441 | + for (var i = 0; i < dcdata[r].length; i++) { | ||
| 442 | + dcdata[r][i] = 0xff & buffer.buffer[i + offset]; | ||
| 443 | + } | ||
| 444 | + offset += dcCount; | ||
| 445 | + | ||
| 446 | + var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount); | ||
| 447 | + var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1); | ||
| 448 | + | ||
| 449 | + var modPoly = rawPoly.mod(rsPoly); | ||
| 450 | + ecdata[r] = new Array(rsPoly.getLength() - 1); | ||
| 451 | + for (var i = 0; i < ecdata[r].length; i++) { | ||
| 452 | + var modIndex = i + modPoly.getLength() - ecdata[r].length; | ||
| 453 | + ecdata[r][i] = (modIndex >= 0) ? modPoly.get(modIndex) : 0; | ||
| 454 | + } | ||
| 455 | + | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + var totalCodeCount = 0; | ||
| 459 | + for (var i = 0; i < rsBlocks.length; i++) { | ||
| 460 | + totalCodeCount += rsBlocks[i].totalCount; | ||
| 461 | + } | ||
| 462 | + | ||
| 463 | + var data = new Array(totalCodeCount); | ||
| 464 | + var index = 0; | ||
| 465 | + | ||
| 466 | + for (var i = 0; i < maxDcCount; i++) { | ||
| 467 | + for (var r = 0; r < rsBlocks.length; r++) { | ||
| 468 | + if (i < dcdata[r].length) { | ||
| 469 | + data[index++] = dcdata[r][i]; | ||
| 470 | + } | ||
| 471 | + } | ||
| 472 | + } | ||
| 473 | + | ||
| 474 | + for (var i = 0; i < maxEcCount; i++) { | ||
| 475 | + for (var r = 0; r < rsBlocks.length; r++) { | ||
| 476 | + if (i < ecdata[r].length) { | ||
| 477 | + data[index++] = ecdata[r][i]; | ||
| 478 | + } | ||
| 479 | + } | ||
| 480 | + } | ||
| 481 | + | ||
| 482 | + return data; | ||
| 483 | + | ||
| 484 | + } | ||
| 485 | + | ||
| 486 | + //--------------------------------------------------------------------- | ||
| 487 | + // QRMode | ||
| 488 | + //--------------------------------------------------------------------- | ||
| 489 | + | ||
| 490 | + var QRMode = { | ||
| 491 | + MODE_NUMBER: 1 << 0, | ||
| 492 | + MODE_ALPHA_NUM: 1 << 1, | ||
| 493 | + MODE_8BIT_BYTE: 1 << 2, | ||
| 494 | + MODE_KANJI: 1 << 3 | ||
| 495 | + }; | ||
| 496 | + | ||
| 497 | + //--------------------------------------------------------------------- | ||
| 498 | + // QRErrorCorrectLevel | ||
| 499 | + //--------------------------------------------------------------------- | ||
| 500 | + | ||
| 501 | + var QRErrorCorrectLevel = { | ||
| 502 | + L: 1, | ||
| 503 | + M: 0, | ||
| 504 | + Q: 3, | ||
| 505 | + H: 2 | ||
| 506 | + }; | ||
| 507 | + | ||
| 508 | + //--------------------------------------------------------------------- | ||
| 509 | + // QRMaskPattern | ||
| 510 | + //--------------------------------------------------------------------- | ||
| 511 | + | ||
| 512 | + var QRMaskPattern = { | ||
| 513 | + PATTERN000: 0, | ||
| 514 | + PATTERN001: 1, | ||
| 515 | + PATTERN010: 2, | ||
| 516 | + PATTERN011: 3, | ||
| 517 | + PATTERN100: 4, | ||
| 518 | + PATTERN101: 5, | ||
| 519 | + PATTERN110: 6, | ||
| 520 | + PATTERN111: 7 | ||
| 521 | + }; | ||
| 522 | + | ||
| 523 | + //--------------------------------------------------------------------- | ||
| 524 | + // QRUtil | ||
| 525 | + //--------------------------------------------------------------------- | ||
| 526 | + | ||
| 527 | + var QRUtil = { | ||
| 528 | + | ||
| 529 | + PATTERN_POSITION_TABLE: [ | ||
| 530 | + [], | ||
| 531 | + [6, 18], | ||
| 532 | + [6, 22], | ||
| 533 | + [6, 26], | ||
| 534 | + [6, 30], | ||
| 535 | + [6, 34], | ||
| 536 | + [6, 22, 38], | ||
| 537 | + [6, 24, 42], | ||
| 538 | + [6, 26, 46], | ||
| 539 | + [6, 28, 50], | ||
| 540 | + [6, 30, 54], | ||
| 541 | + [6, 32, 58], | ||
| 542 | + [6, 34, 62], | ||
| 543 | + [6, 26, 46, 66], | ||
| 544 | + [6, 26, 48, 70], | ||
| 545 | + [6, 26, 50, 74], | ||
| 546 | + [6, 30, 54, 78], | ||
| 547 | + [6, 30, 56, 82], | ||
| 548 | + [6, 30, 58, 86], | ||
| 549 | + [6, 34, 62, 90], | ||
| 550 | + [6, 28, 50, 72, 94], | ||
| 551 | + [6, 26, 50, 74, 98], | ||
| 552 | + [6, 30, 54, 78, 102], | ||
| 553 | + [6, 28, 54, 80, 106], | ||
| 554 | + [6, 32, 58, 84, 110], | ||
| 555 | + [6, 30, 58, 86, 114], | ||
| 556 | + [6, 34, 62, 90, 118], | ||
| 557 | + [6, 26, 50, 74, 98, 122], | ||
| 558 | + [6, 30, 54, 78, 102, 126], | ||
| 559 | + [6, 26, 52, 78, 104, 130], | ||
| 560 | + [6, 30, 56, 82, 108, 134], | ||
| 561 | + [6, 34, 60, 86, 112, 138], | ||
| 562 | + [6, 30, 58, 86, 114, 142], | ||
| 563 | + [6, 34, 62, 90, 118, 146], | ||
| 564 | + [6, 30, 54, 78, 102, 126, 150], | ||
| 565 | + [6, 24, 50, 76, 102, 128, 154], | ||
| 566 | + [6, 28, 54, 80, 106, 132, 158], | ||
| 567 | + [6, 32, 58, 84, 110, 136, 162], | ||
| 568 | + [6, 26, 54, 82, 110, 138, 166], | ||
| 569 | + [6, 30, 58, 86, 114, 142, 170] | ||
| 570 | + ], | ||
| 571 | + | ||
| 572 | + G15: (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0), | ||
| 573 | + G18: (1 << 12) | (1 << 11) | (1 << 10) | (1 << 9) | (1 << 8) | (1 << 5) | (1 << 2) | (1 << 0), | ||
| 574 | + G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1), | ||
| 575 | + | ||
| 576 | + getBCHTypeInfo: function(data) { | ||
| 577 | + var d = data << 10; | ||
| 578 | + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) { | ||
| 579 | + d ^= (QRUtil.G15 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15))); | ||
| 580 | + } | ||
| 581 | + return ((data << 10) | d) ^ QRUtil.G15_MASK; | ||
| 582 | + }, | ||
| 583 | + | ||
| 584 | + getBCHTypeNumber: function(data) { | ||
| 585 | + var d = data << 12; | ||
| 586 | + while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) { | ||
| 587 | + d ^= (QRUtil.G18 << (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18))); | ||
| 588 | + } | ||
| 589 | + return (data << 12) | d; | ||
| 590 | + }, | ||
| 591 | + | ||
| 592 | + getBCHDigit: function(data) { | ||
| 593 | + | ||
| 594 | + var digit = 0; | ||
| 595 | + | ||
| 596 | + while (data != 0) { | ||
| 597 | + digit++; | ||
| 598 | + data >>>= 1; | ||
| 599 | + } | ||
| 600 | + | ||
| 601 | + return digit; | ||
| 602 | + }, | ||
| 603 | + | ||
| 604 | + getPatternPosition: function(typeNumber) { | ||
| 605 | + return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1]; | ||
| 606 | + }, | ||
| 607 | + | ||
| 608 | + getMask: function(maskPattern, i, j) { | ||
| 609 | + | ||
| 610 | + switch (maskPattern) { | ||
| 611 | + | ||
| 612 | + case QRMaskPattern.PATTERN000: | ||
| 613 | + return (i + j) % 2 == 0; | ||
| 614 | + case QRMaskPattern.PATTERN001: | ||
| 615 | + return i % 2 == 0; | ||
| 616 | + case QRMaskPattern.PATTERN010: | ||
| 617 | + return j % 3 == 0; | ||
| 618 | + case QRMaskPattern.PATTERN011: | ||
| 619 | + return (i + j) % 3 == 0; | ||
| 620 | + case QRMaskPattern.PATTERN100: | ||
| 621 | + return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0; | ||
| 622 | + case QRMaskPattern.PATTERN101: | ||
| 623 | + return (i * j) % 2 + (i * j) % 3 == 0; | ||
| 624 | + case QRMaskPattern.PATTERN110: | ||
| 625 | + return ((i * j) % 2 + (i * j) % 3) % 2 == 0; | ||
| 626 | + case QRMaskPattern.PATTERN111: | ||
| 627 | + return ((i * j) % 3 + (i + j) % 2) % 2 == 0; | ||
| 628 | + | ||
| 629 | + default: | ||
| 630 | + throw new Error("bad maskPattern:" + maskPattern); | ||
| 631 | + } | ||
| 632 | + }, | ||
| 633 | + | ||
| 634 | + getErrorCorrectPolynomial: function(errorCorrectLength) { | ||
| 635 | + | ||
| 636 | + var a = new QRPolynomial([1], 0); | ||
| 637 | + | ||
| 638 | + for (var i = 0; i < errorCorrectLength; i++) { | ||
| 639 | + a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0)); | ||
| 640 | + } | ||
| 641 | + | ||
| 642 | + return a; | ||
| 643 | + }, | ||
| 644 | + | ||
| 645 | + getLengthInBits: function(mode, type) { | ||
| 646 | + | ||
| 647 | + if (1 <= type && type < 10) { | ||
| 648 | + | ||
| 649 | + // 1 - 9 | ||
| 650 | + | ||
| 651 | + switch (mode) { | ||
| 652 | + case QRMode.MODE_NUMBER: | ||
| 653 | + return 10; | ||
| 654 | + case QRMode.MODE_ALPHA_NUM: | ||
| 655 | + return 9; | ||
| 656 | + case QRMode.MODE_8BIT_BYTE: | ||
| 657 | + return 8; | ||
| 658 | + case QRMode.MODE_KANJI: | ||
| 659 | + return 8; | ||
| 660 | + default: | ||
| 661 | + throw new Error("mode:" + mode); | ||
| 662 | + } | ||
| 663 | + | ||
| 664 | + } else if (type < 27) { | ||
| 665 | + | ||
| 666 | + // 10 - 26 | ||
| 667 | + | ||
| 668 | + switch (mode) { | ||
| 669 | + case QRMode.MODE_NUMBER: | ||
| 670 | + return 12; | ||
| 671 | + case QRMode.MODE_ALPHA_NUM: | ||
| 672 | + return 11; | ||
| 673 | + case QRMode.MODE_8BIT_BYTE: | ||
| 674 | + return 16; | ||
| 675 | + case QRMode.MODE_KANJI: | ||
| 676 | + return 10; | ||
| 677 | + default: | ||
| 678 | + throw new Error("mode:" + mode); | ||
| 679 | + } | ||
| 680 | + | ||
| 681 | + } else if (type < 41) { | ||
| 682 | + | ||
| 683 | + // 27 - 40 | ||
| 684 | + | ||
| 685 | + switch (mode) { | ||
| 686 | + case QRMode.MODE_NUMBER: | ||
| 687 | + return 14; | ||
| 688 | + case QRMode.MODE_ALPHA_NUM: | ||
| 689 | + return 13; | ||
| 690 | + case QRMode.MODE_8BIT_BYTE: | ||
| 691 | + return 16; | ||
| 692 | + case QRMode.MODE_KANJI: | ||
| 693 | + return 12; | ||
| 694 | + default: | ||
| 695 | + throw new Error("mode:" + mode); | ||
| 696 | + } | ||
| 697 | + | ||
| 698 | + } else { | ||
| 699 | + throw new Error("type:" + type); | ||
| 700 | + } | ||
| 701 | + }, | ||
| 702 | + | ||
| 703 | + getLostPoint: function(qrCode) { | ||
| 704 | + | ||
| 705 | + var moduleCount = qrCode.getModuleCount(); | ||
| 706 | + | ||
| 707 | + var lostPoint = 0; | ||
| 708 | + | ||
| 709 | + // LEVEL1 | ||
| 710 | + | ||
| 711 | + for (var row = 0; row < moduleCount; row++) { | ||
| 712 | + | ||
| 713 | + for (var col = 0; col < moduleCount; col++) { | ||
| 714 | + | ||
| 715 | + var sameCount = 0; | ||
| 716 | + var dark = qrCode.isDark(row, col); | ||
| 717 | + | ||
| 718 | + for (var r = -1; r <= 1; r++) { | ||
| 719 | + | ||
| 720 | + if (row + r < 0 || moduleCount <= row + r) { | ||
| 721 | + continue; | ||
| 722 | + } | ||
| 723 | + | ||
| 724 | + for (var c = -1; c <= 1; c++) { | ||
| 725 | + | ||
| 726 | + if (col + c < 0 || moduleCount <= col + c) { | ||
| 727 | + continue; | ||
| 728 | + } | ||
| 729 | + | ||
| 730 | + if (r == 0 && c == 0) { | ||
| 731 | + continue; | ||
| 732 | + } | ||
| 733 | + | ||
| 734 | + if (dark == qrCode.isDark(row + r, col + c)) { | ||
| 735 | + sameCount++; | ||
| 736 | + } | ||
| 737 | + } | ||
| 738 | + } | ||
| 739 | + | ||
| 740 | + if (sameCount > 5) { | ||
| 741 | + lostPoint += (3 + sameCount - 5); | ||
| 742 | + } | ||
| 743 | + } | ||
| 744 | + } | ||
| 745 | + | ||
| 746 | + // LEVEL2 | ||
| 747 | + | ||
| 748 | + for (var row = 0; row < moduleCount - 1; row++) { | ||
| 749 | + for (var col = 0; col < moduleCount - 1; col++) { | ||
| 750 | + var count = 0; | ||
| 751 | + if (qrCode.isDark(row, col)) count++; | ||
| 752 | + if (qrCode.isDark(row + 1, col)) count++; | ||
| 753 | + if (qrCode.isDark(row, col + 1)) count++; | ||
| 754 | + if (qrCode.isDark(row + 1, col + 1)) count++; | ||
| 755 | + if (count == 0 || count == 4) { | ||
| 756 | + lostPoint += 3; | ||
| 757 | + } | ||
| 758 | + } | ||
| 759 | + } | ||
| 760 | + | ||
| 761 | + // LEVEL3 | ||
| 762 | + | ||
| 763 | + for (var row = 0; row < moduleCount; row++) { | ||
| 764 | + for (var col = 0; col < moduleCount - 6; col++) { | ||
| 765 | + if (qrCode.isDark(row, col) && | ||
| 766 | + !qrCode.isDark(row, col + 1) && | ||
| 767 | + qrCode.isDark(row, col + 2) && | ||
| 768 | + qrCode.isDark(row, col + 3) && | ||
| 769 | + qrCode.isDark(row, col + 4) && | ||
| 770 | + !qrCode.isDark(row, col + 5) && | ||
| 771 | + qrCode.isDark(row, col + 6)) { | ||
| 772 | + lostPoint += 40; | ||
| 773 | + } | ||
| 774 | + } | ||
| 775 | + } | ||
| 776 | + | ||
| 777 | + for (var col = 0; col < moduleCount; col++) { | ||
| 778 | + for (var row = 0; row < moduleCount - 6; row++) { | ||
| 779 | + if (qrCode.isDark(row, col) && | ||
| 780 | + !qrCode.isDark(row + 1, col) && | ||
| 781 | + qrCode.isDark(row + 2, col) && | ||
| 782 | + qrCode.isDark(row + 3, col) && | ||
| 783 | + qrCode.isDark(row + 4, col) && | ||
| 784 | + !qrCode.isDark(row + 5, col) && | ||
| 785 | + qrCode.isDark(row + 6, col)) { | ||
| 786 | + lostPoint += 40; | ||
| 787 | + } | ||
| 788 | + } | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + // LEVEL4 | ||
| 792 | + | ||
| 793 | + var darkCount = 0; | ||
| 794 | + | ||
| 795 | + for (var col = 0; col < moduleCount; col++) { | ||
| 796 | + for (var row = 0; row < moduleCount; row++) { | ||
| 797 | + if (qrCode.isDark(row, col)) { | ||
| 798 | + darkCount++; | ||
| 799 | + } | ||
| 800 | + } | ||
| 801 | + } | ||
| 802 | + | ||
| 803 | + var ratio = Math.abs(100 * darkCount / moduleCount / moduleCount - 50) / 5; | ||
| 804 | + lostPoint += ratio * 10; | ||
| 805 | + | ||
| 806 | + return lostPoint; | ||
| 807 | + } | ||
| 808 | + | ||
| 809 | + }; | ||
| 810 | + | ||
| 811 | + | ||
| 812 | + //--------------------------------------------------------------------- | ||
| 813 | + // QRMath | ||
| 814 | + //--------------------------------------------------------------------- | ||
| 815 | + | ||
| 816 | + var QRMath = { | ||
| 817 | + | ||
| 818 | + glog: function(n) { | ||
| 819 | + | ||
| 820 | + if (n < 1) { | ||
| 821 | + throw new Error("glog(" + n + ")"); | ||
| 822 | + } | ||
| 823 | + | ||
| 824 | + return QRMath.LOG_TABLE[n]; | ||
| 825 | + }, | ||
| 826 | + | ||
| 827 | + gexp: function(n) { | ||
| 828 | + | ||
| 829 | + while (n < 0) { | ||
| 830 | + n += 255; | ||
| 831 | + } | ||
| 832 | + | ||
| 833 | + while (n >= 256) { | ||
| 834 | + n -= 255; | ||
| 835 | + } | ||
| 836 | + | ||
| 837 | + return QRMath.EXP_TABLE[n]; | ||
| 838 | + }, | ||
| 839 | + | ||
| 840 | + EXP_TABLE: new Array(256), | ||
| 841 | + | ||
| 842 | + LOG_TABLE: new Array(256) | ||
| 843 | + | ||
| 844 | + }; | ||
| 845 | + | ||
| 846 | + for (var i = 0; i < 8; i++) { | ||
| 847 | + QRMath.EXP_TABLE[i] = 1 << i; | ||
| 848 | + } | ||
| 849 | + for (var i = 8; i < 256; i++) { | ||
| 850 | + QRMath.EXP_TABLE[i] = QRMath.EXP_TABLE[i - 4] ^ | ||
| 851 | + QRMath.EXP_TABLE[i - 5] ^ | ||
| 852 | + QRMath.EXP_TABLE[i - 6] ^ | ||
| 853 | + QRMath.EXP_TABLE[i - 8]; | ||
| 854 | + } | ||
| 855 | + for (var i = 0; i < 255; i++) { | ||
| 856 | + QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i; | ||
| 857 | + } | ||
| 858 | + | ||
| 859 | + //--------------------------------------------------------------------- | ||
| 860 | + // QRPolynomial | ||
| 861 | + //--------------------------------------------------------------------- | ||
| 862 | + | ||
| 863 | + function QRPolynomial(num, shift) { | ||
| 864 | + | ||
| 865 | + if (num.length == undefined) { | ||
| 866 | + throw new Error(num.length + "/" + shift); | ||
| 867 | + } | ||
| 868 | + | ||
| 869 | + var offset = 0; | ||
| 870 | + | ||
| 871 | + while (offset < num.length && num[offset] == 0) { | ||
| 872 | + offset++; | ||
| 873 | + } | ||
| 874 | + | ||
| 875 | + this.num = new Array(num.length - offset + shift); | ||
| 876 | + for (var i = 0; i < num.length - offset; i++) { | ||
| 877 | + this.num[i] = num[i + offset]; | ||
| 878 | + } | ||
| 879 | + } | ||
| 880 | + | ||
| 881 | + QRPolynomial.prototype = { | ||
| 882 | + | ||
| 883 | + get: function(index) { | ||
| 884 | + return this.num[index]; | ||
| 885 | + }, | ||
| 886 | + | ||
| 887 | + getLength: function() { | ||
| 888 | + return this.num.length; | ||
| 889 | + }, | ||
| 890 | + | ||
| 891 | + multiply: function(e) { | ||
| 892 | + | ||
| 893 | + var num = new Array(this.getLength() + e.getLength() - 1); | ||
| 894 | + | ||
| 895 | + for (var i = 0; i < this.getLength(); i++) { | ||
| 896 | + for (var j = 0; j < e.getLength(); j++) { | ||
| 897 | + num[i + j] ^= QRMath.gexp(QRMath.glog(this.get(i)) + QRMath.glog(e.get(j))); | ||
| 898 | + } | ||
| 899 | + } | ||
| 900 | + | ||
| 901 | + return new QRPolynomial(num, 0); | ||
| 902 | + }, | ||
| 903 | + | ||
| 904 | + mod: function(e) { | ||
| 905 | + | ||
| 906 | + if (this.getLength() - e.getLength() < 0) { | ||
| 907 | + return this; | ||
| 908 | + } | ||
| 909 | + | ||
| 910 | + var ratio = QRMath.glog(this.get(0)) - QRMath.glog(e.get(0)); | ||
| 911 | + | ||
| 912 | + var num = new Array(this.getLength()); | ||
| 913 | + | ||
| 914 | + for (var i = 0; i < this.getLength(); i++) { | ||
| 915 | + num[i] = this.get(i); | ||
| 916 | + } | ||
| 917 | + | ||
| 918 | + for (var i = 0; i < e.getLength(); i++) { | ||
| 919 | + num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio); | ||
| 920 | + } | ||
| 921 | + | ||
| 922 | + // recursive call | ||
| 923 | + return new QRPolynomial(num, 0).mod(e); | ||
| 924 | + } | ||
| 925 | + }; | ||
| 926 | + | ||
| 927 | + //--------------------------------------------------------------------- | ||
| 928 | + // QRRSBlock | ||
| 929 | + //--------------------------------------------------------------------- | ||
| 930 | + | ||
| 931 | + function QRRSBlock(totalCount, dataCount) { | ||
| 932 | + this.totalCount = totalCount; | ||
| 933 | + this.dataCount = dataCount; | ||
| 934 | + } | ||
| 935 | + | ||
| 936 | + QRRSBlock.RS_BLOCK_TABLE = [ | ||
| 937 | + | ||
| 938 | + // L | ||
| 939 | + // M | ||
| 940 | + // Q | ||
| 941 | + // H | ||
| 942 | + | ||
| 943 | + // 1 | ||
| 944 | + [1, 26, 19], | ||
| 945 | + [1, 26, 16], | ||
| 946 | + [1, 26, 13], | ||
| 947 | + [1, 26, 9], | ||
| 948 | + | ||
| 949 | + // 2 | ||
| 950 | + [1, 44, 34], | ||
| 951 | + [1, 44, 28], | ||
| 952 | + [1, 44, 22], | ||
| 953 | + [1, 44, 16], | ||
| 954 | + | ||
| 955 | + // 3 | ||
| 956 | + [1, 70, 55], | ||
| 957 | + [1, 70, 44], | ||
| 958 | + [2, 35, 17], | ||
| 959 | + [2, 35, 13], | ||
| 960 | + | ||
| 961 | + // 4 | ||
| 962 | + [1, 100, 80], | ||
| 963 | + [2, 50, 32], | ||
| 964 | + [2, 50, 24], | ||
| 965 | + [4, 25, 9], | ||
| 966 | + | ||
| 967 | + // 5 | ||
| 968 | + [1, 134, 108], | ||
| 969 | + [2, 67, 43], | ||
| 970 | + [2, 33, 15, 2, 34, 16], | ||
| 971 | + [2, 33, 11, 2, 34, 12], | ||
| 972 | + | ||
| 973 | + // 6 | ||
| 974 | + [2, 86, 68], | ||
| 975 | + [4, 43, 27], | ||
| 976 | + [4, 43, 19], | ||
| 977 | + [4, 43, 15], | ||
| 978 | + | ||
| 979 | + // 7 | ||
| 980 | + [2, 98, 78], | ||
| 981 | + [4, 49, 31], | ||
| 982 | + [2, 32, 14, 4, 33, 15], | ||
| 983 | + [4, 39, 13, 1, 40, 14], | ||
| 984 | + | ||
| 985 | + // 8 | ||
| 986 | + [2, 121, 97], | ||
| 987 | + [2, 60, 38, 2, 61, 39], | ||
| 988 | + [4, 40, 18, 2, 41, 19], | ||
| 989 | + [4, 40, 14, 2, 41, 15], | ||
| 990 | + | ||
| 991 | + // 9 | ||
| 992 | + [2, 146, 116], | ||
| 993 | + [3, 58, 36, 2, 59, 37], | ||
| 994 | + [4, 36, 16, 4, 37, 17], | ||
| 995 | + [4, 36, 12, 4, 37, 13], | ||
| 996 | + | ||
| 997 | + // 10 | ||
| 998 | + [2, 86, 68, 2, 87, 69], | ||
| 999 | + [4, 69, 43, 1, 70, 44], | ||
| 1000 | + [6, 43, 19, 2, 44, 20], | ||
| 1001 | + [6, 43, 15, 2, 44, 16], | ||
| 1002 | + | ||
| 1003 | + // 11 | ||
| 1004 | + [4, 101, 81], | ||
| 1005 | + [1, 80, 50, 4, 81, 51], | ||
| 1006 | + [4, 50, 22, 4, 51, 23], | ||
| 1007 | + [3, 36, 12, 8, 37, 13], | ||
| 1008 | + | ||
| 1009 | + // 12 | ||
| 1010 | + [2, 116, 92, 2, 117, 93], | ||
| 1011 | + [6, 58, 36, 2, 59, 37], | ||
| 1012 | + [4, 46, 20, 6, 47, 21], | ||
| 1013 | + [7, 42, 14, 4, 43, 15], | ||
| 1014 | + | ||
| 1015 | + // 13 | ||
| 1016 | + [4, 133, 107], | ||
| 1017 | + [8, 59, 37, 1, 60, 38], | ||
| 1018 | + [8, 44, 20, 4, 45, 21], | ||
| 1019 | + [12, 33, 11, 4, 34, 12], | ||
| 1020 | + | ||
| 1021 | + // 14 | ||
| 1022 | + [3, 145, 115, 1, 146, 116], | ||
| 1023 | + [4, 64, 40, 5, 65, 41], | ||
| 1024 | + [11, 36, 16, 5, 37, 17], | ||
| 1025 | + [11, 36, 12, 5, 37, 13], | ||
| 1026 | + | ||
| 1027 | + // 15 | ||
| 1028 | + [5, 109, 87, 1, 110, 88], | ||
| 1029 | + [5, 65, 41, 5, 66, 42], | ||
| 1030 | + [5, 54, 24, 7, 55, 25], | ||
| 1031 | + [11, 36, 12], | ||
| 1032 | + | ||
| 1033 | + // 16 | ||
| 1034 | + [5, 122, 98, 1, 123, 99], | ||
| 1035 | + [7, 73, 45, 3, 74, 46], | ||
| 1036 | + [15, 43, 19, 2, 44, 20], | ||
| 1037 | + [3, 45, 15, 13, 46, 16], | ||
| 1038 | + | ||
| 1039 | + // 17 | ||
| 1040 | + [1, 135, 107, 5, 136, 108], | ||
| 1041 | + [10, 74, 46, 1, 75, 47], | ||
| 1042 | + [1, 50, 22, 15, 51, 23], | ||
| 1043 | + [2, 42, 14, 17, 43, 15], | ||
| 1044 | + | ||
| 1045 | + // 18 | ||
| 1046 | + [5, 150, 120, 1, 151, 121], | ||
| 1047 | + [9, 69, 43, 4, 70, 44], | ||
| 1048 | + [17, 50, 22, 1, 51, 23], | ||
| 1049 | + [2, 42, 14, 19, 43, 15], | ||
| 1050 | + | ||
| 1051 | + // 19 | ||
| 1052 | + [3, 141, 113, 4, 142, 114], | ||
| 1053 | + [3, 70, 44, 11, 71, 45], | ||
| 1054 | + [17, 47, 21, 4, 48, 22], | ||
| 1055 | + [9, 39, 13, 16, 40, 14], | ||
| 1056 | + | ||
| 1057 | + // 20 | ||
| 1058 | + [3, 135, 107, 5, 136, 108], | ||
| 1059 | + [3, 67, 41, 13, 68, 42], | ||
| 1060 | + [15, 54, 24, 5, 55, 25], | ||
| 1061 | + [15, 43, 15, 10, 44, 16], | ||
| 1062 | + | ||
| 1063 | + // 21 | ||
| 1064 | + [4, 144, 116, 4, 145, 117], | ||
| 1065 | + [17, 68, 42], | ||
| 1066 | + [17, 50, 22, 6, 51, 23], | ||
| 1067 | + [19, 46, 16, 6, 47, 17], | ||
| 1068 | + | ||
| 1069 | + // 22 | ||
| 1070 | + [2, 139, 111, 7, 140, 112], | ||
| 1071 | + [17, 74, 46], | ||
| 1072 | + [7, 54, 24, 16, 55, 25], | ||
| 1073 | + [34, 37, 13], | ||
| 1074 | + | ||
| 1075 | + // 23 | ||
| 1076 | + [4, 151, 121, 5, 152, 122], | ||
| 1077 | + [4, 75, 47, 14, 76, 48], | ||
| 1078 | + [11, 54, 24, 14, 55, 25], | ||
| 1079 | + [16, 45, 15, 14, 46, 16], | ||
| 1080 | + | ||
| 1081 | + // 24 | ||
| 1082 | + [6, 147, 117, 4, 148, 118], | ||
| 1083 | + [6, 73, 45, 14, 74, 46], | ||
| 1084 | + [11, 54, 24, 16, 55, 25], | ||
| 1085 | + [30, 46, 16, 2, 47, 17], | ||
| 1086 | + | ||
| 1087 | + // 25 | ||
| 1088 | + [8, 132, 106, 4, 133, 107], | ||
| 1089 | + [8, 75, 47, 13, 76, 48], | ||
| 1090 | + [7, 54, 24, 22, 55, 25], | ||
| 1091 | + [22, 45, 15, 13, 46, 16], | ||
| 1092 | + | ||
| 1093 | + // 26 | ||
| 1094 | + [10, 142, 114, 2, 143, 115], | ||
| 1095 | + [19, 74, 46, 4, 75, 47], | ||
| 1096 | + [28, 50, 22, 6, 51, 23], | ||
| 1097 | + [33, 46, 16, 4, 47, 17], | ||
| 1098 | + | ||
| 1099 | + // 27 | ||
| 1100 | + [8, 152, 122, 4, 153, 123], | ||
| 1101 | + [22, 73, 45, 3, 74, 46], | ||
| 1102 | + [8, 53, 23, 26, 54, 24], | ||
| 1103 | + [12, 45, 15, 28, 46, 16], | ||
| 1104 | + | ||
| 1105 | + // 28 | ||
| 1106 | + [3, 147, 117, 10, 148, 118], | ||
| 1107 | + [3, 73, 45, 23, 74, 46], | ||
| 1108 | + [4, 54, 24, 31, 55, 25], | ||
| 1109 | + [11, 45, 15, 31, 46, 16], | ||
| 1110 | + | ||
| 1111 | + // 29 | ||
| 1112 | + [7, 146, 116, 7, 147, 117], | ||
| 1113 | + [21, 73, 45, 7, 74, 46], | ||
| 1114 | + [1, 53, 23, 37, 54, 24], | ||
| 1115 | + [19, 45, 15, 26, 46, 16], | ||
| 1116 | + | ||
| 1117 | + // 30 | ||
| 1118 | + [5, 145, 115, 10, 146, 116], | ||
| 1119 | + [19, 75, 47, 10, 76, 48], | ||
| 1120 | + [15, 54, 24, 25, 55, 25], | ||
| 1121 | + [23, 45, 15, 25, 46, 16], | ||
| 1122 | + | ||
| 1123 | + // 31 | ||
| 1124 | + [13, 145, 115, 3, 146, 116], | ||
| 1125 | + [2, 74, 46, 29, 75, 47], | ||
| 1126 | + [42, 54, 24, 1, 55, 25], | ||
| 1127 | + [23, 45, 15, 28, 46, 16], | ||
| 1128 | + | ||
| 1129 | + // 32 | ||
| 1130 | + [17, 145, 115], | ||
| 1131 | + [10, 74, 46, 23, 75, 47], | ||
| 1132 | + [10, 54, 24, 35, 55, 25], | ||
| 1133 | + [19, 45, 15, 35, 46, 16], | ||
| 1134 | + | ||
| 1135 | + // 33 | ||
| 1136 | + [17, 145, 115, 1, 146, 116], | ||
| 1137 | + [14, 74, 46, 21, 75, 47], | ||
| 1138 | + [29, 54, 24, 19, 55, 25], | ||
| 1139 | + [11, 45, 15, 46, 46, 16], | ||
| 1140 | + | ||
| 1141 | + // 34 | ||
| 1142 | + [13, 145, 115, 6, 146, 116], | ||
| 1143 | + [14, 74, 46, 23, 75, 47], | ||
| 1144 | + [44, 54, 24, 7, 55, 25], | ||
| 1145 | + [59, 46, 16, 1, 47, 17], | ||
| 1146 | + | ||
| 1147 | + // 35 | ||
| 1148 | + [12, 151, 121, 7, 152, 122], | ||
| 1149 | + [12, 75, 47, 26, 76, 48], | ||
| 1150 | + [39, 54, 24, 14, 55, 25], | ||
| 1151 | + [22, 45, 15, 41, 46, 16], | ||
| 1152 | + | ||
| 1153 | + // 36 | ||
| 1154 | + [6, 151, 121, 14, 152, 122], | ||
| 1155 | + [6, 75, 47, 34, 76, 48], | ||
| 1156 | + [46, 54, 24, 10, 55, 25], | ||
| 1157 | + [2, 45, 15, 64, 46, 16], | ||
| 1158 | + | ||
| 1159 | + // 37 | ||
| 1160 | + [17, 152, 122, 4, 153, 123], | ||
| 1161 | + [29, 74, 46, 14, 75, 47], | ||
| 1162 | + [49, 54, 24, 10, 55, 25], | ||
| 1163 | + [24, 45, 15, 46, 46, 16], | ||
| 1164 | + | ||
| 1165 | + // 38 | ||
| 1166 | + [4, 152, 122, 18, 153, 123], | ||
| 1167 | + [13, 74, 46, 32, 75, 47], | ||
| 1168 | + [48, 54, 24, 14, 55, 25], | ||
| 1169 | + [42, 45, 15, 32, 46, 16], | ||
| 1170 | + | ||
| 1171 | + // 39 | ||
| 1172 | + [20, 147, 117, 4, 148, 118], | ||
| 1173 | + [40, 75, 47, 7, 76, 48], | ||
| 1174 | + [43, 54, 24, 22, 55, 25], | ||
| 1175 | + [10, 45, 15, 67, 46, 16], | ||
| 1176 | + | ||
| 1177 | + // 40 | ||
| 1178 | + [19, 148, 118, 6, 149, 119], | ||
| 1179 | + [18, 75, 47, 31, 76, 48], | ||
| 1180 | + [34, 54, 24, 34, 55, 25], | ||
| 1181 | + [20, 45, 15, 61, 46, 16] | ||
| 1182 | + ]; | ||
| 1183 | + | ||
| 1184 | + QRRSBlock.getRSBlocks = function(typeNumber, errorCorrectLevel) { | ||
| 1185 | + | ||
| 1186 | + var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel); | ||
| 1187 | + | ||
| 1188 | + if (rsBlock == undefined) { | ||
| 1189 | + throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" + errorCorrectLevel); | ||
| 1190 | + } | ||
| 1191 | + | ||
| 1192 | + var length = rsBlock.length / 3; | ||
| 1193 | + | ||
| 1194 | + var list = new Array(); | ||
| 1195 | + | ||
| 1196 | + for (var i = 0; i < length; i++) { | ||
| 1197 | + | ||
| 1198 | + var count = rsBlock[i * 3 + 0]; | ||
| 1199 | + var totalCount = rsBlock[i * 3 + 1]; | ||
| 1200 | + var dataCount = rsBlock[i * 3 + 2]; | ||
| 1201 | + | ||
| 1202 | + for (var j = 0; j < count; j++) { | ||
| 1203 | + list.push(new QRRSBlock(totalCount, dataCount)); | ||
| 1204 | + } | ||
| 1205 | + } | ||
| 1206 | + | ||
| 1207 | + return list; | ||
| 1208 | + } | ||
| 1209 | + | ||
| 1210 | + QRRSBlock.getRsBlockTable = function(typeNumber, errorCorrectLevel) { | ||
| 1211 | + | ||
| 1212 | + switch (errorCorrectLevel) { | ||
| 1213 | + case QRErrorCorrectLevel.L: | ||
| 1214 | + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0]; | ||
| 1215 | + case QRErrorCorrectLevel.M: | ||
| 1216 | + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1]; | ||
| 1217 | + case QRErrorCorrectLevel.Q: | ||
| 1218 | + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2]; | ||
| 1219 | + case QRErrorCorrectLevel.H: | ||
| 1220 | + return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3]; | ||
| 1221 | + default: | ||
| 1222 | + return undefined; | ||
| 1223 | + } | ||
| 1224 | + } | ||
| 1225 | + | ||
| 1226 | + //--------------------------------------------------------------------- | ||
| 1227 | + // QRBitBuffer | ||
| 1228 | + //--------------------------------------------------------------------- | ||
| 1229 | + | ||
| 1230 | + function QRBitBuffer() { | ||
| 1231 | + this.buffer = new Array(); | ||
| 1232 | + this.length = 0; | ||
| 1233 | + } | ||
| 1234 | + | ||
| 1235 | + QRBitBuffer.prototype = { | ||
| 1236 | + | ||
| 1237 | + get: function(index) { | ||
| 1238 | + var bufIndex = Math.floor(index / 8); | ||
| 1239 | + return ((this.buffer[bufIndex] >>> (7 - index % 8)) & 1) == 1; | ||
| 1240 | + }, | ||
| 1241 | + | ||
| 1242 | + put: function(num, length) { | ||
| 1243 | + for (var i = 0; i < length; i++) { | ||
| 1244 | + this.putBit(((num >>> (length - i - 1)) & 1) == 1); | ||
| 1245 | + } | ||
| 1246 | + }, | ||
| 1247 | + | ||
| 1248 | + getLengthInBits: function() { | ||
| 1249 | + return this.length; | ||
| 1250 | + }, | ||
| 1251 | + | ||
| 1252 | + putBit: function(bit) { | ||
| 1253 | + | ||
| 1254 | + var bufIndex = Math.floor(this.length / 8); | ||
| 1255 | + if (this.buffer.length <= bufIndex) { | ||
| 1256 | + this.buffer.push(0); | ||
| 1257 | + } | ||
| 1258 | + | ||
| 1259 | + if (bit) { | ||
| 1260 | + this.buffer[bufIndex] |= (0x80 >>> (this.length % 8)); | ||
| 1261 | + } | ||
| 1262 | + | ||
| 1263 | + this.length++; | ||
| 1264 | + } | ||
| 1265 | + }; | ||
| 1266 | + | ||
| 1267 | + //--------------------------------------------------------------------- | ||
| 1268 | + // Support Chinese | ||
| 1269 | + //--------------------------------------------------------------------- | ||
| 1270 | + function utf16To8(text) { | ||
| 1271 | + var result = ''; | ||
| 1272 | + var c; | ||
| 1273 | + for (var i = 0; i < text.length; i++) { | ||
| 1274 | + c = text.charCodeAt(i); | ||
| 1275 | + if (c >= 0x0001 && c <= 0x007F) { | ||
| 1276 | + result += text.charAt(i); | ||
| 1277 | + } else if (c > 0x07FF) { | ||
| 1278 | + result += String.fromCharCode(0xE0 | c >> 12 & 0x0F); | ||
| 1279 | + result += String.fromCharCode(0x80 | c >> 6 & 0x3F); | ||
| 1280 | + result += String.fromCharCode(0x80 | c >> 0 & 0x3F); | ||
| 1281 | + } else { | ||
| 1282 | + result += String.fromCharCode(0xC0 | c >> 6 & 0x1F); | ||
| 1283 | + result += String.fromCharCode(0x80 | c >> 0 & 0x3F); | ||
| 1284 | + } | ||
| 1285 | + } | ||
| 1286 | + return result; | ||
| 1287 | + } | ||
| 1288 | + | ||
| 1289 | + uQRCode = { | ||
| 1290 | + | ||
| 1291 | + errorCorrectLevel: QRErrorCorrectLevel, | ||
| 1292 | + | ||
| 1293 | + defaults: { | ||
| 1294 | + size: 354, | ||
| 1295 | + margin: 0, | ||
| 1296 | + backgroundColor: '#ffffff', | ||
| 1297 | + foregroundColor: '#000000', | ||
| 1298 | + fileType: 'png', // 'jpg', 'png' | ||
| 1299 | + errorCorrectLevel: QRErrorCorrectLevel.H, | ||
| 1300 | + typeNumber: -1 | ||
| 1301 | + }, | ||
| 1302 | + | ||
| 1303 | + make: function(options) { | ||
| 1304 | + return new Promise((reslove, reject) => { | ||
| 1305 | + var defaultOptions = { | ||
| 1306 | + canvasId: options.canvasId, | ||
| 1307 | + componentInstance: options.componentInstance, | ||
| 1308 | + text: options.text, | ||
| 1309 | + size: this.defaults.size, | ||
| 1310 | + margin: this.defaults.margin, | ||
| 1311 | + backgroundColor: this.defaults.backgroundColor, | ||
| 1312 | + foregroundColor: this.defaults.foregroundColor, | ||
| 1313 | + fileType: this.defaults.fileType, | ||
| 1314 | + errorCorrectLevel: this.defaults.errorCorrectLevel, | ||
| 1315 | + typeNumber: this.defaults.typeNumber | ||
| 1316 | + }; | ||
| 1317 | + if (options) { | ||
| 1318 | + for (var i in options) { | ||
| 1319 | + defaultOptions[i] = options[i]; | ||
| 1320 | + } | ||
| 1321 | + } | ||
| 1322 | + options = defaultOptions; | ||
| 1323 | + if (!options.canvasId) { | ||
| 1324 | + console.error('uQRCode: Please set canvasId!'); | ||
| 1325 | + return; | ||
| 1326 | + } | ||
| 1327 | + | ||
| 1328 | + function createCanvas() { | ||
| 1329 | + var qrcode = new QRCode(options.typeNumber, options.errorCorrectLevel); | ||
| 1330 | + qrcode.addData(utf16To8(options.text)); | ||
| 1331 | + qrcode.make(); | ||
| 1332 | + | ||
| 1333 | + var ctx = uni.createCanvasContext(options.canvasId, options.componentInstance); | ||
| 1334 | + ctx.setFillStyle(options.backgroundColor); | ||
| 1335 | + ctx.fillRect(0, 0, options.size, options.size); | ||
| 1336 | + | ||
| 1337 | + var tileW = (options.size - options.margin * 2) / qrcode.getModuleCount(); | ||
| 1338 | + var tileH = tileW; | ||
| 1339 | + | ||
| 1340 | + for (var row = 0; row < qrcode.getModuleCount(); row++) { | ||
| 1341 | + for (var col = 0; col < qrcode.getModuleCount(); col++) { | ||
| 1342 | + var style = qrcode.isDark(row, col) ? options.foregroundColor : options.backgroundColor; | ||
| 1343 | + ctx.setFillStyle(style); | ||
| 1344 | + var x = Math.round(col * tileW) + options.margin; | ||
| 1345 | + var y = Math.round(row * tileH) + options.margin; | ||
| 1346 | + var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW); | ||
| 1347 | + var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW); | ||
| 1348 | + ctx.fillRect(x, y, w, h); | ||
| 1349 | + } | ||
| 1350 | + } | ||
| 1351 | + | ||
| 1352 | + setTimeout(function() { | ||
| 1353 | + ctx.draw(false, (function() { | ||
| 1354 | + setTimeout(function() { | ||
| 1355 | + uni.canvasToTempFilePath({ | ||
| 1356 | + canvasId: options.canvasId, | ||
| 1357 | + fileType: options.fileType, | ||
| 1358 | + width: options.size, | ||
| 1359 | + height: options.size, | ||
| 1360 | + destWidth: options.size, | ||
| 1361 | + destHeight: options.size, | ||
| 1362 | + success: function(res) { | ||
| 1363 | + let resData; // 将统一为base64格式 | ||
| 1364 | + let tempFilePath = res.tempFilePath; // H5为base64,其他为相对路径 | ||
| 1365 | + | ||
| 1366 | + // #ifdef H5 | ||
| 1367 | + resData = tempFilePath; | ||
| 1368 | + options.success && options.success(resData); | ||
| 1369 | + reslove(resData); | ||
| 1370 | + // #endif | ||
| 1371 | + | ||
| 1372 | + // #ifdef APP-PLUS | ||
| 1373 | + const path = plus.io.convertLocalFileSystemURL(tempFilePath) // 绝对路径 | ||
| 1374 | + let fileReader = new plus.io.FileReader(); | ||
| 1375 | + fileReader.readAsDataURL(path); | ||
| 1376 | + fileReader.onloadend = res => { | ||
| 1377 | + resData = res.target.result; | ||
| 1378 | + options.success && options.success(resData); | ||
| 1379 | + reslove(resData); | ||
| 1380 | + }; | ||
| 1381 | + // #endif | ||
| 1382 | + | ||
| 1383 | + // #ifdef MP-WEIXIN || MP-QQ || MP-TOUTIAO | ||
| 1384 | + uni.getFileSystemManager().readFile({ | ||
| 1385 | + filePath: tempFilePath, | ||
| 1386 | + encoding: 'base64', | ||
| 1387 | + success: res => { | ||
| 1388 | + resData = 'data:image/png;base64,' + res.data; | ||
| 1389 | + options.success && options.success(resData); | ||
| 1390 | + reslove(resData); | ||
| 1391 | + } | ||
| 1392 | + }) | ||
| 1393 | + // #endif | ||
| 1394 | + | ||
| 1395 | + // #ifndef H5 || APP-PLUS || MP-WEIXIN || MP-QQ || MP-TOUTIAO | ||
| 1396 | + if (plus) { | ||
| 1397 | + const path = plus.io.convertLocalFileSystemURL(tempFilePath) // 绝对路径 | ||
| 1398 | + let fileReader = new plus.io.FileReader(); | ||
| 1399 | + fileReader.readAsDataURL(path); | ||
| 1400 | + fileReader.onloadend = res => { | ||
| 1401 | + resData = res.target.result; | ||
| 1402 | + options.success && options.success(resData); | ||
| 1403 | + reslove(resData); | ||
| 1404 | + }; | ||
| 1405 | + } else { | ||
| 1406 | + uni.request({ | ||
| 1407 | + url: tempFilePath, | ||
| 1408 | + method: 'GET', | ||
| 1409 | + responseType: 'arraybuffer', | ||
| 1410 | + success: res => { | ||
| 1411 | + resData = `data:image/png;base64,${uni.arrayBufferToBase64(res.data)}`; // 把arraybuffer转成base64 | ||
| 1412 | + options.success && options.success(resData); | ||
| 1413 | + reslove(resData); | ||
| 1414 | + } | ||
| 1415 | + }) | ||
| 1416 | + } | ||
| 1417 | + // #endif | ||
| 1418 | + }, | ||
| 1419 | + fail: function(error) { | ||
| 1420 | + options.fail && options.fail(error); | ||
| 1421 | + reject(error); | ||
| 1422 | + }, | ||
| 1423 | + complete: function(res) { | ||
| 1424 | + options.complete && options.complete(res); | ||
| 1425 | + } | ||
| 1426 | + }, options.componentInstance); | ||
| 1427 | + }, options.text.length + 100); | ||
| 1428 | + })()); | ||
| 1429 | + }, 150); | ||
| 1430 | + } | ||
| 1431 | + | ||
| 1432 | + createCanvas(); | ||
| 1433 | + }); | ||
| 1434 | + } | ||
| 1435 | + } | ||
| 1436 | + | ||
| 1437 | +})() | ||
| 1438 | + | ||
| 1439 | +export default uQRCode | ||
| 1440 | + | ||
| 1441 | + |
pages/businessCard/provideCard.vue
| @@ -12,8 +12,8 @@ | @@ -12,8 +12,8 @@ | ||
| 12 | </uni-section> | 12 | </uni-section> |
| 13 | 13 | ||
| 14 | <view class=" uni-card" style="padding: 10px 0"> | 14 | <view class=" uni-card" style="padding: 10px 0"> |
| 15 | - <view style="width: 80%;height: 100px;border: 1px solid #ccc;margin: 0 auto"> | ||
| 16 | - | 15 | + <view class="qr-box"> |
| 16 | + <canvas canvas-id="qrcode" v-show="qrShow" style="width: 300rpx;margin: 0 auto;"/> | ||
| 17 | </view> | 17 | </view> |
| 18 | </view> | 18 | </view> |
| 19 | 19 | ||
| @@ -32,10 +32,11 @@ | @@ -32,10 +32,11 @@ | ||
| 32 | </template> | 32 | </template> |
| 33 | 33 | ||
| 34 | <script> | 34 | <script> |
| 35 | +import uQRCode from '../../common/uqrcode.js' //引入uqrcode.js | ||
| 35 | export default { | 36 | export default { |
| 36 | data() { | 37 | data() { |
| 37 | return { | 38 | return { |
| 38 | - | 39 | + qrShow: false, |
| 39 | cardTypeName: '',// 卡类型名称 | 40 | cardTypeName: '',// 卡类型名称 |
| 40 | cardRuleName: '',// 卡名称 | 41 | cardRuleName: '',// 卡名称 |
| 41 | plName:'', // 停车场 | 42 | plName:'', // 停车场 |
| @@ -47,13 +48,13 @@ export default { | @@ -47,13 +48,13 @@ export default { | ||
| 47 | wx.showShareMenu({ | 48 | wx.showShareMenu({ |
| 48 | withShareTicket: true | 49 | withShareTicket: true |
| 49 | }) | 50 | }) |
| 50 | - let option = JSON.parse(params.optionData) | ||
| 51 | - console.log(option) | ||
| 52 | - this.cardTypeName = option.cardTypeName | ||
| 53 | - this.cardRuleName = option.cardRuleName | ||
| 54 | - this.plName = option.plName | ||
| 55 | - this.price = option.value | ||
| 56 | - this.cardNum = option.cardNum | 51 | + // let option = JSON.parse(params.optionData) |
| 52 | + // console.log(option) | ||
| 53 | + // this.cardTypeName = option.cardTypeName | ||
| 54 | + // this.cardRuleName = option.cardRuleName | ||
| 55 | + // this.plName = option.plName | ||
| 56 | + // this.price = option.value | ||
| 57 | + // this.cardNum = option.cardNum | ||
| 57 | // this.maxNum = option.cardNum | 58 | // this.maxNum = option.cardNum |
| 58 | this.getCouponDynamicQR() | 59 | this.getCouponDynamicQR() |
| 59 | }, | 60 | }, |
| @@ -78,8 +79,27 @@ export default { | @@ -78,8 +79,27 @@ export default { | ||
| 78 | data: that.$common.requestSign(paramsData) | 79 | data: that.$common.requestSign(paramsData) |
| 79 | }).then(res => { | 80 | }).then(res => { |
| 80 | console.log(res) | 81 | console.log(res) |
| 82 | + let qrUrl = res.data.qrUrl | ||
| 83 | + that.qrFun(qrUrl) //调用二维码方法 | ||
| 84 | + console.log(qrUrl) | ||
| 81 | }) | 85 | }) |
| 82 | }, | 86 | }, |
| 87 | + //**生成二维码**// | ||
| 88 | + qrFun: function(text) { | ||
| 89 | + this.qrShow = true | ||
| 90 | + uQRCode.make({ | ||
| 91 | + canvasId: 'qrcode', | ||
| 92 | + componentInstance: this, | ||
| 93 | + text: text, | ||
| 94 | + size: 150, | ||
| 95 | + margin: 0, | ||
| 96 | + backgroundColor: '#ffffff', | ||
| 97 | + foregroundColor: '#000000', | ||
| 98 | + fileType: 'jpg', | ||
| 99 | + errorCorrectLevel: uQRCode.errorCorrectLevel.H, | ||
| 100 | + success: res => {} | ||
| 101 | + }) | ||
| 102 | + } | ||
| 83 | } | 103 | } |
| 84 | } | 104 | } |
| 85 | </script> | 105 | </script> |