-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarcode.html
More file actions
236 lines (215 loc) · 7.58 KB
/
barcode.html
File metadata and controls
236 lines (215 loc) · 7.58 KB
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>自定义扫码</title>
<script src="./sources/reqrcode.js"></script>
<style>
body,
ul {
margin: 0;
padding: 0 list-style: none
}
.app__layout {
position: absolute;
width: 100%;
height: 100%;
overflow: hidden;
background-color: #7f7f7f
}
video {
transform: translateX(-50%) translateY(-50%);
top: 50%;
left: 50%;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
overflow: hidden;
position: absolute
}
.app__overlay {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
transition: all .2s ease-in;
width: 540px;
height: 540px;
margin: auto;
background: linear-gradient(#2196F3, #2196F3) left top, linear-gradient(#2196F3, #2196F3) left top, linear-gradient(#2196F3, #2196F3) right top, linear-gradient(#2196F3, #2196F3) right top, linear-gradient(#2196F3, #2196F3) right bottom, linear-gradient(#2196F3, #2196F3) right bottom, linear-gradient(#2196F3, #2196F3) left bottom, linear-gradient(#2196F3, #2196F3) left bottom;
background-repeat: no-repeat;
background-size: 7px 70px, 70px 7px
}
.app__overlay2 {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 100%;
height: 100%;
overflow: hidden;
padding-top: 0;
margin: auto;
transition: all .2s ease-in;
}
.app__overlay3 {
position: fixed;
top: 0;
bottom: 0;
right: 0;
left: 0;
width: 600px;
height: 600px;
margin: auto;
transition: all .2s ease-in;
}
.app__overlay4 {
position: fixed;
margin: auto;
transition: all .2s ease-in;
}
@-webkit-keyframes scanner {
0% {
bottom: 100%
}
50% {
bottom: 0
}
to {
bottom: 100%
}
}
@-moz-keyframes scanner {
0% {
bottom: 100%
}
to {
bottom: 0
}
}
@-o-keyframes scanner {
0% {
bottom: 100%
}
to {
bottom: 0
}
}
@keyframes scanner {
0% {
bottom: 100%
}
to {
bottom: 0
}
}
.custom-scanner {
width: 500px;
height: 7px;
background: linear-gradient(to right, rgba(0, 0, 0, 0) 00%, #2196f3 50%, rgba(0, 0, 0, 0) 100%);
position: absolute;
-webkit-transition: all .2s linear;
-moz-transition: all .2s linear;
transition: all .2s linear;
-webkit-animation: scanner 7s linear infinite;
-moz-animation: scanner 7s infinite linear;
-o-animation: scanner 7s infinite linear;
animation: scanner 7s linear infinite;
display: none;
margin-left: 20px
}
</style>
</head>
<body>
<div class="app__layout"><video id="v" autoplay playsinline disablepictureinpicture muted></video></div>
<canvas id="canvas" style="display:none;"></canvas>
<div class="app__overlay">
<div class="custom-scanner" style="display: block;"></div>
</div>
<svg class="app__overlay2">
<defs>
<mask id="myMask">
<rect x="0" y="0" width="100%" height="100%" style="stroke:none; fill: #ccc;"></rect>
<rect width="540px" height="540px" x="50%" y="50%" transform="translate(-270,-270)" style="fill: #000">
</rect>
</mask>
</defs>
<rect x="0" y="0" width="100%" height="100%" style="stroke: none; fill: rgba(0, 0, 0, 0.5); mask: url(#myMask)">
</rect>
</svg>
<div class="app__overlay3" style="transform: translateY(680px);">
<center>
<font color="white" size="30px">请扫描二维码</font>
</center>
</div>
<a class="app__overlay4" style="transform: translateY(30px) translateX(30px);text-decoration:none;" href="#"
onclick="javascript:history.back(-1);">
<font color="white" size="30px">返回</font>
</a>
<script>
!(function () {
// 老的浏览器可能根本没有实现 mediaDevices,所以我们可以先设置一个空的对象
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function (constraints) {
// 首先,如果有getUserMedia的话,就获得它
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
// 一些浏览器根本没实现它 - 那么就返回一个error到promise的reject来保持一个统一的接口
if (!getUserMedia) {
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
}
// 否则,为老的navigator.getUserMedia方法包裹一个Promise
return new Promise(function (resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
const constraints = {
video: {
facingMode: "environment"
},
audio: false
};
let videoPlaying = false;
let v = document.getElementById('v');
let promise = navigator.mediaDevices.getUserMedia(constraints);
promise.then(stream => {
// 旧的浏览器可能没有srcObject
if ("srcObject" in v) {
v.srcObject = stream;
} else {
// 防止再新的浏览器里使用它,应为它已经不再支持了
v.src = window.URL.createObjectURL(stream);
}
v.onloadedmetadata = function (e) {
v.play();
videoPlaying = true;
};
}).catch(err => {
console.error(err.name + ": " + err.message);
})
window.setInterval(function () {
//里面写内容
if (videoPlaying) {
let canvas = document.getElementById('canvas');
canvas.width = v.videoWidth;
canvas.height = v.videoHeight;
canvas.getContext('2d').drawImage(v, 0, 0);
let data = canvas.toDataURL('image/webp');
qrcode.decode(data);
qrcode.callback = function (imgMsg) {
if (imgMsg != 'error decoding QR Code') {
window.location.href = "./pass.html";
};
};
};
}, 1000);
})();
</script>
</body>
</html>