yh-hiprint 2.6.12 → 2.6.13
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.
- package/libs/hiprint.bundle.js +1 -0
- package/libs/plugins/qrcode.js +46 -18
- package/package.json +1 -1
package/libs/hiprint.bundle.js
CHANGED
|
@@ -11114,6 +11114,7 @@ var hiprint = (function (t) {
|
|
|
11114
11114
|
colorDark: this.options.color || '#000000',
|
|
11115
11115
|
useSVG: !0,
|
|
11116
11116
|
correctLevel: this.options.getQRcodeLevel(),
|
|
11117
|
+
mode: 4,
|
|
11117
11118
|
}).makeCode(n);
|
|
11118
11119
|
(a.html(box), !this.options.hideTitle && a.append(`<div class="hiqrcode_displayValue" style="white-space:nowrap">${n}</div>`));
|
|
11119
11120
|
}
|
package/libs/plugins/qrcode.js
CHANGED
|
@@ -63,24 +63,52 @@ function chooseBestMode ({ mode, content, charset }) {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
export default
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
export default class QRCode {
|
|
67
|
+
constructor (dom, options) {
|
|
68
|
+
this.dom = dom;
|
|
69
|
+
this.options = options;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
makeCode (content) {
|
|
73
|
+
const { colorDark = '#000000', useSVG, correctLevel, mode = 4 } = this.options;
|
|
74
|
+
|
|
75
|
+
const data = {
|
|
76
|
+
level: correctLevel,
|
|
77
|
+
version: undefined,
|
|
78
|
+
content,
|
|
79
|
+
mode,
|
|
80
|
+
charset: 'UTF-8',
|
|
81
|
+
moduleSize: 2,
|
|
82
|
+
quietZone: 1,
|
|
83
|
+
background: '#FFFFFF',
|
|
84
|
+
foreground: colorDark
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const encoder = new Encoder({
|
|
88
|
+
level: data.level,
|
|
89
|
+
version: data.version,
|
|
90
|
+
hints: getHints(data),
|
|
82
91
|
});
|
|
83
|
-
|
|
84
|
-
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const qrcode = encoder.encode(chooseBestMode(data));
|
|
95
|
+
const { moduleSize, quietZone, background, foreground } = data;
|
|
96
|
+
const dataURL = qrcode.toDataURL(moduleSize, {
|
|
97
|
+
margin: quietZone,
|
|
98
|
+
background: hex2rgb(background),
|
|
99
|
+
foreground: hex2rgb(foreground),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// 渲染二维码到DOM
|
|
103
|
+
const img = document.createElement('img');
|
|
104
|
+
img.src = dataURL;
|
|
105
|
+
img.style.width = '100%';
|
|
106
|
+
img.style.height = '100%';
|
|
107
|
+
this.dom.innerHTML = '';
|
|
108
|
+
this.dom.appendChild(img);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
console.error('QRCode generation error:', error);
|
|
111
|
+
this.dom.innerHTML = '二维码生成失败';
|
|
112
|
+
}
|
|
85
113
|
}
|
|
86
114
|
}
|