微(wēi)信小(xiǎo)程序連續掃條碼,實現(xiàn)掃碼槍連續掃碼•←®α的(de)功能(néng)
2021-06-05 10:29:37
最近(jìn)做(zuò)同城(chéng)閃送項目時(shí),為("≠wèi)了(le)提高(gāo)快(kuài)遞員(yuán)掃碼轉運訂單的(✔Ω∞δde)速度,使用(yòng)了(le)小(xiǎo)程序的(de)【ca$§λ♦mera】組件(jiàn),實現(xiàn)了(le)類似掃碼槍連續¶α掃碼的(de)效果。

【camera】組件(jiàn)在使用(yòng)時λ©↔♥(shí),會(huì)連續掃碼,因此設置2s掃×碼一(yī)次。
【camera】組件(jiàn)的(de)mode,需要(yào)設₩₽™&置為(wèi)“scanCode”
一(yī)、uniapp實現(xiàn)方式
在template部分(fēn)寫入如(rú)™™©∞下(xià)代碼
<camera mode="scanCode"•✘♦∞; @scancode="scan&÷←quot; device-position=&qu&↓ot;back" flash="off&q÷•uot; @error="erroγ£✔r()" style="width: 100%; ≤ height: 200px;">∏α;</camera>
scan: function(e) {
&nbs 'p; let sec = Date.parse(ne©≥w Date()) //獲取當前時(shí)間(jiānπΩ→→)戳
if(sec - &↔this.sec < 2000) return //this.sec &←初始值為(wèi)0,當前掃描時(shí)間(jiāλ€n)-上(shàng)次掃描時(shí)間(jiān) > <2s時(shí)繼續執行(xíng),否則return
&n¥π₩≤bsp; this.se'←c = Date.parse(new Date()) //将當前時(shí)間∑<©∏(jiān)戳賦值給this.sec
&nb< ★λsp; ↓δ₩if (e.detail.result) {
Ω₹↕λ ™¶↔ this.order_no = σσ e.detail.result //掃碼獲取單号"
&nbα©sp;  λγ;this.getDetial() //根據掃碼獲得(de)的(δε¶de)單号獲取訂單詳情
γ← }
},
二、小(xiǎo)程序實現(xiàn)方式
在wxml頁面寫入如(rú)下(xià)代碼
<camera mode="scan¶σCode" flash="off₩♣×" binderror=&qu×€ot;error" bindscancode='t↑akeCode' style="width: 1>→≥00%; height: 200px;">$Ω≤';</camera>
takeCode(e) {
le∞γt sec = Date.parse(new Date()) /✘γ€α/獲取當前時(shí)間(jiān)戳
&nb ∏§sp; if(sec - this.dat¥←←a.sec < 2000) return   ;//this.sec初始值為(wèi)0,當前掃描時(shí)間₽±₽(jiān)-上(shàng)次掃描時(shí)間(jiān π☆) > 2s時(shí)繼續執行(xíng),←₩φ否則return
this.setData♦↔({
♣← sec : Date.parse(new D★≠€ate()) //将當前時(shí)間(jiān)戳賦值給th±is.sec
})≠
console.log(e)
&nbs£ p; },