生活随笔
收集整理的這篇文章主要介紹了
2,uniapp功能之—扫码(条形码,二维码)点击扫码或者pda侧边按钮扫码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
最近在搞uniapp的項目,所以最近的文章基本上是關于uniapp的。
分享一個自動生成二維碼的網址,點擊前往
注意 如果掃碼和上一個nfc功能在同一個頁面里面,會發(fā)生沖突,只有一個有用,一個沒有用,所有,我給掃碼的分裝成了一個組件,這樣就不會沖突了。
1,在component里面新建一個ScanCode.vue組件
<template
><view
class="Big"><view id
="page"><text v
-if="isKeshi" class="nameSty">掃描二維碼獲取
</text
><text v
-if="!isKeshi" class="nameSty">{{codes
}}</text
></view
></view
>
</template
><script
>var main
, receiver
, filter
;var _codeQueryTag
= false;export default {name
:"nfc",data() {return {codes
:'',isKeshi
:true,nameStys
:false,};},created(option) {this.initScan();this.startScan();},onHide() {this.stopScan();},destroyed() {this.stopScan();},methods
:{initScan() {let _this
= this;main
= plus
.android
.runtimeMainActivity(); let IntentFilter1
= plus
.android
.importClass('android.content.IntentFilter');filter
= new IntentFilter1();filter
.addAction("com.seuic.scan"); receiver
= plus
.android
.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {onReceive: function(context, intent) {plus
.android
.importClass(intent
);let code
= intent
.getStringExtra("scannerdata"); _this
.codes
= code
;_this
.queryCode(code
);_this
.$emit("setData",code
.replace(/\n/g,""));_this
.isKeshi
= false;}});},startScan() {main
.registerReceiver(receiver
, filter
);},stopScan() {main
.unregisterReceiver(receiver
);},queryCode(code) {if (_codeQueryTag
) return false;_codeQueryTag
= true;setTimeout(function() {_codeQueryTag
= false;}, 150);let id
= code
},ScanCode() {let main1
= plus
.android
.runtimeMainActivity(); let Intent
= plus
.android
.importClass("android.content.Intent");let intent2
= new Intent("com.scan.onStartScan");main1
.sendBroadcast(intent2
);},},}
</script
><style
>
.Big
{width
: 220px
;
}
.nameSty
{height
: 30px
;width
: 220px
!important
;line
-height
: 30px
;font
-size
: 18px
;font
-weight
: bold
;color
: #
828282 !important
;
}/deep/.u
-size
-default,/deep/.uni
-input
-input
{font
-size
: 18px
;
}
</style
>
2,在需要的頁面引入
<template
><view
class="box"><scanCode @setData
="getData"></scanCode
></view
>
</template
>
<script
>
import scanCode
from "../../components/saoma.vue";export default {components
: {scanCode
},methods
: {getData(res){console
.log(res
)},}}
</script
>
沒了,結束了,是不是很簡單吶,如有問題,歡迎留言。
最后:如果此篇博文對您有幫助,還請動動小手點點關注點點贊吶~,謝謝 ~ ~
總結
以上是生活随笔為你收集整理的2,uniapp功能之—扫码(条形码,二维码)点击扫码或者pda侧边按钮扫码的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。