-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathindex.html
More file actions
121 lines (107 loc) · 4.47 KB
/
index.html
File metadata and controls
121 lines (107 loc) · 4.47 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pick One To Fill with BarcodeScanner</title>
<link rel="stylesheet" href="./index.css">
<!-- Include Dynamsoft Barcode Reader Bundle via CDN -->
<script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.4.2000/dist/dbr.bundle.js"></script>
<!-- If the network is unstable or you prefer to self-host the SDK, uncomment the line below to load it locally -->
<!-- <script src="../../../dist/dbr.bundle.js"></script> -->
</head>
<body>
<div class="container">
<!-- This div will host the barcode scanner's camera view -->
<div class="barcode-scanner-view"></div>
<div class="guide-view">
<span>Please click the "<span style="color: #999999;">Open Camera</span>" button below to open the scanning interface.</span>
</div>
<div class="form-view">
<div class="item pn">
<label class="title">Product Name: </label>
<input type="text">
</div>
<div class="item sn">
<label class="title">SN: </label>
<div class="content">
<input type="text">
<button class="open-btn open-sn">Open Camera</button>
<button class="decode-btn decode-sn">Decode to Auto-Fill</button>
</div>
</div>
<div class="item mac">
<label class="title">MAC: </label>
<div class="content">
<input type="text">
<button class="open-btn open-mac">Open Camera</button>
<button class="decode-btn decode-mac">Decode to Auto-Fill</button>
</div>
</div>
<div class="item eid">
<label class="title">EID: </label>
<div class="content">
<input type="text">
<button class="open-btn open-eid">Open Camera</button>
<button class="decode-btn decode-mac">Decode to Auto-Fill</button>
</div>
</div>
</div>
</div>
<script>
const guideView = document.querySelector(".guide-view");
const barcodeScannerView = document.querySelector(".barcode-scanner-view");
const scanBtns = document.querySelectorAll(".open-btn");
const decodeBtns = document.querySelectorAll(".decode-btn");
Dynamsoft.License.LicenseManager.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9");
const pInit = (async () => {
const cameraView = await Dynamsoft.DCE.CameraView.createInstance();
const cameraEnhancer = await Dynamsoft.DCE.CameraEnhancer.createInstance(cameraView);
const cvRouter = await Dynamsoft.CVR.CaptureVisionRouter.createInstance();
cvRouter.setInput(cameraEnhancer);
barcodeScannerView.append(cameraView.getUIElement());
return {
cameraView,
cameraEnhancer,
cvRouter
}
})();
for (let i = 0; i < scanBtns.length; i++) {
const scanBtn = scanBtns[i];
const decodeBtn = decodeBtns[i];
scanBtn.addEventListener("click", async (e) => {
const { cameraView, cameraEnhancer, cvRouter } = await pInit;
if (cameraEnhancer.isOpen()) return;
await cameraEnhancer.open();
const target = e.target.classList[1].split("-")[1];
const targetInput = document.querySelector(`.${target} input`);
const resultReceiver = new Dynamsoft.CVR.CapturedResultReceiver();
resultReceiver.onDecodedBarcodesReceived = (result) => {
if (result.barcodeResultItems.length > 0) {
// Display the first detected barcode's text in an alert
targetInput.value = result.barcodeResultItems[0].text;
guideView.style.display = "flex";
barcodeScannerView.style.display = "none";
scanBtn.style.display = "inline-block";
decodeBtn.style.display = "none";
decodeBtn.innerText = "Decode to Auto-Fill";
cameraEnhancer.close();
cvRouter.stopCapturing();
cvRouter.removeResultReceiver(resultReceiver);
}
}
await cvRouter.addResultReceiver(resultReceiver);
guideView.style.display = "none";
barcodeScannerView.style.display = "block";
scanBtn.style.display = "none";
decodeBtn.style.display = "inline-block";
})
decodeBtn.addEventListener("click", async () => {
decodeBtn.innerText = "Scanning...";
const { cameraView, cameraEnhancer, cvRouter } = await pInit;
await cvRouter.startCapturing("ReadSingleBarcode");
})
}
</script>
</body>
</html>