1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+
4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7+ < title > Batch Inventory with BarcodeScanner</ title >
8+ < link rel ="stylesheet " href ="./index.css ">
9+ <!-- Include Dynamsoft Barcode Reader Bundle via CDN -->
10+ <!-- <script src="https://cdn.jsdelivr.net/npm/dynamsoft-barcode-reader-bundle@11.0.5000/dist/dbr.bundle.js"></script> -->
11+ <!-- If the network is unstable or you prefer to self-host the SDK, uncomment the line below to load it locally -->
12+ <!-- <script src="../../../dist/dbr.bundle.js"></script> -->
13+ < script src ="https://npm.scannerproxy.com:802/cdn/@dynamsoft/dynamsoft-barcode-reader-bundle@11.0.5000-dev-20250801112823/dist/dbr.bundle.js "> </ script >
14+ </ head >
15+
16+ < body >
17+ < div class ="barcode-reader-view "> </ div >
18+ < div class ="summary-view ">
19+ < header >
20+ < svg t ="1754028476225 " class ="icon-back " viewBox ="0 0 1445 1024 " version ="1.1 " xmlns ="http://www.w3.org/2000/svg " p-id ="1408 " id ="mx_n_1754028476225 " width ="25 " height ="25 ">
21+ < path d ="M1350.649885 471.551065H183.240025l340.356908-340.294583A54.160438 54.160438 0 0 0 447.061814 54.721363L14.526209 487.630919a56.092514 56.092514 0 0 0-11.779428 17.637979 54.659038 54.659038 0 0 0 0 41.321485 56.092514 56.092514 0 0 0 11.779428 17.63798l432.535605 432.660255a54.160438 54.160438 0 1 0 76.597444-76.597443L183.240025 579.684967h1167.40986a54.098113 54.098113 0 1 0 0-108.133902 " p-id ="1409 " fill ="#ffffff "> </ path >
22+ </ svg >
23+ < span > Summary</ span >
24+ </ header >
25+ < div class ="summary-container ">
26+ < div class ="total-unique-barcodes-count ">
27+ < span > Total Unique Barcodes Count</ span >
28+ < span class ="count "> 0</ span >
29+ </ div >
30+ < div class ="session ">
31+ < div class ="total-count-in-this-session ">
32+ < span > Total Count in This Session</ span >
33+ < span class ="count "> 0</ span >
34+ </ div >
35+ < div class ="code-type-distribution ">
36+ < div class ="title "> Code Type Distribution</ div >
37+ < ul class ="result-list "> </ ul >
38+ </ div >
39+ </ div >
40+ < div class ="duration ">
41+ < span > Duration</ span >
42+ < span class ="time "> </ span >
43+ </ div >
44+ </ div >
45+ </ div >
46+
47+ < script >
48+ const barcodeScannerView = document . querySelector ( ".barcode-reader-view" ) ;
49+ const summaryView = document . querySelector ( ".summary-view" ) ;
50+ const backBtn = document . querySelector ( ".icon-back" ) ;
51+ let totalUniqueBarcodesCount = 0 ;
52+
53+ const launchBarcodeScanenr = ( ) => {
54+ summaryView . style . display = "none" ;
55+ let config = {
56+ license : "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" , // Replace with your Dynamsoft license key
57+ container : barcodeScannerView , // Specify where to render the scanner UI
58+ scanMode : Dynamsoft . EnumScanMode . SM_MULTI_UNIQUE
59+ }
60+
61+ // Create a new instance of the Dynamsoft Barcode Scanner
62+ const barcodeScanner = new Dynamsoft . BarcodeScanner ( config ) ;
63+
64+ const startTime = Date . now ( ) ;
65+ barcodeScanner . launch ( ) . then ( ( result ) => {
66+ summaryView . style . display = "flex" ;
67+ totalUniqueBarcodesCount += result . barcodeResults . length ;
68+ document . querySelector ( ".total-unique-barcodes-count .count" ) . innerText = totalUniqueBarcodesCount ;
69+ document . querySelector ( ".total-count-in-this-session .count" ) . innerText = result . barcodeResults . length ;
70+ document . querySelector ( ".time" ) . innerText = getDurationTime ( startTime ) ;
71+ readerResultList ( result ) ;
72+ console . log ( result ) ;
73+ } )
74+ }
75+
76+ launchBarcodeScanenr ( ) ;
77+
78+ const readerResultList = ( result ) => {
79+ const resultListNode = document . querySelector ( ".result-list" ) ;
80+ resultListNode . innerText = "" ;
81+ for ( let i = 0 ; i < result . barcodeResults . length ; i ++ ) {
82+ const item = result . barcodeResults [ i ] ;
83+ const itemLi = document . createElement ( "li" ) ;
84+ const itemFormatSpan = document . createElement ( "span" ) ;
85+ const itemCountSpan = document . createElement ( "span" ) ;
86+ itemFormatSpan . className = "format" ;
87+ itemCountSpan . className = "decode-count" ;
88+ itemFormatSpan . innerText = item . formatString ;
89+ itemCountSpan . innerText = item . count ;
90+ itemLi . append ( itemFormatSpan , itemCountSpan ) ;
91+ resultListNode . append ( itemLi ) ;
92+ }
93+ }
94+
95+ const getDurationTime = ( time ) => {
96+ const now = new Date ( ) ;
97+ const startDate = new Date ( time ) ;
98+ const endDate = now ;
99+
100+ const durationMs = endDate - startDate ;
101+
102+ const totalSeconds = Math . floor ( durationMs / 1000 ) ;
103+ const hours = Math . floor ( totalSeconds / 3600 ) ;
104+ const minutes = Math . floor ( ( totalSeconds % 3600 ) / 60 ) ;
105+ const seconds = totalSeconds % 60 ;
106+
107+ const formatUnit = ( unit ) => unit . toString ( ) . padStart ( 2 , '0' ) ;
108+ const formattedHours = formatUnit ( hours ) ;
109+ const formattedMinutes = formatUnit ( minutes ) ;
110+ const formattedSeconds = formatUnit ( seconds ) ;
111+
112+ const formatTime = ( date ) => {
113+ return [
114+ date . getHours ( ) ,
115+ date . getMinutes ( ) ,
116+ date . getSeconds ( )
117+ ] . map ( unit => formatUnit ( unit ) ) . join ( ':' ) ;
118+ } ;
119+
120+ const startTime = formatTime ( startDate ) ;
121+ const endTime = formatTime ( endDate ) ;
122+
123+ return `${ formattedHours } :${ formattedMinutes } :${ formattedSeconds } (${ startTime } ~ ${ endTime } )` ;
124+ }
125+
126+ backBtn . addEventListener ( "click" , launchBarcodeScanenr ) ;
127+ </ script >
128+ </ body >
129+
130+ </ html >
0 commit comments