2db47680
hexiaodong
chore: 初始提交 php 遗...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
<title>client side test for node-qrcode</title>
<!--[if ie]><script type="text/javascript" src="vendors/excanvas/excanvas.js"></script><![endif]-->
<script src="qrcode.js"></script> <!-- This doesn't exist in the examples, you'll need to supply this. -->
<script src="qrcode.tosjis.js"></script> <!-- This doesn't exist in the examples, you'll need to supply. -->
<style>
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
html,
body {
margin: 0;
background-color: ghostwhite;
}
input,
textarea {
font-size: 14px;
padding: 2px;
}
textarea {
resize: none;
}
.container {
display: flex;
margin: 0 auto;
padding: 16px;
justify-content: center;
}
.controls {
flex: 2;
display: flex;
flex-direction: column;
min-width: 400px;
max-width: 400px;
}
.qrcode-container {
display: flex;
justify-content: center;
align-items: center;
}
.qrcode-image {
border: 1px solid #ccc;
}
.container>*+* {
margin-left: 40px;
}
.title {
text-align: center;
}
.control-group {
display: flex;
}
.control-group+.control-group {
margin-top: 16px;
}
.control {
flex: 1;
display: flex;
flex-direction: column;
}
.control+.control {
margin-left: 16px;
}
.control>input {
width: 100%;
}
.control>textarea {
width: 100%;
flex-grow: 1;
}
.expand {
flex-grow: 1;
}
</style>
</head>
<body>
<h1 class="title">node-qrcode</h1>
<div class="container">
<div class="controls">
<div class="control-group">
<div class="control">
<label for="version">Version:</label>
<select id="version" name="version">
<option>Auto</option>
</select>
</div>
<div class="control">
<label for="mode">Mode:</label>
<select id="mode" name="mode">
<option>Auto</option>
<option>Numeric</option>
<option>Alphanumeric</option>
<option>Byte</option>
<option>Kanji</option>
</select>
</div>
</div>
<div class="control-group">
<div class="control">
<label for="margin">Margin:</label>
<input id="margin" type="number" name="margin" min="4" value="4" />
</div>
<div class="control">
<label for="errorLevel">Error Correction:</label>
<select id="errorLevel" name="errorLevel">
<option>Default (Medium)</option>
<option>Low</option>
<option>Medium</option>
<option>Quartile</option>
<option>High</option>
</select>
</div>
</div>
<div class="control-group">
<div class="control color-control">
<label for="lightColor">Light color:</label>
<input id="lightColor" type="color" name="light" value="#ffffff" />
</div>
<div class="control color-control">
<label for="darkColor">Dark color:</label>
<input id="darkColor" type="color" name="dark" value="#000000" />
</div>
</div>
<div class="control-group expand">
<div class="control">
<label for="input-text">Text:</label>
<textarea id="input-text">https://github.com/soldair/node-qrcode</textarea>
</div>
</div>
</div>
<div class="qrcode-container">
<p id="error" class="error"></p>
<canvas id="canvas" class="qrcode-image"></canvas>
</div>
</div>
<script>
var errorEl = document.getElementById('error')
var versionEl = document.getElementById('version')
var errorLevelEl = document.getElementById('errorLevel')
var modeEl = document.getElementById('mode')
var marginEl = document.getElementById('margin')
var lightColorEl = document.getElementById('lightColor')
var darkColorEl = document.getElementById('darkColor')
var canvasEl = document.getElementById('canvas')
var textEl = document.getElementById('input-text')
function debounce(func, wait, immediate) {
var timeout
return function () {
var context = this
var args = arguments
var later = function () {
timeout = null
if (!immediate) func.apply(context, args)
}
var callNow = immediate && !timeout
clearTimeout(timeout)
timeout = setTimeout(later, wait)
if (callNow) func.apply(context, args)
}
}
function drawQR(text) {
errorEl.style.display = 'none'
canvasEl.style.display = 'block'
QRCode.toCanvas(canvasEl, text, {
version: versionEl.value,
errorCorrectionLevel: errorLevelEl.options[errorLevelEl.selectedIndex].text,
margin: marginEl.value,
color: {
light: lightColorEl.value,
dark: darkColorEl.value
},
toSJISFunc: QRCode.toSJIS
}, function (error, canvas) {
if (error) {
canvasEl.style.display = 'none'
errorEl.style.display = 'inline'
errorEl.textContent = error
}
})
}
var updateQR = debounce(function () {
var mode = modeEl.options[modeEl.selectedIndex].text
if (mode !== 'Auto') {
drawQR([{ data: textEl.value, mode: mode }])
} else {
drawQR(textEl.value)
}
}, 250)
versionEl.addEventListener('change', updateQR, false)
errorLevelEl.addEventListener('change', updateQR, false)
modeEl.addEventListener('change', updateQR, false)
marginEl.addEventListener('change', updateQR, false)
lightColorEl.addEventListener('change', updateQR, false)
darkColorEl.addEventListener('change', updateQR, false)
textEl.addEventListener('keyup', updateQR, false)
for (var i = 1; i <= 40; i++) {
versionEl.options[versionEl.options.length] = new Option(i.toString(), i)
}
drawQR(textEl.value)
</script>
</body>
</html>
|