hy-app 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +42 -0
  2. package/api/http.ts +138 -0
  3. package/api/index.ts +1 -0
  4. package/common/index.ts +1 -0
  5. package/common/versionControl.ts +102 -0
  6. package/components/dialog/TheDialog.vue +128 -0
  7. package/components/dialog/index.ts +38 -0
  8. package/components/hy-address-picker/hy-address-picker.vue +262 -0
  9. package/components/hy-address-picker/props.ts +27 -0
  10. package/components/hy-address-picker/typing.d.ts +98 -0
  11. package/components/hy-avatar/hy-avatar.vue +217 -0
  12. package/components/hy-avatar/props.ts +20 -0
  13. package/components/hy-avatar/typing.d.ts +64 -0
  14. package/components/hy-back-top/hy-back-top.vue +71 -0
  15. package/components/hy-back-top/props.ts +23 -0
  16. package/components/hy-back-top/typing.d.ts +49 -0
  17. package/components/hy-badge/hy-badge.vue +155 -0
  18. package/components/hy-badge/props.ts +19 -0
  19. package/components/hy-badge/typing.d.ts +60 -0
  20. package/components/hy-button/hy-button.vue +394 -0
  21. package/components/hy-button/props.ts +36 -0
  22. package/components/hy-button/typing.d.ts +125 -0
  23. package/components/hy-card/hy-card.vue +198 -0
  24. package/components/hy-card/props.ts +29 -0
  25. package/components/hy-card/typing.d.ts +112 -0
  26. package/components/hy-cell/hy-cell.vue +268 -0
  27. package/components/hy-cell/props.ts +20 -0
  28. package/components/hy-cell/typing.d.ts +98 -0
  29. package/components/hy-check-button/hy-check-button.vue +71 -0
  30. package/components/hy-check-button/props.ts +20 -0
  31. package/components/hy-check-button/typing.d.ts +79 -0
  32. package/components/hy-checkbox/hy-checkbox.vue +299 -0
  33. package/components/hy-checkbox/props.ts +28 -0
  34. package/components/hy-checkbox/typing.d.ts +77 -0
  35. package/components/hy-datetime-picker/hy-datetime-picker.vue +584 -0
  36. package/components/hy-datetime-picker/props.ts +36 -0
  37. package/components/hy-datetime-picker/typing.d.ts +135 -0
  38. package/components/hy-divider/hy-divider.vue +164 -0
  39. package/components/hy-divider/props.ts +21 -0
  40. package/components/hy-divider/typing.d.ts +64 -0
  41. package/components/hy-empty/hy-empty.vue +122 -0
  42. package/components/hy-empty/props.ts +21 -0
  43. package/components/hy-empty/typing.d.ts +68 -0
  44. package/components/hy-folding-panel/hy-folding-panel.vue +94 -0
  45. package/components/hy-folding-panel/props.ts +17 -0
  46. package/components/hy-folding-panel/typing.d.ts +59 -0
  47. package/components/hy-form/hy-form.vue +372 -0
  48. package/components/hy-form/props.ts +15 -0
  49. package/components/hy-form/typing.d.ts +51 -0
  50. package/components/hy-grid/hy-grid.vue +126 -0
  51. package/components/hy-grid/props.ts +16 -0
  52. package/components/hy-grid/typing.d.ts +62 -0
  53. package/components/hy-icon/hy-icon.vue +207 -0
  54. package/components/hy-icon/props.ts +24 -0
  55. package/components/hy-icon/typing.d.ts +80 -0
  56. package/components/hy-input/hy-input.vue +402 -0
  57. package/components/hy-input/props.ts +41 -0
  58. package/components/hy-input/typing.d.ts +148 -0
  59. package/components/hy-line/hy-line.vue +44 -0
  60. package/components/hy-line/props.ts +12 -0
  61. package/components/hy-line/typing.d.ts +32 -0
  62. package/components/hy-line-progress/hy-line-progress.vue +118 -0
  63. package/components/hy-line-progress/props.ts +12 -0
  64. package/components/hy-line-progress/typing.d.ts +28 -0
  65. package/components/hy-list/hy-list.vue +250 -0
  66. package/components/hy-list/props.ts +18 -0
  67. package/components/hy-list/typing.d.ts +50 -0
  68. package/components/hy-login/ThePhoneLogin.vue +106 -0
  69. package/components/hy-login/TheUserLogin.vue +391 -0
  70. package/components/hy-login/hy-login.vue +283 -0
  71. package/components/hy-login/props.ts +32 -0
  72. package/components/hy-login/typing.d.ts +60 -0
  73. package/components/hy-modal/hy-modal.vue +240 -0
  74. package/components/hy-modal/props.ts +24 -0
  75. package/components/hy-modal/typing.d.ts +70 -0
  76. package/components/hy-navbar/hy-navbar.vue +194 -0
  77. package/components/hy-navbar/props.ts +24 -0
  78. package/components/hy-navbar/typing.d.ts +81 -0
  79. package/components/hy-notice-bar/hy-column-notice.vue +130 -0
  80. package/components/hy-notice-bar/hy-notice-bar.vue +82 -0
  81. package/components/hy-notice-bar/hy-row-notice.vue +182 -0
  82. package/components/hy-notice-bar/props.ts +19 -0
  83. package/components/hy-notice-bar/typing.d.ts +56 -0
  84. package/components/hy-number-step/hy-number-step.vue +428 -0
  85. package/components/hy-number-step/props.ts +29 -0
  86. package/components/hy-number-step/typing.d.ts +104 -0
  87. package/components/hy-overlay/hy-overlay.vue +54 -0
  88. package/components/hy-overlay/props.ts +10 -0
  89. package/components/hy-overlay/typing.d.ts +24 -0
  90. package/components/hy-picker/hy-picker.vue +499 -0
  91. package/components/hy-picker/props.ts +30 -0
  92. package/components/hy-picker/typing.d.ts +115 -0
  93. package/components/hy-popup/hy-popup.vue +269 -0
  94. package/components/hy-popup/props.ts +21 -0
  95. package/components/hy-popup/typing.d.ts +68 -0
  96. package/components/hy-price/hy-price.vue +86 -0
  97. package/components/hy-price/props.ts +13 -0
  98. package/components/hy-price/typing.d.ts +36 -0
  99. package/components/hy-qrcode/hy-qrcode.vue +153 -0
  100. package/components/hy-qrcode/props.ts +20 -0
  101. package/components/hy-qrcode/qrcode.js +1364 -0
  102. package/components/hy-qrcode/typing.d.ts +64 -0
  103. package/components/hy-radio/hy-radio.vue +319 -0
  104. package/components/hy-radio/props.ts +28 -0
  105. package/components/hy-radio/typing.d.ts +85 -0
  106. package/components/hy-rate/hy-rate.vue +261 -0
  107. package/components/hy-rate/props.ts +18 -0
  108. package/components/hy-rate/typing.d.ts +60 -0
  109. package/components/hy-read-more/hy-read-more.vue +134 -0
  110. package/components/hy-read-more/props.ts +20 -0
  111. package/components/hy-read-more/typing.d.ts +44 -0
  112. package/components/hy-safe-bottom/hy-safe-bottom.vue +64 -0
  113. package/components/hy-scroll-list/hy-scroll-list.vue +146 -0
  114. package/components/hy-scroll-list/props.ts +12 -0
  115. package/components/hy-scroll-list/typing.d.ts +28 -0
  116. package/components/hy-search/hy-search.vue +294 -0
  117. package/components/hy-search/props.ts +29 -0
  118. package/components/hy-search/typing.d.ts +109 -0
  119. package/components/hy-slider/hy-slider.vue +511 -0
  120. package/components/hy-slider/props.ts +21 -0
  121. package/components/hy-slider/typing.d.ts +68 -0
  122. package/components/hy-steps/hy-steps.vue +352 -0
  123. package/components/hy-steps/props.ts +15 -0
  124. package/components/hy-steps/typing.d.ts +58 -0
  125. package/components/hy-subsection/hy-subsection.vue +272 -0
  126. package/components/hy-subsection/props.ts +16 -0
  127. package/components/hy-subsection/typing.d.ts +44 -0
  128. package/components/hy-swiper/hy-swiper-indicator.vue +105 -0
  129. package/components/hy-swiper/hy-swiper.vue +242 -0
  130. package/components/hy-swiper/props.ts +30 -0
  131. package/components/hy-swiper/typing.d.ts +107 -0
  132. package/components/hy-switch/hy-switch.vue +168 -0
  133. package/components/hy-switch/props.ts +16 -0
  134. package/components/hy-switch/typing.d.ts +48 -0
  135. package/components/hy-tabs/hy-tabs.vue +416 -0
  136. package/components/hy-tabs/props.ts +26 -0
  137. package/components/hy-tabs/typing.d.ts +86 -0
  138. package/components/hy-tag/hy-tag.vue +374 -0
  139. package/components/hy-tag/props.ts +22 -0
  140. package/components/hy-tag/typing.d.ts +76 -0
  141. package/components/hy-textarea/hy-textarea.vue +229 -0
  142. package/components/hy-textarea/props.ts +26 -0
  143. package/components/hy-textarea/typing.d.ts +27 -0
  144. package/components/hy-tooltip/hy-tooltip.vue +332 -0
  145. package/components/hy-tooltip/props.ts +17 -0
  146. package/components/hy-tooltip/typing.d.ts +52 -0
  147. package/components/hy-transition/hy-transition.vue +150 -0
  148. package/components/hy-transition/index.scss +113 -0
  149. package/components/hy-transition/props.ts +10 -0
  150. package/components/hy-transition/typing.d.ts +36 -0
  151. package/components/hy-upload/hy-upload.vue +557 -0
  152. package/components/hy-upload/props.ts +29 -0
  153. package/components/hy-upload/typing.d.ts +147 -0
  154. package/components/hy-warn/hy-warn.vue +228 -0
  155. package/components/hy-warn/props.ts +14 -0
  156. package/components/hy-warn/typing.d.ts +40 -0
  157. package/components/hy-waterfall/hy-waterfall.vue +51 -0
  158. package/components/hy-waterfall/props.ts +10 -0
  159. package/components/hy-waterfall/typing.d.ts +20 -0
  160. package/components/index.ts +162 -0
  161. package/components/message/TheMessage.vue +169 -0
  162. package/components/message/index.ts +54 -0
  163. package/components/u-form/form.js +22 -0
  164. package/components/u-form/hy-form.vue +324 -0
  165. package/components/u-form/props.js +49 -0
  166. package/components/u-form/schema.js +1451 -0
  167. package/components/u-form/u-form.vue +267 -0
  168. package/components/u-form/utils.js +65 -0
  169. package/components/u-form-item/formItem.js +24 -0
  170. package/components/u-form-item/hy-form-item.vue +360 -0
  171. package/components/u-form-item/props.js +57 -0
  172. package/components/u-form-item/u-form-item.vue +294 -0
  173. package/components/yk-dialog/yk-dialog.vue +129 -0
  174. package/components/yk-tabbar/props.ts +49 -0
  175. package/components/yk-tabbar/yk-tabbar.vue +224 -0
  176. package/config/color.ts +6 -0
  177. package/config/icon.ts +366 -0
  178. package/config/index.ts +2 -0
  179. package/global/index.ts +6 -0
  180. package/global/register-properties.ts +37 -0
  181. package/index.ts +8 -0
  182. package/libs/css/common.scss +0 -0
  183. package/libs/css/iconfont.css +379 -0
  184. package/libs/css/iconfont.ttf +0 -0
  185. package/libs/css/mixin.scss +15 -0
  186. package/package.json +42 -0
  187. package/public/icons/error.png +0 -0
  188. package/public/icons/success.png +0 -0
  189. package/public/icons/warning.png +0 -0
  190. package/store/index.ts +1 -0
  191. package/store/userInfo.ts +25 -0
  192. package/theme.scss +94 -0
  193. package/typing/index.ts +7 -0
  194. package/typing/modules/common.d.ts +50 -0
  195. package/typing/modules/dialog.ts +17 -0
  196. package/typing/modules/enum.ts +67 -0
  197. package/typing/modules/form.ts +161 -0
  198. package/typing/modules/http.ts +68 -0
  199. package/typing/modules/icon.d.ts +366 -0
  200. package/typing/modules/img.ts +15 -0
  201. package/typing/modules/rect.ts +10 -0
  202. package/utils/address.json +5890 -0
  203. package/utils/base64.ts +119 -0
  204. package/utils/index.ts +3 -0
  205. package/utils/inside.ts +310 -0
  206. package/utils/utils.ts +446 -0
@@ -0,0 +1,1364 @@
1
+ let QRCode = {};
2
+ (function () {
3
+ /**
4
+ * 获取单个字符的utf8编码
5
+ * unicode BMP平面约65535个字符
6
+ * @param {num} code
7
+ * return {array}
8
+ */
9
+ function unicodeFormat8(code) {
10
+ // 1 byte
11
+ var c0, c1, c2;
12
+ if (code < 128) {
13
+ return [code];
14
+ // 2 bytes
15
+ } else if (code < 2048) {
16
+ c0 = 192 + (code >> 6);
17
+ c1 = 128 + (code & 63);
18
+ return [c0, c1];
19
+ // 3 bytes
20
+ } else {
21
+ c0 = 224 + (code >> 12);
22
+ c1 = 128 + ((code >> 6) & 63);
23
+ c2 = 128 + (code & 63);
24
+ return [c0, c1, c2];
25
+ }
26
+ }
27
+ /**
28
+ * 获取字符串的utf8编码字节串
29
+ * @param {string} string
30
+ * @return {array}
31
+ */
32
+ function getUTF8Bytes(string) {
33
+ var utf8codes = [];
34
+ for (var i = 0; i < string.length; i++) {
35
+ var code = string.charCodeAt(i);
36
+ var utf8 = unicodeFormat8(code);
37
+ for (var j = 0; j < utf8.length; j++) {
38
+ utf8codes.push(utf8[j]);
39
+ }
40
+ }
41
+ return utf8codes;
42
+ }
43
+ /**
44
+ * 二维码算法实现
45
+ * @param {string} data 要编码的信息字符串
46
+ * @param {num} errorCorrectLevel 纠错等级
47
+ */
48
+ function QRCodeAlg(data, errorCorrectLevel) {
49
+ this.typeNumber = -1; //版本
50
+ this.errorCorrectLevel = errorCorrectLevel;
51
+ this.modules = null; //二维矩阵,存放最终结果
52
+ this.moduleCount = 0; //矩阵大小
53
+ this.dataCache = null; //数据缓存
54
+ this.rsBlocks = null; //版本数据信息
55
+ this.totalDataCount = -1; //可使用的数据量
56
+ this.data = data;
57
+ this.utf8bytes = getUTF8Bytes(data);
58
+ this.make();
59
+ }
60
+ QRCodeAlg.prototype = {
61
+ constructor: QRCodeAlg,
62
+ /**
63
+ * 获取二维码矩阵大小
64
+ * @return {num} 矩阵大小
65
+ */
66
+ getModuleCount: function () {
67
+ return this.moduleCount;
68
+ },
69
+ /**
70
+ * 编码
71
+ */
72
+ make: function () {
73
+ this.getRightType();
74
+ this.dataCache = this.createData();
75
+ this.createQrcode();
76
+ },
77
+ /**
78
+ * 设置二位矩阵功能图形
79
+ * @param {bool} test 表示是否在寻找最好掩膜阶段
80
+ * @param {num} maskPattern 掩膜的版本
81
+ */
82
+ makeImpl: function (maskPattern) {
83
+ this.moduleCount = this.typeNumber * 4 + 17;
84
+ this.modules = new Array(this.moduleCount);
85
+ for (var row = 0; row < this.moduleCount; row++) {
86
+ this.modules[row] = new Array(this.moduleCount);
87
+ }
88
+ this.setupPositionProbePattern(0, 0);
89
+ this.setupPositionProbePattern(this.moduleCount - 7, 0);
90
+ this.setupPositionProbePattern(0, this.moduleCount - 7);
91
+ this.setupPositionAdjustPattern();
92
+ this.setupTimingPattern();
93
+ this.setupTypeInfo(true, maskPattern);
94
+ if (this.typeNumber >= 7) {
95
+ this.setupTypeNumber(true);
96
+ }
97
+ this.mapData(this.dataCache, maskPattern);
98
+ },
99
+ /**
100
+ * 设置二维码的位置探测图形
101
+ * @param {num} row 探测图形的中心横坐标
102
+ * @param {num} col 探测图形的中心纵坐标
103
+ */
104
+ setupPositionProbePattern: function (row, col) {
105
+ for (var r = -1; r <= 7; r++) {
106
+ if (row + r <= -1 || this.moduleCount <= row + r) continue;
107
+ for (var c = -1; c <= 7; c++) {
108
+ if (col + c <= -1 || this.moduleCount <= col + c) continue;
109
+ if (
110
+ (0 <= r && r <= 6 && (c == 0 || c == 6)) ||
111
+ (0 <= c && c <= 6 && (r == 0 || r == 6)) ||
112
+ (2 <= r && r <= 4 && 2 <= c && c <= 4)
113
+ ) {
114
+ this.modules[row + r][col + c] = true;
115
+ } else {
116
+ this.modules[row + r][col + c] = false;
117
+ }
118
+ }
119
+ }
120
+ },
121
+ /**
122
+ * 创建二维码
123
+ * @return {[type]} [description]
124
+ */
125
+ createQrcode: function () {
126
+ var minLostPoint = 0;
127
+ var pattern = 0;
128
+ var bestModules = null;
129
+ for (var i = 0; i < 8; i++) {
130
+ this.makeImpl(i);
131
+ var lostPoint = QRUtil.getLostPoint(this);
132
+ if (i == 0 || minLostPoint > lostPoint) {
133
+ minLostPoint = lostPoint;
134
+ pattern = i;
135
+ bestModules = this.modules;
136
+ }
137
+ }
138
+ this.modules = bestModules;
139
+ this.setupTypeInfo(false, pattern);
140
+ if (this.typeNumber >= 7) {
141
+ this.setupTypeNumber(false);
142
+ }
143
+ },
144
+ /**
145
+ * 设置定位图形
146
+ * @return {[type]} [description]
147
+ */
148
+ setupTimingPattern: function () {
149
+ for (var r = 8; r < this.moduleCount - 8; r++) {
150
+ if (this.modules[r][6] != null) {
151
+ continue;
152
+ }
153
+ this.modules[r][6] = r % 2 == 0;
154
+ if (this.modules[6][r] != null) {
155
+ continue;
156
+ }
157
+ this.modules[6][r] = r % 2 == 0;
158
+ }
159
+ },
160
+ /**
161
+ * 设置矫正图形
162
+ * @return {[type]} [description]
163
+ */
164
+ setupPositionAdjustPattern: function () {
165
+ var pos = QRUtil.getPatternPosition(this.typeNumber);
166
+ for (var i = 0; i < pos.length; i++) {
167
+ for (var j = 0; j < pos.length; j++) {
168
+ var row = pos[i];
169
+ var col = pos[j];
170
+ if (this.modules[row][col] != null) {
171
+ continue;
172
+ }
173
+ for (var r = -2; r <= 2; r++) {
174
+ for (var c = -2; c <= 2; c++) {
175
+ if (
176
+ r == -2 ||
177
+ r == 2 ||
178
+ c == -2 ||
179
+ c == 2 ||
180
+ (r == 0 && c == 0)
181
+ ) {
182
+ this.modules[row + r][col + c] = true;
183
+ } else {
184
+ this.modules[row + r][col + c] = false;
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ },
191
+ /**
192
+ * 设置版本信息(7以上版本才有)
193
+ * @param {bool} test 是否处于判断最佳掩膜阶段
194
+ * @return {[type]} [description]
195
+ */
196
+ setupTypeNumber: function (test) {
197
+ var bits = QRUtil.getBCHTypeNumber(this.typeNumber);
198
+ for (var i = 0; i < 18; i++) {
199
+ var mod = !test && ((bits >> i) & 1) == 1;
200
+ this.modules[Math.floor(i / 3)][(i % 3) + this.moduleCount - 8 - 3] =
201
+ mod;
202
+ this.modules[(i % 3) + this.moduleCount - 8 - 3][Math.floor(i / 3)] =
203
+ mod;
204
+ }
205
+ },
206
+ /**
207
+ * 设置格式信息(纠错等级和掩膜版本)
208
+ * @param {bool} test
209
+ * @param {num} maskPattern 掩膜版本
210
+ * @return {}
211
+ */
212
+ setupTypeInfo: function (test, maskPattern) {
213
+ var data =
214
+ (QRErrorCorrectLevel[this.errorCorrectLevel] << 3) | maskPattern;
215
+ var bits = QRUtil.getBCHTypeInfo(data);
216
+ // vertical
217
+ for (var i = 0; i < 15; i++) {
218
+ var mod = !test && ((bits >> i) & 1) == 1;
219
+ if (i < 6) {
220
+ this.modules[i][8] = mod;
221
+ } else if (i < 8) {
222
+ this.modules[i + 1][8] = mod;
223
+ } else {
224
+ this.modules[this.moduleCount - 15 + i][8] = mod;
225
+ }
226
+ // horizontal
227
+ var mod = !test && ((bits >> i) & 1) == 1;
228
+ if (i < 8) {
229
+ this.modules[8][this.moduleCount - i - 1] = mod;
230
+ } else if (i < 9) {
231
+ this.modules[8][15 - i - 1 + 1] = mod;
232
+ } else {
233
+ this.modules[8][15 - i - 1] = mod;
234
+ }
235
+ }
236
+ // fixed module
237
+ this.modules[this.moduleCount - 8][8] = !test;
238
+ },
239
+ /**
240
+ * 数据编码
241
+ * @return {[type]} [description]
242
+ */
243
+ createData: function () {
244
+ var buffer = new QRBitBuffer();
245
+ var lengthBits = this.typeNumber > 9 ? 16 : 8;
246
+ buffer.put(4, 4); //添加模式
247
+ buffer.put(this.utf8bytes.length, lengthBits);
248
+ for (var i = 0, l = this.utf8bytes.length; i < l; i++) {
249
+ buffer.put(this.utf8bytes[i], 8);
250
+ }
251
+ if (buffer.length + 4 <= this.totalDataCount * 8) {
252
+ buffer.put(0, 4);
253
+ }
254
+ // padding
255
+ while (buffer.length % 8 != 0) {
256
+ buffer.putBit(false);
257
+ }
258
+ // padding
259
+ while (true) {
260
+ if (buffer.length >= this.totalDataCount * 8) {
261
+ break;
262
+ }
263
+ buffer.put(QRCodeAlg.PAD0, 8);
264
+ if (buffer.length >= this.totalDataCount * 8) {
265
+ break;
266
+ }
267
+ buffer.put(QRCodeAlg.PAD1, 8);
268
+ }
269
+ return this.createBytes(buffer);
270
+ },
271
+ /**
272
+ * 纠错码编码
273
+ * @param {buffer} buffer 数据编码
274
+ * @return {[type]}
275
+ */
276
+ createBytes: function (buffer) {
277
+ var offset = 0;
278
+ var maxDcCount = 0;
279
+ var maxEcCount = 0;
280
+ var length = this.rsBlock.length / 3;
281
+ var rsBlocks = new Array();
282
+ for (var i = 0; i < length; i++) {
283
+ var count = this.rsBlock[i * 3 + 0];
284
+ var totalCount = this.rsBlock[i * 3 + 1];
285
+ var dataCount = this.rsBlock[i * 3 + 2];
286
+ for (var j = 0; j < count; j++) {
287
+ rsBlocks.push([dataCount, totalCount]);
288
+ }
289
+ }
290
+ var dcdata = new Array(rsBlocks.length);
291
+ var ecdata = new Array(rsBlocks.length);
292
+ for (var r = 0; r < rsBlocks.length; r++) {
293
+ var dcCount = rsBlocks[r][0];
294
+ var ecCount = rsBlocks[r][1] - dcCount;
295
+ maxDcCount = Math.max(maxDcCount, dcCount);
296
+ maxEcCount = Math.max(maxEcCount, ecCount);
297
+ dcdata[r] = new Array(dcCount);
298
+ for (var i = 0; i < dcdata[r].length; i++) {
299
+ dcdata[r][i] = 0xff & buffer.buffer[i + offset];
300
+ }
301
+ offset += dcCount;
302
+ var rsPoly = QRUtil.getErrorCorrectPolynomial(ecCount);
303
+ var rawPoly = new QRPolynomial(dcdata[r], rsPoly.getLength() - 1);
304
+ var modPoly = rawPoly.mod(rsPoly);
305
+ ecdata[r] = new Array(rsPoly.getLength() - 1);
306
+ for (var i = 0; i < ecdata[r].length; i++) {
307
+ var modIndex = i + modPoly.getLength() - ecdata[r].length;
308
+ ecdata[r][i] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
309
+ }
310
+ }
311
+ var data = new Array(this.totalDataCount);
312
+ var index = 0;
313
+ for (var i = 0; i < maxDcCount; i++) {
314
+ for (var r = 0; r < rsBlocks.length; r++) {
315
+ if (i < dcdata[r].length) {
316
+ data[index++] = dcdata[r][i];
317
+ }
318
+ }
319
+ }
320
+ for (var i = 0; i < maxEcCount; i++) {
321
+ for (var r = 0; r < rsBlocks.length; r++) {
322
+ if (i < ecdata[r].length) {
323
+ data[index++] = ecdata[r][i];
324
+ }
325
+ }
326
+ }
327
+ return data;
328
+ },
329
+ /**
330
+ * 布置模块,构建最终信息
331
+ * @param {} data
332
+ * @param {} maskPattern
333
+ * @return {}
334
+ */
335
+ mapData: function (data, maskPattern) {
336
+ var inc = -1;
337
+ var row = this.moduleCount - 1;
338
+ var bitIndex = 7;
339
+ var byteIndex = 0;
340
+ for (var col = this.moduleCount - 1; col > 0; col -= 2) {
341
+ if (col == 6) col--;
342
+ while (true) {
343
+ for (var c = 0; c < 2; c++) {
344
+ if (this.modules[row][col - c] == null) {
345
+ var dark = false;
346
+ if (byteIndex < data.length) {
347
+ dark = ((data[byteIndex] >>> bitIndex) & 1) == 1;
348
+ }
349
+ var mask = QRUtil.getMask(maskPattern, row, col - c);
350
+ if (mask) {
351
+ dark = !dark;
352
+ }
353
+ this.modules[row][col - c] = dark;
354
+ bitIndex--;
355
+ if (bitIndex == -1) {
356
+ byteIndex++;
357
+ bitIndex = 7;
358
+ }
359
+ }
360
+ }
361
+ row += inc;
362
+ if (row < 0 || this.moduleCount <= row) {
363
+ row -= inc;
364
+ inc = -inc;
365
+ break;
366
+ }
367
+ }
368
+ }
369
+ }
370
+ };
371
+ /**
372
+ * 填充字段
373
+ */
374
+ QRCodeAlg.PAD0 = 0xec;
375
+ QRCodeAlg.PAD1 = 0x11;
376
+ //---------------------------------------------------------------------
377
+ // 纠错等级对应的编码
378
+ //---------------------------------------------------------------------
379
+ var QRErrorCorrectLevel = [1, 0, 3, 2];
380
+ //---------------------------------------------------------------------
381
+ // 掩膜版本
382
+ //---------------------------------------------------------------------
383
+ var QRMaskPattern = {
384
+ PATTERN000: 0,
385
+ PATTERN001: 1,
386
+ PATTERN010: 2,
387
+ PATTERN011: 3,
388
+ PATTERN100: 4,
389
+ PATTERN101: 5,
390
+ PATTERN110: 6,
391
+ PATTERN111: 7
392
+ };
393
+ //---------------------------------------------------------------------
394
+ // 工具类
395
+ //---------------------------------------------------------------------
396
+ var QRUtil = {
397
+ /*
398
+ 每个版本矫正图形的位置
399
+ */
400
+ PATTERN_POSITION_TABLE: [
401
+ [],
402
+ [6, 18],
403
+ [6, 22],
404
+ [6, 26],
405
+ [6, 30],
406
+ [6, 34],
407
+ [6, 22, 38],
408
+ [6, 24, 42],
409
+ [6, 26, 46],
410
+ [6, 28, 50],
411
+ [6, 30, 54],
412
+ [6, 32, 58],
413
+ [6, 34, 62],
414
+ [6, 26, 46, 66],
415
+ [6, 26, 48, 70],
416
+ [6, 26, 50, 74],
417
+ [6, 30, 54, 78],
418
+ [6, 30, 56, 82],
419
+ [6, 30, 58, 86],
420
+ [6, 34, 62, 90],
421
+ [6, 28, 50, 72, 94],
422
+ [6, 26, 50, 74, 98],
423
+ [6, 30, 54, 78, 102],
424
+ [6, 28, 54, 80, 106],
425
+ [6, 32, 58, 84, 110],
426
+ [6, 30, 58, 86, 114],
427
+ [6, 34, 62, 90, 118],
428
+ [6, 26, 50, 74, 98, 122],
429
+ [6, 30, 54, 78, 102, 126],
430
+ [6, 26, 52, 78, 104, 130],
431
+ [6, 30, 56, 82, 108, 134],
432
+ [6, 34, 60, 86, 112, 138],
433
+ [6, 30, 58, 86, 114, 142],
434
+ [6, 34, 62, 90, 118, 146],
435
+ [6, 30, 54, 78, 102, 126, 150],
436
+ [6, 24, 50, 76, 102, 128, 154],
437
+ [6, 28, 54, 80, 106, 132, 158],
438
+ [6, 32, 58, 84, 110, 136, 162],
439
+ [6, 26, 54, 82, 110, 138, 166],
440
+ [6, 30, 58, 86, 114, 142, 170]
441
+ ],
442
+ G15:
443
+ (1 << 10) |
444
+ (1 << 8) |
445
+ (1 << 5) |
446
+ (1 << 4) |
447
+ (1 << 2) |
448
+ (1 << 1) |
449
+ (1 << 0),
450
+ G18:
451
+ (1 << 12) |
452
+ (1 << 11) |
453
+ (1 << 10) |
454
+ (1 << 9) |
455
+ (1 << 8) |
456
+ (1 << 5) |
457
+ (1 << 2) |
458
+ (1 << 0),
459
+ G15_MASK: (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1),
460
+ /*
461
+ BCH编码格式信息
462
+ */
463
+ getBCHTypeInfo: function (data) {
464
+ var d = data << 10;
465
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15) >= 0) {
466
+ d ^=
467
+ QRUtil.G15 <<
468
+ (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G15));
469
+ }
470
+ return ((data << 10) | d) ^ QRUtil.G15_MASK;
471
+ },
472
+ /*
473
+ BCH编码版本信息
474
+ */
475
+ getBCHTypeNumber: function (data) {
476
+ var d = data << 12;
477
+ while (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18) >= 0) {
478
+ d ^=
479
+ QRUtil.G18 <<
480
+ (QRUtil.getBCHDigit(d) - QRUtil.getBCHDigit(QRUtil.G18));
481
+ }
482
+ return (data << 12) | d;
483
+ },
484
+ /*
485
+ 获取BCH位信息
486
+ */
487
+ getBCHDigit: function (data) {
488
+ var digit = 0;
489
+ while (data != 0) {
490
+ digit++;
491
+ data >>>= 1;
492
+ }
493
+ return digit;
494
+ },
495
+ /*
496
+ 获取版本对应的矫正图形位置
497
+ */
498
+ getPatternPosition: function (typeNumber) {
499
+ return QRUtil.PATTERN_POSITION_TABLE[typeNumber - 1];
500
+ },
501
+ /*
502
+ 掩膜算法
503
+ */
504
+ getMask: function (maskPattern, i, j) {
505
+ switch (maskPattern) {
506
+ case QRMaskPattern.PATTERN000:
507
+ return (i + j) % 2 == 0;
508
+ case QRMaskPattern.PATTERN001:
509
+ return i % 2 == 0;
510
+ case QRMaskPattern.PATTERN010:
511
+ return j % 3 == 0;
512
+ case QRMaskPattern.PATTERN011:
513
+ return (i + j) % 3 == 0;
514
+ case QRMaskPattern.PATTERN100:
515
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 == 0;
516
+ case QRMaskPattern.PATTERN101:
517
+ return ((i * j) % 2) + ((i * j) % 3) == 0;
518
+ case QRMaskPattern.PATTERN110:
519
+ return (((i * j) % 2) + ((i * j) % 3)) % 2 == 0;
520
+ case QRMaskPattern.PATTERN111:
521
+ return (((i * j) % 3) + ((i + j) % 2)) % 2 == 0;
522
+ default:
523
+ throw new Error("bad maskPattern:" + maskPattern);
524
+ }
525
+ },
526
+ /*
527
+ 获取RS的纠错多项式
528
+ */
529
+ getErrorCorrectPolynomial: function (errorCorrectLength) {
530
+ var a = new QRPolynomial([1], 0);
531
+ for (var i = 0; i < errorCorrectLength; i++) {
532
+ a = a.multiply(new QRPolynomial([1, QRMath.gexp(i)], 0));
533
+ }
534
+ return a;
535
+ },
536
+ /*
537
+ 获取评价
538
+ */
539
+ getLostPoint: function (qrCode) {
540
+ var moduleCount = qrCode.getModuleCount(),
541
+ lostPoint = 0,
542
+ darkCount = 0;
543
+ for (var row = 0; row < moduleCount; row++) {
544
+ var sameCount = 0;
545
+ var head = qrCode.modules[row][0];
546
+ for (var col = 0; col < moduleCount; col++) {
547
+ var current = qrCode.modules[row][col];
548
+ //level 3 评价
549
+ if (col < moduleCount - 6) {
550
+ if (
551
+ current &&
552
+ !qrCode.modules[row][col + 1] &&
553
+ qrCode.modules[row][col + 2] &&
554
+ qrCode.modules[row][col + 3] &&
555
+ qrCode.modules[row][col + 4] &&
556
+ !qrCode.modules[row][col + 5] &&
557
+ qrCode.modules[row][col + 6]
558
+ ) {
559
+ if (col < moduleCount - 10) {
560
+ if (
561
+ qrCode.modules[row][col + 7] &&
562
+ qrCode.modules[row][col + 8] &&
563
+ qrCode.modules[row][col + 9] &&
564
+ qrCode.modules[row][col + 10]
565
+ ) {
566
+ lostPoint += 40;
567
+ }
568
+ } else if (col > 3) {
569
+ if (
570
+ qrCode.modules[row][col - 1] &&
571
+ qrCode.modules[row][col - 2] &&
572
+ qrCode.modules[row][col - 3] &&
573
+ qrCode.modules[row][col - 4]
574
+ ) {
575
+ lostPoint += 40;
576
+ }
577
+ }
578
+ }
579
+ }
580
+ //level 2 评价
581
+ if (row < moduleCount - 1 && col < moduleCount - 1) {
582
+ var count = 0;
583
+ if (current) count++;
584
+ if (qrCode.modules[row + 1][col]) count++;
585
+ if (qrCode.modules[row][col + 1]) count++;
586
+ if (qrCode.modules[row + 1][col + 1]) count++;
587
+ if (count == 0 || count == 4) {
588
+ lostPoint += 3;
589
+ }
590
+ }
591
+ //level 1 评价
592
+ if (head ^ current) {
593
+ sameCount++;
594
+ } else {
595
+ head = current;
596
+ if (sameCount >= 5) {
597
+ lostPoint += 3 + sameCount - 5;
598
+ }
599
+ sameCount = 1;
600
+ }
601
+ //level 4 评价
602
+ if (current) {
603
+ darkCount++;
604
+ }
605
+ }
606
+ }
607
+ for (var col = 0; col < moduleCount; col++) {
608
+ var sameCount = 0;
609
+ var head = qrCode.modules[0][col];
610
+ for (var row = 0; row < moduleCount; row++) {
611
+ var current = qrCode.modules[row][col];
612
+ //level 3 评价
613
+ if (row < moduleCount - 6) {
614
+ if (
615
+ current &&
616
+ !qrCode.modules[row + 1][col] &&
617
+ qrCode.modules[row + 2][col] &&
618
+ qrCode.modules[row + 3][col] &&
619
+ qrCode.modules[row + 4][col] &&
620
+ !qrCode.modules[row + 5][col] &&
621
+ qrCode.modules[row + 6][col]
622
+ ) {
623
+ if (row < moduleCount - 10) {
624
+ if (
625
+ qrCode.modules[row + 7][col] &&
626
+ qrCode.modules[row + 8][col] &&
627
+ qrCode.modules[row + 9][col] &&
628
+ qrCode.modules[row + 10][col]
629
+ ) {
630
+ lostPoint += 40;
631
+ }
632
+ } else if (row > 3) {
633
+ if (
634
+ qrCode.modules[row - 1][col] &&
635
+ qrCode.modules[row - 2][col] &&
636
+ qrCode.modules[row - 3][col] &&
637
+ qrCode.modules[row - 4][col]
638
+ ) {
639
+ lostPoint += 40;
640
+ }
641
+ }
642
+ }
643
+ }
644
+ //level 1 评价
645
+ if (head ^ current) {
646
+ sameCount++;
647
+ } else {
648
+ head = current;
649
+ if (sameCount >= 5) {
650
+ lostPoint += 3 + sameCount - 5;
651
+ }
652
+ sameCount = 1;
653
+ }
654
+ }
655
+ }
656
+ // LEVEL4
657
+ var ratio =
658
+ Math.abs((100 * darkCount) / moduleCount / moduleCount - 50) / 5;
659
+ lostPoint += ratio * 10;
660
+ return lostPoint;
661
+ }
662
+ };
663
+ //---------------------------------------------------------------------
664
+ // QRMath使用的数学工具
665
+ //---------------------------------------------------------------------
666
+ var QRMath = {
667
+ /*
668
+ 将n转化为a^m
669
+ */
670
+ glog: function (n) {
671
+ if (n < 1) {
672
+ throw new Error("glog(" + n + ")");
673
+ }
674
+ return QRMath.LOG_TABLE[n];
675
+ },
676
+ /*
677
+ 将a^m转化为n
678
+ */
679
+ gexp: function (n) {
680
+ while (n < 0) {
681
+ n += 255;
682
+ }
683
+ while (n >= 256) {
684
+ n -= 255;
685
+ }
686
+ return QRMath.EXP_TABLE[n];
687
+ },
688
+ EXP_TABLE: new Array(256),
689
+ LOG_TABLE: new Array(256)
690
+ };
691
+ for (var i = 0; i < 8; i++) {
692
+ QRMath.EXP_TABLE[i] = 1 << i;
693
+ }
694
+ for (var i = 8; i < 256; i++) {
695
+ QRMath.EXP_TABLE[i] =
696
+ QRMath.EXP_TABLE[i - 4] ^
697
+ QRMath.EXP_TABLE[i - 5] ^
698
+ QRMath.EXP_TABLE[i - 6] ^
699
+ QRMath.EXP_TABLE[i - 8];
700
+ }
701
+ for (var i = 0; i < 255; i++) {
702
+ QRMath.LOG_TABLE[QRMath.EXP_TABLE[i]] = i;
703
+ }
704
+ //---------------------------------------------------------------------
705
+ // QRPolynomial 多项式
706
+ //---------------------------------------------------------------------
707
+ /**
708
+ * 多项式类
709
+ * @param {Array} num 系数
710
+ * @param {num} shift a^shift
711
+ */
712
+ function QRPolynomial(num, shift) {
713
+ if (num.length == undefined) {
714
+ throw new Error(num.length + "/" + shift);
715
+ }
716
+ var offset = 0;
717
+ while (offset < num.length && num[offset] == 0) {
718
+ offset++;
719
+ }
720
+ this.num = new Array(num.length - offset + shift);
721
+ for (var i = 0; i < num.length - offset; i++) {
722
+ this.num[i] = num[i + offset];
723
+ }
724
+ }
725
+ QRPolynomial.prototype = {
726
+ get: function (index) {
727
+ return this.num[index];
728
+ },
729
+ getLength: function () {
730
+ return this.num.length;
731
+ },
732
+ /**
733
+ * 多项式乘法
734
+ * @param {QRPolynomial} e 被乘多项式
735
+ * @return {[type]} [description]
736
+ */
737
+ multiply: function (e) {
738
+ var num = new Array(this.getLength() + e.getLength() - 1);
739
+ for (var i = 0; i < this.getLength(); i++) {
740
+ for (var j = 0; j < e.getLength(); j++) {
741
+ num[i + j] ^= QRMath.gexp(
742
+ QRMath.glog(this.get(i)) + QRMath.glog(e.get(j))
743
+ );
744
+ }
745
+ }
746
+ return new QRPolynomial(num, 0);
747
+ },
748
+ /**
749
+ * 多项式模运算
750
+ * @param {QRPolynomial} e 模多项式
751
+ * @return {}
752
+ */
753
+ mod: function (e) {
754
+ var tl = this.getLength(),
755
+ el = e.getLength();
756
+ if (tl - el < 0) {
757
+ return this;
758
+ }
759
+ var num = new Array(tl);
760
+ for (var i = 0; i < tl; i++) {
761
+ num[i] = this.get(i);
762
+ }
763
+ while (num.length >= el) {
764
+ var ratio = QRMath.glog(num[0]) - QRMath.glog(e.get(0));
765
+
766
+ for (var i = 0; i < e.getLength(); i++) {
767
+ num[i] ^= QRMath.gexp(QRMath.glog(e.get(i)) + ratio);
768
+ }
769
+ while (num[0] == 0) {
770
+ num.shift();
771
+ }
772
+ }
773
+ return new QRPolynomial(num, 0);
774
+ }
775
+ };
776
+
777
+ //---------------------------------------------------------------------
778
+ // RS_BLOCK_TABLE
779
+ //---------------------------------------------------------------------
780
+ /*
781
+ 二维码各个版本信息[块数, 每块中的数据块数, 每块中的信息块数]
782
+ */
783
+ var RS_BLOCK_TABLE = [
784
+ // L
785
+ // M
786
+ // Q
787
+ // H
788
+ // 1
789
+ [1, 26, 19],
790
+ [1, 26, 16],
791
+ [1, 26, 13],
792
+ [1, 26, 9],
793
+
794
+ // 2
795
+ [1, 44, 34],
796
+ [1, 44, 28],
797
+ [1, 44, 22],
798
+ [1, 44, 16],
799
+
800
+ // 3
801
+ [1, 70, 55],
802
+ [1, 70, 44],
803
+ [2, 35, 17],
804
+ [2, 35, 13],
805
+
806
+ // 4
807
+ [1, 100, 80],
808
+ [2, 50, 32],
809
+ [2, 50, 24],
810
+ [4, 25, 9],
811
+
812
+ // 5
813
+ [1, 134, 108],
814
+ [2, 67, 43],
815
+ [2, 33, 15, 2, 34, 16],
816
+ [2, 33, 11, 2, 34, 12],
817
+
818
+ // 6
819
+ [2, 86, 68],
820
+ [4, 43, 27],
821
+ [4, 43, 19],
822
+ [4, 43, 15],
823
+
824
+ // 7
825
+ [2, 98, 78],
826
+ [4, 49, 31],
827
+ [2, 32, 14, 4, 33, 15],
828
+ [4, 39, 13, 1, 40, 14],
829
+
830
+ // 8
831
+ [2, 121, 97],
832
+ [2, 60, 38, 2, 61, 39],
833
+ [4, 40, 18, 2, 41, 19],
834
+ [4, 40, 14, 2, 41, 15],
835
+
836
+ // 9
837
+ [2, 146, 116],
838
+ [3, 58, 36, 2, 59, 37],
839
+ [4, 36, 16, 4, 37, 17],
840
+ [4, 36, 12, 4, 37, 13],
841
+
842
+ // 10
843
+ [2, 86, 68, 2, 87, 69],
844
+ [4, 69, 43, 1, 70, 44],
845
+ [6, 43, 19, 2, 44, 20],
846
+ [6, 43, 15, 2, 44, 16],
847
+
848
+ // 11
849
+ [4, 101, 81],
850
+ [1, 80, 50, 4, 81, 51],
851
+ [4, 50, 22, 4, 51, 23],
852
+ [3, 36, 12, 8, 37, 13],
853
+
854
+ // 12
855
+ [2, 116, 92, 2, 117, 93],
856
+ [6, 58, 36, 2, 59, 37],
857
+ [4, 46, 20, 6, 47, 21],
858
+ [7, 42, 14, 4, 43, 15],
859
+
860
+ // 13
861
+ [4, 133, 107],
862
+ [8, 59, 37, 1, 60, 38],
863
+ [8, 44, 20, 4, 45, 21],
864
+ [12, 33, 11, 4, 34, 12],
865
+
866
+ // 14
867
+ [3, 145, 115, 1, 146, 116],
868
+ [4, 64, 40, 5, 65, 41],
869
+ [11, 36, 16, 5, 37, 17],
870
+ [11, 36, 12, 5, 37, 13],
871
+
872
+ // 15
873
+ [5, 109, 87, 1, 110, 88],
874
+ [5, 65, 41, 5, 66, 42],
875
+ [5, 54, 24, 7, 55, 25],
876
+ [11, 36, 12],
877
+
878
+ // 16
879
+ [5, 122, 98, 1, 123, 99],
880
+ [7, 73, 45, 3, 74, 46],
881
+ [15, 43, 19, 2, 44, 20],
882
+ [3, 45, 15, 13, 46, 16],
883
+
884
+ // 17
885
+ [1, 135, 107, 5, 136, 108],
886
+ [10, 74, 46, 1, 75, 47],
887
+ [1, 50, 22, 15, 51, 23],
888
+ [2, 42, 14, 17, 43, 15],
889
+
890
+ // 18
891
+ [5, 150, 120, 1, 151, 121],
892
+ [9, 69, 43, 4, 70, 44],
893
+ [17, 50, 22, 1, 51, 23],
894
+ [2, 42, 14, 19, 43, 15],
895
+
896
+ // 19
897
+ [3, 141, 113, 4, 142, 114],
898
+ [3, 70, 44, 11, 71, 45],
899
+ [17, 47, 21, 4, 48, 22],
900
+ [9, 39, 13, 16, 40, 14],
901
+
902
+ // 20
903
+ [3, 135, 107, 5, 136, 108],
904
+ [3, 67, 41, 13, 68, 42],
905
+ [15, 54, 24, 5, 55, 25],
906
+ [15, 43, 15, 10, 44, 16],
907
+
908
+ // 21
909
+ [4, 144, 116, 4, 145, 117],
910
+ [17, 68, 42],
911
+ [17, 50, 22, 6, 51, 23],
912
+ [19, 46, 16, 6, 47, 17],
913
+
914
+ // 22
915
+ [2, 139, 111, 7, 140, 112],
916
+ [17, 74, 46],
917
+ [7, 54, 24, 16, 55, 25],
918
+ [34, 37, 13],
919
+
920
+ // 23
921
+ [4, 151, 121, 5, 152, 122],
922
+ [4, 75, 47, 14, 76, 48],
923
+ [11, 54, 24, 14, 55, 25],
924
+ [16, 45, 15, 14, 46, 16],
925
+
926
+ // 24
927
+ [6, 147, 117, 4, 148, 118],
928
+ [6, 73, 45, 14, 74, 46],
929
+ [11, 54, 24, 16, 55, 25],
930
+ [30, 46, 16, 2, 47, 17],
931
+
932
+ // 25
933
+ [8, 132, 106, 4, 133, 107],
934
+ [8, 75, 47, 13, 76, 48],
935
+ [7, 54, 24, 22, 55, 25],
936
+ [22, 45, 15, 13, 46, 16],
937
+
938
+ // 26
939
+ [10, 142, 114, 2, 143, 115],
940
+ [19, 74, 46, 4, 75, 47],
941
+ [28, 50, 22, 6, 51, 23],
942
+ [33, 46, 16, 4, 47, 17],
943
+
944
+ // 27
945
+ [8, 152, 122, 4, 153, 123],
946
+ [22, 73, 45, 3, 74, 46],
947
+ [8, 53, 23, 26, 54, 24],
948
+ [12, 45, 15, 28, 46, 16],
949
+
950
+ // 28
951
+ [3, 147, 117, 10, 148, 118],
952
+ [3, 73, 45, 23, 74, 46],
953
+ [4, 54, 24, 31, 55, 25],
954
+ [11, 45, 15, 31, 46, 16],
955
+
956
+ // 29
957
+ [7, 146, 116, 7, 147, 117],
958
+ [21, 73, 45, 7, 74, 46],
959
+ [1, 53, 23, 37, 54, 24],
960
+ [19, 45, 15, 26, 46, 16],
961
+
962
+ // 30
963
+ [5, 145, 115, 10, 146, 116],
964
+ [19, 75, 47, 10, 76, 48],
965
+ [15, 54, 24, 25, 55, 25],
966
+ [23, 45, 15, 25, 46, 16],
967
+
968
+ // 31
969
+ [13, 145, 115, 3, 146, 116],
970
+ [2, 74, 46, 29, 75, 47],
971
+ [42, 54, 24, 1, 55, 25],
972
+ [23, 45, 15, 28, 46, 16],
973
+
974
+ // 32
975
+ [17, 145, 115],
976
+ [10, 74, 46, 23, 75, 47],
977
+ [10, 54, 24, 35, 55, 25],
978
+ [19, 45, 15, 35, 46, 16],
979
+
980
+ // 33
981
+ [17, 145, 115, 1, 146, 116],
982
+ [14, 74, 46, 21, 75, 47],
983
+ [29, 54, 24, 19, 55, 25],
984
+ [11, 45, 15, 46, 46, 16],
985
+
986
+ // 34
987
+ [13, 145, 115, 6, 146, 116],
988
+ [14, 74, 46, 23, 75, 47],
989
+ [44, 54, 24, 7, 55, 25],
990
+ [59, 46, 16, 1, 47, 17],
991
+
992
+ // 35
993
+ [12, 151, 121, 7, 152, 122],
994
+ [12, 75, 47, 26, 76, 48],
995
+ [39, 54, 24, 14, 55, 25],
996
+ [22, 45, 15, 41, 46, 16],
997
+
998
+ // 36
999
+ [6, 151, 121, 14, 152, 122],
1000
+ [6, 75, 47, 34, 76, 48],
1001
+ [46, 54, 24, 10, 55, 25],
1002
+ [2, 45, 15, 64, 46, 16],
1003
+
1004
+ // 37
1005
+ [17, 152, 122, 4, 153, 123],
1006
+ [29, 74, 46, 14, 75, 47],
1007
+ [49, 54, 24, 10, 55, 25],
1008
+ [24, 45, 15, 46, 46, 16],
1009
+
1010
+ // 38
1011
+ [4, 152, 122, 18, 153, 123],
1012
+ [13, 74, 46, 32, 75, 47],
1013
+ [48, 54, 24, 14, 55, 25],
1014
+ [42, 45, 15, 32, 46, 16],
1015
+
1016
+ // 39
1017
+ [20, 147, 117, 4, 148, 118],
1018
+ [40, 75, 47, 7, 76, 48],
1019
+ [43, 54, 24, 22, 55, 25],
1020
+ [10, 45, 15, 67, 46, 16],
1021
+
1022
+ // 40
1023
+ [19, 148, 118, 6, 149, 119],
1024
+ [18, 75, 47, 31, 76, 48],
1025
+ [34, 54, 24, 34, 55, 25],
1026
+ [20, 45, 15, 61, 46, 16]
1027
+ ];
1028
+
1029
+ /**
1030
+ * 根据数据获取对应版本
1031
+ * @return {[type]} [description]
1032
+ */
1033
+ QRCodeAlg.prototype.getRightType = function () {
1034
+ for (var typeNumber = 1; typeNumber < 41; typeNumber++) {
1035
+ var rsBlock =
1036
+ RS_BLOCK_TABLE[(typeNumber - 1) * 4 + this.errorCorrectLevel];
1037
+ if (rsBlock == undefined) {
1038
+ throw new Error(
1039
+ "bad rs block @ typeNumber:" +
1040
+ typeNumber +
1041
+ "/errorCorrectLevel:" +
1042
+ this.errorCorrectLevel
1043
+ );
1044
+ }
1045
+ var length = rsBlock.length / 3;
1046
+ var totalDataCount = 0;
1047
+ for (var i = 0; i < length; i++) {
1048
+ var count = rsBlock[i * 3 + 0];
1049
+ var dataCount = rsBlock[i * 3 + 2];
1050
+ totalDataCount += dataCount * count;
1051
+ }
1052
+ var lengthBytes = typeNumber > 9 ? 2 : 1;
1053
+ if (
1054
+ this.utf8bytes.length + lengthBytes < totalDataCount ||
1055
+ typeNumber == 40
1056
+ ) {
1057
+ this.typeNumber = typeNumber;
1058
+ this.rsBlock = rsBlock;
1059
+ this.totalDataCount = totalDataCount;
1060
+ break;
1061
+ }
1062
+ }
1063
+ };
1064
+
1065
+ //---------------------------------------------------------------------
1066
+ // QRBitBuffer
1067
+ //---------------------------------------------------------------------
1068
+ function QRBitBuffer() {
1069
+ this.buffer = new Array();
1070
+ this.length = 0;
1071
+ }
1072
+ QRBitBuffer.prototype = {
1073
+ get: function (index) {
1074
+ var bufIndex = Math.floor(index / 8);
1075
+ return (this.buffer[bufIndex] >>> (7 - (index % 8))) & 1;
1076
+ },
1077
+ put: function (num, length) {
1078
+ for (var i = 0; i < length; i++) {
1079
+ this.putBit((num >>> (length - i - 1)) & 1);
1080
+ }
1081
+ },
1082
+ putBit: function (bit) {
1083
+ var bufIndex = Math.floor(this.length / 8);
1084
+ if (this.buffer.length <= bufIndex) {
1085
+ this.buffer.push(0);
1086
+ }
1087
+ if (bit) {
1088
+ this.buffer[bufIndex] |= 0x80 >>> this.length % 8;
1089
+ }
1090
+ this.length++;
1091
+ }
1092
+ };
1093
+
1094
+ // xzedit
1095
+ let qrcodeAlgObjCache = [];
1096
+ /**
1097
+ * 二维码构造函数,主要用于绘制
1098
+ * @param {参数列表} opt 传递参数
1099
+ * @return {}
1100
+ */
1101
+ QRCode = function (opt) {
1102
+ //设置默认参数
1103
+ this.options = {
1104
+ text: "",
1105
+ size: 256,
1106
+ correctLevel: 3,
1107
+ background: "#ffffff",
1108
+ foreground: "#000000",
1109
+ pdground: "#000000",
1110
+ image: "",
1111
+ imageSize: 30,
1112
+ canvasId: opt.canvasId,
1113
+ nvueContext: opt.nvueContext,
1114
+ context: opt.context,
1115
+ usingComponents: opt.usingComponents,
1116
+ showLoading: opt.showLoading,
1117
+ loadingText: opt.loadingText
1118
+ };
1119
+ if (typeof opt === "string") {
1120
+ // 只编码ASCII字符串
1121
+ opt = {
1122
+ text: opt
1123
+ };
1124
+ }
1125
+ if (opt) {
1126
+ for (var i in opt) {
1127
+ this.options[i] = opt[i];
1128
+ }
1129
+ }
1130
+ //使用QRCodeAlg创建二维码结构
1131
+ var qrCodeAlg = null;
1132
+ for (var i = 0, l = qrcodeAlgObjCache.length; i < l; i++) {
1133
+ if (
1134
+ qrcodeAlgObjCache[i].text == this.options.text &&
1135
+ qrcodeAlgObjCache[i].text.correctLevel == this.options.correctLevel
1136
+ ) {
1137
+ qrCodeAlg = qrcodeAlgObjCache[i].obj;
1138
+ break;
1139
+ }
1140
+ }
1141
+ if (i == l) {
1142
+ qrCodeAlg = new QRCodeAlg(this.options.text, this.options.correctLevel);
1143
+ qrcodeAlgObjCache.push({
1144
+ text: this.options.text,
1145
+ correctLevel: this.options.correctLevel,
1146
+ obj: qrCodeAlg
1147
+ });
1148
+ }
1149
+ /**
1150
+ * 计算矩阵点的前景色
1151
+ * @param {Obj} config
1152
+ * @param {Number} config.row 点x坐标
1153
+ * @param {Number} config.col 点y坐标
1154
+ * @param {Number} config.count 矩阵大小
1155
+ * @param {Number} config.options 组件的options
1156
+ * @return {String}
1157
+ */
1158
+ let getForeGround = function (config) {
1159
+ var options = config.options;
1160
+ if (
1161
+ options.pdground &&
1162
+ ((config.row > 1 &&
1163
+ config.row < 5 &&
1164
+ config.col > 1 &&
1165
+ config.col < 5) ||
1166
+ (config.row > config.count - 6 &&
1167
+ config.row < config.count - 2 &&
1168
+ config.col > 1 &&
1169
+ config.col < 5) ||
1170
+ (config.row > 1 &&
1171
+ config.row < 5 &&
1172
+ config.col > config.count - 6 &&
1173
+ config.col < config.count - 2))
1174
+ ) {
1175
+ return options.pdground;
1176
+ }
1177
+ return options.foreground;
1178
+ };
1179
+ // 创建canvas
1180
+ let createCanvas = function (options) {
1181
+ if (options.showLoading) {
1182
+ uni.showLoading({
1183
+ title: options.loadingText,
1184
+ mask: true
1185
+ });
1186
+ }
1187
+ var ctx = "";
1188
+ if (options.nvueContext) {
1189
+ ctx = options.nvueContext;
1190
+ } else {
1191
+ ctx = uni.createCanvasContext(options.canvasId, options.context);
1192
+ }
1193
+ var count = qrCodeAlg.getModuleCount();
1194
+ var ratioSize = options.size;
1195
+ var ratioImgSize = options.imageSize;
1196
+ //计算每个点的长宽
1197
+ var tileW = (ratioSize / count).toPrecision(4);
1198
+ var tileH = (ratioSize / count).toPrecision(4);
1199
+ //绘制
1200
+ for (var row = 0; row < count; row++) {
1201
+ for (var col = 0; col < count; col++) {
1202
+ var w = Math.ceil((col + 1) * tileW) - Math.floor(col * tileW);
1203
+ var h = Math.ceil((row + 1) * tileW) - Math.floor(row * tileW);
1204
+ var foreground = getForeGround({
1205
+ row: row,
1206
+ col: col,
1207
+ count: count,
1208
+ options: options
1209
+ });
1210
+ ctx.setFillStyle(
1211
+ qrCodeAlg.modules[row][col] ? foreground : options.background
1212
+ );
1213
+ ctx.fillRect(Math.round(col * tileW), Math.round(row * tileH), w, h);
1214
+ }
1215
+ }
1216
+ if (options.image) {
1217
+ var x = Number(((ratioSize - ratioImgSize) / 2).toFixed(2));
1218
+ var y = Number(((ratioSize - ratioImgSize) / 2).toFixed(2));
1219
+ drawRoundedRect(
1220
+ ctx,
1221
+ x,
1222
+ y,
1223
+ ratioImgSize,
1224
+ ratioImgSize,
1225
+ 2,
1226
+ 6,
1227
+ true,
1228
+ true
1229
+ );
1230
+ ctx.drawImage(options.image, x, y, ratioImgSize, ratioImgSize);
1231
+ // 画圆角矩形
1232
+ function drawRoundedRect(
1233
+ ctxi,
1234
+ x,
1235
+ y,
1236
+ width,
1237
+ height,
1238
+ r,
1239
+ lineWidth,
1240
+ fill,
1241
+ stroke
1242
+ ) {
1243
+ ctxi.setLineWidth(lineWidth);
1244
+ ctxi.setFillStyle(options.background);
1245
+ ctxi.setStrokeStyle(options.background);
1246
+ ctxi.beginPath(); // draw top and top right corner
1247
+ ctxi.moveTo(x + r, y);
1248
+ ctxi.arcTo(x + width, y, x + width, y + r, r); // draw right side and bottom right corner
1249
+ ctxi.arcTo(x + width, y + height, x + width - r, y + height, r); // draw bottom and bottom left corner
1250
+ ctxi.arcTo(x, y + height, x, y + height - r, r); // draw left and top left corner
1251
+ ctxi.arcTo(x, y, x + r, y, r);
1252
+ ctxi.closePath();
1253
+ if (fill) {
1254
+ ctxi.fill();
1255
+ }
1256
+ if (stroke) {
1257
+ ctxi.stroke();
1258
+ }
1259
+ }
1260
+ }
1261
+ setTimeout(
1262
+ () => {
1263
+ ctx.draw(true, () => {
1264
+ // 保存到临时区域
1265
+ setTimeout(() => {
1266
+ if (options.nvueContext) {
1267
+ ctx.toTempFilePath(
1268
+ 0,
1269
+ 0,
1270
+ options.width,
1271
+ options.height,
1272
+ options.width,
1273
+ options.height,
1274
+ "",
1275
+ 1,
1276
+ function (res) {
1277
+ if (options.cbResult) {
1278
+ options.cbResult(res.tempFilePath);
1279
+ }
1280
+ }
1281
+ );
1282
+ } else {
1283
+ uni.canvasToTempFilePath(
1284
+ {
1285
+ width: options.width,
1286
+ height: options.height,
1287
+ destWidth: options.width,
1288
+ destHeight: options.height,
1289
+ canvasId: options.canvasId,
1290
+ quality: Number(1),
1291
+ success: function (res) {
1292
+ if (options.cbResult) {
1293
+ // 由于官方还没有统一此接口的输出字段,所以先判定下 支付宝为 res.apFilePath
1294
+ if (!empty(res.tempFilePath)) {
1295
+ options.cbResult(res.tempFilePath);
1296
+ } else if (!empty(res.apFilePath)) {
1297
+ options.cbResult(res.apFilePath);
1298
+ } else {
1299
+ options.cbResult(res.tempFilePath);
1300
+ }
1301
+ }
1302
+ },
1303
+ fail: function (res) {
1304
+ if (options.cbResult) {
1305
+ options.cbResult(res);
1306
+ }
1307
+ },
1308
+ complete: function () {
1309
+ uni.hideLoading();
1310
+ }
1311
+ },
1312
+ options.context
1313
+ );
1314
+ }
1315
+ }, options.text.length + 100);
1316
+ });
1317
+ },
1318
+ options.usingComponents ? 0 : 150
1319
+ );
1320
+ };
1321
+ createCanvas(this.options);
1322
+ // 空判定
1323
+ let empty = function (v) {
1324
+ let tp = typeof v,
1325
+ rt = false;
1326
+ if (tp == "number" && String(v) == "") {
1327
+ rt = true;
1328
+ } else if (tp == "undefined") {
1329
+ rt = true;
1330
+ } else if (tp == "object") {
1331
+ if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null)
1332
+ rt = true;
1333
+ } else if (tp == "string") {
1334
+ if (
1335
+ v == "" ||
1336
+ v == "undefined" ||
1337
+ v == "null" ||
1338
+ v == "{}" ||
1339
+ v == "[]"
1340
+ )
1341
+ rt = true;
1342
+ } else if (tp == "function") {
1343
+ rt = false;
1344
+ }
1345
+ return rt;
1346
+ };
1347
+ };
1348
+ QRCode.prototype.clear = function (fn) {
1349
+ var ctx = "";
1350
+ if (options.nvueContext) {
1351
+ ctx = options.nvueContext;
1352
+ } else {
1353
+ uni.createCanvasContext(this.options.canvasId, this.options.context);
1354
+ }
1355
+ ctx.clearRect(0, 0, this.options.size, this.options.size);
1356
+ ctx.draw(false, () => {
1357
+ if (fn) {
1358
+ fn();
1359
+ }
1360
+ });
1361
+ };
1362
+ })();
1363
+
1364
+ export default QRCode;