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.
@@ -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
  }
@@ -63,24 +63,52 @@ function chooseBestMode ({ mode, content, charset }) {
63
63
  }
64
64
  }
65
65
 
66
- export default function (data) {
67
- const { level, version } = data;
68
-
69
- const encoder = new Encoder({
70
- level,
71
- version,
72
- hints: getHints(data),
73
- });
74
-
75
- try {
76
- const qrcode = encoder.encode(chooseBestMode(data));
77
- const { moduleSize, quietZone, background, foreground } = data;
78
- return qrcode.toDataURL(moduleSize, {
79
- margin: quietZone,
80
- background: hex2rgb(background),
81
- foreground: hex2rgb(foreground),
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
- } catch (error) {
84
- return "";
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yh-hiprint",
3
- "version": "2.6.12",
3
+ "version": "2.6.13",
4
4
  "description": "Hiprint for Vue3 by NoahLiu in ForceCon in Hunan Changesha",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",