nv-img-barcode-bw 1.0.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.
@@ -0,0 +1,5 @@
1
+ //const js_str = require("fs").readFileSync(require("path").join(__dirname,"../DIST/nv-img-barcode-bw.js")).toString();
2
+ //const jb = require("fs").readFileSync(require("path").join(__dirname,"../DEPS/jsbarcode.min.js")).toString();
3
+ //const hc = require("fs").readFileSync(require("path").join(__dirname,"../DEPS/html2canvas.min.js")).toString();
4
+ //const qg = require("fs").readFileSync(require("path").join(__dirname,"../DEPS/quagga.min.js")).toString();
5
+ //require("fs").writeFileSync(require("path").join(__dirname,"../DIST/nv-img-barcode-bw.js"),`${hc}\n${jb}\n${qg}\n${js_str}\n`);
@@ -0,0 +1,13 @@
1
+ {
2
+ const html_tmpl = require("fs").readFileSync(require("path").join(__dirname,"./index.tmpl.html")).toString();
3
+ const js_str = require("fs").readFileSync(require("path").join(__dirname,"../DIST/nv-img-barcode-bw.js")).toString();
4
+ const html = html_tmpl.replace(/@SCRIPT@/g,js_str);
5
+ require("fs").writeFileSync(require("path").join(__dirname,"../TEST/index.html"),html);
6
+ }
7
+
8
+ {
9
+ const html_tmpl = require("fs").readFileSync(require("path").join(__dirname,"./api.tmpl.html")).toString();
10
+ const js_str = require("fs").readFileSync(require("path").join(__dirname,"../DIST/nv-img-barcode-bw.js")).toString();
11
+ const html = html_tmpl.replace(/@SCRIPT@/g,js_str);
12
+ require("fs").writeFileSync(require("path").join(__dirname,"../TEST/api.html"),html);
13
+ }
@@ -0,0 +1,481 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>BarcodeButton 测试页面</title>
7
+ <style>
8
+ * {
9
+ margin: 0;
10
+ padding: 0;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ body {
15
+ font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
16
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
17
+ min-height: 100vh;
18
+ padding: 20px;
19
+ }
20
+
21
+ .container {
22
+ max-width: 800px;
23
+ margin: 0 auto;
24
+ background: white;
25
+ padding: 40px;
26
+ border-radius: 20px;
27
+ box-shadow: 0 20px 60px rgba(0,0,0,0.3);
28
+ }
29
+
30
+ header {
31
+ text-align: center;
32
+ margin-bottom: 40px;
33
+ }
34
+
35
+ h1 {
36
+ color: #333;
37
+ font-size: 2.5rem;
38
+ margin-bottom: 10px;
39
+ }
40
+
41
+ .subtitle {
42
+ color: #666;
43
+ font-size: 1.1rem;
44
+ }
45
+
46
+ .input-form {
47
+ background: #f8f9fa;
48
+ padding: 30px;
49
+ border-radius: 12px;
50
+ margin-bottom: 30px;
51
+ }
52
+
53
+ .form-title {
54
+ color: #4a5568;
55
+ margin-bottom: 20px;
56
+ font-size: 1.4rem;
57
+ }
58
+
59
+ .form-group {
60
+ margin-bottom: 20px;
61
+ }
62
+
63
+ .form-group label {
64
+ display: block;
65
+ margin-bottom: 8px;
66
+ font-weight: 600;
67
+ color: #4a5568;
68
+ }
69
+
70
+ .form-control {
71
+ width: 100%;
72
+ padding: 12px;
73
+ border: 2px solid #e2e8f0;
74
+ border-radius: 8px;
75
+ font-size: 16px;
76
+ box-sizing: border-box;
77
+ }
78
+
79
+ .form-control:focus {
80
+ outline: none;
81
+ border-color: #667eea;
82
+ }
83
+
84
+ .form-row {
85
+ display: grid;
86
+ grid-template-columns: 1fr 1fr;
87
+ gap: 20px;
88
+ }
89
+
90
+ .color-input-wrapper {
91
+ display: flex;
92
+ align-items: center;
93
+ gap: 10px;
94
+ }
95
+
96
+ .color-input {
97
+ width: 60px;
98
+ height: 50px;
99
+ padding: 0;
100
+ border: 2px solid #e2e8f0;
101
+ border-radius: 8px;
102
+ cursor: pointer;
103
+ }
104
+
105
+ .color-value {
106
+ flex: 1;
107
+ padding: 12px;
108
+ background: white;
109
+ border: 2px solid #e2e8f0;
110
+ border-radius: 8px;
111
+ font-family: 'Courier New', monospace;
112
+ }
113
+
114
+ .generate-btn {
115
+ width: 100%;
116
+ padding: 15px;
117
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
118
+ color: white;
119
+ border: none;
120
+ border-radius: 8px;
121
+ font-size: 18px;
122
+ font-weight: 600;
123
+ cursor: pointer;
124
+ margin-top: 10px;
125
+ transition: all 0.3s;
126
+ }
127
+
128
+ .generate-btn:hover {
129
+ transform: translateY(-2px);
130
+ box-shadow: 0 5px 15px rgba(0,0,0,0.2);
131
+ }
132
+
133
+ .preview-section {
134
+ background: #f8f9fa;
135
+ padding: 30px;
136
+ border-radius: 12px;
137
+ }
138
+
139
+ .preview-title {
140
+ color: #4a5568;
141
+ margin-bottom: 20px;
142
+ font-size: 1.4rem;
143
+ }
144
+
145
+ .preview-grid {
146
+ display: grid;
147
+ grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
148
+ gap: 20px;
149
+ margin-top: 20px;
150
+ }
151
+
152
+ .preview-item {
153
+ text-align: center;
154
+ }
155
+
156
+ .preview-label {
157
+ font-weight: 600;
158
+ color: #4a5568;
159
+ margin-bottom: 10px;
160
+ }
161
+
162
+ .examples-section {
163
+ margin-top: 40px;
164
+ }
165
+
166
+ .examples-title {
167
+ color: #4a5568;
168
+ margin-bottom: 20px;
169
+ font-size: 1.4rem;
170
+ }
171
+
172
+ .examples-grid {
173
+ display: grid;
174
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
175
+ gap: 20px;
176
+ }
177
+
178
+ .example-item {
179
+ background: #f8f9fa;
180
+ padding: 20px;
181
+ border-radius: 8px;
182
+ cursor: pointer;
183
+ transition: all 0.3s;
184
+ }
185
+
186
+ .example-item:hover {
187
+ transform: translateY(-3px);
188
+ box-shadow: 0 5px 15px rgba(0,0,0,0.1);
189
+ }
190
+
191
+ .example-content {
192
+ font-weight: 600;
193
+ margin-bottom: 10px;
194
+ }
195
+
196
+ .example-description {
197
+ color: #718096;
198
+ font-size: 14px;
199
+ }
200
+
201
+ .dynamic-barcode {
202
+ margin-top: 30px;
203
+ }
204
+
205
+ .alert {
206
+ position: fixed;
207
+ top: 20px;
208
+ right: 20px;
209
+ padding: 12px 20px;
210
+ border-radius: 8px;
211
+ background: #38a169;
212
+ color: white;
213
+ font-weight: 500;
214
+ box-shadow: 0 4px 12px rgba(0,0,0,0.15);
215
+ z-index: 1000;
216
+ display: none;
217
+ }
218
+
219
+ .alert.show {
220
+ display: block;
221
+ animation: slideIn 0.3s ease;
222
+ }
223
+
224
+ @keyframes slideIn {
225
+ from { transform: translateX(100%); opacity: 0; }
226
+ to { transform: translateX(0); opacity: 1; }
227
+ }
228
+
229
+ footer {
230
+ text-align: center;
231
+ margin-top: 40px;
232
+ padding-top: 20px;
233
+ border-top: 1px solid #e2e8f0;
234
+ color: #718096;
235
+ }
236
+ </style>
237
+ </head>
238
+ <body>
239
+ <div class="container">
240
+ <header>
241
+ <h1>📊 BarcodeButton 测试页面</h1>
242
+ <p class="subtitle">在下方输入条形码信息,点击生成按钮查看效果</p>
243
+ </header>
244
+
245
+ <div class="input-form">
246
+ <h2 class="form-title">🔧 自定义条形码生成</h2>
247
+
248
+ <div class="form-group">
249
+ <label for="barcode-input">条形码内容:</label>
250
+ <input type="text" id="barcode-input" class="form-control"
251
+ placeholder="输入条形码内容(支持中文、英文、数字)"
252
+ value="123456789012">
253
+ </div>
254
+
255
+ <div class="form-row">
256
+ <div class="form-group">
257
+ <label for="format-select">编码格式:</label>
258
+ <select id="format-select" class="form-control">
259
+ <option value="CODE128" selected>CODE128(通用格式)</option>
260
+ <option value="EAN13">EAN13(商品条码)</option>
261
+ <option value="EAN8">EAN8</option>
262
+ <option value="UPC">UPC(北美商品码)</option>
263
+ <option value="CODE39">CODE39</option>
264
+ <option value="ITF14">ITF14(物流包装)</option>
265
+ <option value="MSI">MSI(库存管理)</option>
266
+ <option value="pharmacode">Pharmacode(药品码)</option>
267
+ </select>
268
+ </div>
269
+
270
+ <div class="form-group">
271
+ <label for="color-input">线条颜色:</label>
272
+ <div class="color-input-wrapper">
273
+ <input type="color" id="color-input" class="color-input" value="#000000">
274
+ <input type="text" id="color-value" class="color-value" value="#000000">
275
+ </div>
276
+ </div>
277
+ </div>
278
+
279
+ <button class="generate-btn" id="generate-btn">
280
+ 🎯 生成条形码
281
+ </button>
282
+ </div>
283
+
284
+ <div class="preview-section">
285
+ <h2 class="preview-title">🔍 条形码预览</h2>
286
+ <div id="barcode-preview"></div>
287
+ </div>
288
+
289
+ <div class="dynamic-barcode">
290
+ <h2 class="preview-title">📦 动态生成的条形码</h2>
291
+ <p style="color: #666; margin-bottom: 20px;">以下是通过JavaScript动态创建的条形码按钮:</p>
292
+ <div id="dynamic-barcodes"></div>
293
+ </div>
294
+
295
+ <div class="examples-section">
296
+ <h2 class="examples-title">🎯 示例条形码</h2>
297
+ <p style="color: #666; margin-bottom: 20px;">点击下方示例快速生成条形码:</p>
298
+
299
+ <div class="examples-grid">
300
+ <div class="example-item" data-code="123456789012" data-format="EAN13" data-color="#e53e3e">
301
+ <div class="example-content">123456789012</div>
302
+ <div class="example-description">EAN13 商品条码</div>
303
+ </div>
304
+
305
+ <div class="example-item" data-code="PRODUCT-2024-001" data-format="CODE128" data-color="#38a169">
306
+ <div class="example-content">PRODUCT-2024-001</div>
307
+ <div class="example-description">产品编码</div>
308
+ </div>
309
+
310
+ <div class="example-item" data-code="微信扫码测试" data-format="CODE128" data-color="#805ad5">
311
+ <div class="example-content">微信扫码测试</div>
312
+ <div class="example-description">中文内容</div>
313
+ </div>
314
+
315
+ <div class="example-item" data-code="ORDER-789-ABC" data-format="CODE39" data-color="#d69e2e">
316
+ <div class="example-content">ORDER-789-ABC</div>
317
+ <div class="example-description">订单编码</div>
318
+ </div>
319
+ </div>
320
+ </div>
321
+
322
+ <footer>
323
+ <p>BarcodeButton 组件测试页面 | 点击生成按钮查看条形码弹窗,支持PNG/SVG下载</p>
324
+ </footer>
325
+ </div>
326
+
327
+ <div class="alert" id="alert"></div>
328
+
329
+ <script>
330
+ // 动态创建BarcodeButton组件
331
+ class DynamicBarcodeButton extends HTMLElement {
332
+ constructor(code, format, lineColor, text, bgColor) {
333
+ super();
334
+ this.code = code;
335
+ this.format = format;
336
+ this.lineColor = lineColor;
337
+ this.text = text;
338
+ this.bgColor = bgColor;
339
+ }
340
+
341
+ connectedCallback() {
342
+ this.innerHTML = `
343
+ <nv-barcode-button
344
+ code="${this.code}"
345
+ format="${this.format}"
346
+ line-color="${this.lineColor}"
347
+ text="${this.text}"
348
+ bg-color="${this.bgColor}"
349
+ ></nv-barcode-button>
350
+ `;
351
+ }
352
+ }
353
+ customElements.define('dynamic-barcode', DynamicBarcodeButton);
354
+ </script>
355
+
356
+ <!-- 引入BarcodeButton组件 -->
357
+ <script>@SCRIPT@</script>
358
+
359
+ <script>
360
+ document.addEventListener('DOMContentLoaded', function() {
361
+ // DOM元素
362
+ const barcodeInput = document.getElementById('barcode-input');
363
+ const formatSelect = document.getElementById('format-select');
364
+ const colorInput = document.getElementById('color-input');
365
+ const colorValue = document.getElementById('color-value');
366
+ const generateBtn = document.getElementById('generate-btn');
367
+ const barcodePreview = document.getElementById('barcode-preview');
368
+ const dynamicBarcodes = document.getElementById('dynamic-barcodes');
369
+ const alertDiv = document.getElementById('alert');
370
+ const exampleItems = document.querySelectorAll('.example-item');
371
+
372
+ // 显示提示
373
+ function showAlert(message, type = 'success') {
374
+ const colors = {
375
+ success: '#38a169',
376
+ error: '#e53e3e',
377
+ warning: '#d69e2e',
378
+ info: '#667eea'
379
+ };
380
+
381
+ alertDiv.textContent = message;
382
+ alertDiv.style.background = colors[type] || colors.success;
383
+ alertDiv.classList.add('show');
384
+
385
+ setTimeout(() => {
386
+ alertDiv.classList.remove('show');
387
+ }, 3000);
388
+ }
389
+
390
+ // 颜色选择器同步
391
+ colorInput.addEventListener('input', function() {
392
+ colorValue.value = this.value;
393
+ });
394
+
395
+ colorValue.addEventListener('input', function() {
396
+ const value = this.value;
397
+ if (value.match(/^#[0-9A-F]{6}$/i)) {
398
+ colorInput.value = value;
399
+ }
400
+ });
401
+
402
+ // 生成条形码
403
+ generateBtn.addEventListener('click', function() {
404
+ const code = barcodeInput.value.trim();
405
+ const format = formatSelect.value;
406
+ const lineColor = colorInput.value;
407
+
408
+ if (!code) {
409
+ showAlert('请输入条形码内容', 'error');
410
+ return;
411
+ }
412
+
413
+ // 移除之前的预览
414
+ barcodePreview.innerHTML = '';
415
+
416
+ // 创建新的条形码按钮
417
+ const barcodeBtn = document.createElement('nv-barcode-button');
418
+ barcodeBtn.setAttribute('code', code);
419
+ barcodeBtn.setAttribute('format', format);
420
+ barcodeBtn.setAttribute('line-color', lineColor);
421
+ barcodeBtn.setAttribute('text', '查看条形码');
422
+ barcodeBtn.setAttribute('bg-color', 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)');
423
+ barcodeBtn.setAttribute('width', '2');
424
+ barcodeBtn.setAttribute('height', '100');
425
+ barcodeBtn.setAttribute('background-color', '#ffffff');
426
+ barcodeBtn.setAttribute('show-text', 'true');
427
+ barcodeBtn.setAttribute('font-size', '20');
428
+ barcodeBtn.setAttribute('margin', '10');
429
+
430
+ barcodePreview.appendChild(barcodeBtn);
431
+
432
+ showAlert('已生成条形码按钮,点击"查看条形码"预览');
433
+ });
434
+
435
+ // 示例点击
436
+ exampleItems.forEach(item => {
437
+ item.addEventListener('click', function() {
438
+ const code = this.dataset.code;
439
+ const format = this.dataset.format;
440
+ const color = this.dataset.color;
441
+
442
+ barcodeInput.value = code;
443
+ formatSelect.value = format;
444
+ colorInput.value = color;
445
+ colorValue.value = color;
446
+
447
+ // 自动触发生成
448
+ generateBtn.click();
449
+ });
450
+ });
451
+
452
+ // 动态创建一些示例条形码
453
+ const dynamicExamples = [
454
+ { code: 'TEST-001', format: 'CODE128', color: '#e53e3e', text: '测试1', bgColor: 'linear-gradient(135deg, #e53e3e 0%, #c53030 100%)' },
455
+ { code: '4567890123', format: 'EAN8', color: '#38a169', text: '测试2', bgColor: 'linear-gradient(135deg, #38a169 0%, #276749 100%)' },
456
+ { code: 'ABC123XYZ', format: 'CODE39', color: '#805ad5', text: '测试3', bgColor: 'linear-gradient(135deg, #805ad5 0%, #6b46c1 100%)' },
457
+ { code: 'HELLO-WORLD', format: 'CODE128', color: '#d69e2e', text: '测试4', bgColor: 'linear-gradient(135deg, #d69e2e 0%, #b7791f 100%)' }
458
+ ];
459
+
460
+ dynamicExamples.forEach(example => {
461
+ const dynamicBtn = document.createElement('dynamic-barcode');
462
+ dynamicBtn.code = example.code;
463
+ dynamicBtn.format = example.format;
464
+ dynamicBtn.lineColor = example.color;
465
+ dynamicBtn.text = example.text;
466
+ dynamicBtn.bgColor = example.bgColor;
467
+ dynamicBarcodes.appendChild(dynamicBtn);
468
+
469
+ // 添加一些间距
470
+ const br = document.createElement('br');
471
+ dynamicBarcodes.appendChild(br);
472
+ });
473
+
474
+ // 初始生成一个示例
475
+ setTimeout(() => {
476
+ generateBtn.click();
477
+ }, 500);
478
+ });
479
+ </script>
480
+ </body>
481
+ </html>
package/cfg.js ADDED
@@ -0,0 +1,56 @@
1
+
2
+ const init = require("nv-facutil-def-bw-attr");
3
+
4
+ ////
5
+
6
+ const ACTIONS = {};
7
+ const ATTRS = {
8
+ 'jsbarcode-src':{
9
+ type:"str",
10
+ dflt:"https://cdn.jsdelivr.net/npm/jsbarcode@3.11.5/dist/JsBarcode.all.min.js",
11
+ action:"load_script",
12
+ extra:{impt_name:"JsBarcode"}
13
+ },
14
+ 'html2canvas-src':{
15
+ type:"str",
16
+ dflt:"https://html2canvas.hertzen.com/dist/html2canvas.min.js",
17
+ action:"load_script",
18
+ extra:{impt_name:"html2canvas"}
19
+ },
20
+ 'zxing-src':{
21
+ type:"str",
22
+ dflt:"https://unpkg.com/@zxing/library@0.21.3/umd/index.min.js",
23
+ action:"load_script",
24
+ extra:{impt_name:"Quagga"}
25
+ },
26
+ ////
27
+ "auto-destroy":{type:'bool',dflt:false, action:"none"},
28
+ "code" :{type:'str', dflt:'', action:"none"},
29
+ "format" :{type:'str', dflt:'CODE128', action:"none"},
30
+ 'ean128' :{type:'bool',dflt:true, action:"none"},
31
+ "hide-button" :{type:'bool',dflt:false, action:"auto"/*host([hide-button="true"])*/},
32
+ "barcode-btn-text":{type:'str',dflt:'生成条形码',action:(self,attr,type,val,accessor_name,extra)=>{
33
+ const btn = self.shadowRoot.querySelector('#bacode-btn');
34
+ btn.innerText = val;
35
+ }},
36
+ 'barcode-container-background':{type:'str',dflt:'#ffffff', action:"set_style_prop" },
37
+ 'barcode-btn-background' :{type:'str',dflt:'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',action:"set_style_prop" },
38
+ 'barcode-btn-color' :{type:'str',dflt:'#ffffff', action:"set_style_prop" },
39
+ 'barcode-btn-border-radius':{type:'num',dflt:8, action:"set_style_prop" },
40
+ 'barcode-btn-font-size' :{type:'num',dflt:16, action:"set_style_prop" },
41
+ ////
42
+ 'barcode-show-text': {type:'bool',dflt:true, action:"extn"},
43
+ 'barcode-width': {type:'num',dflt:2, action:"extn"},
44
+ 'barcode-height': {type:'num',dflt:100, action:"extn"},
45
+ 'barcode-line-color':{type:'str',dflt:'#000000', action:"extn"},
46
+ 'barcode-font-size': {type:'num',dflt:20, action:"extn"},
47
+ 'barcode-margin': {type:'num',dflt:10, action:"extn"},
48
+ }
49
+
50
+ //// init_dflts_and_rtrn_attr_change_executor
51
+ //// creat_load_libs
52
+ module.exports = init(ACTIONS,ATTRS);
53
+ module.exports.ACTIONS = ACTIONS;
54
+ module.exports.ATTRS = ATTRS;
55
+
56
+
package/com.sh ADDED
@@ -0,0 +1,5 @@
1
+ nv_cli_build -m -g nvimgbarcode -i index.js -o DIST/nv-img-barcode-bw.js
2
+ nv_cli_build -g nvimgbarcode -i index.js -o DIST/nv-img-barcode-bw.full.js
3
+ node ./TOOL/cli-creat-dist.js
4
+ node ./TOOL/cli-creat-html.js
5
+ csnpm publish