Files
SmartCulturalTourismManageU…/components/scan.vue
2025-08-26 16:17:24 +08:00

112 lines
2.7 KiB
Vue

<template>
<view>
<view id="barcode"></view>
<view id="light"></view>
<view id="close"></view>
</view>
</template>
<script>
var light, close;
export default {
data() {
return {
// #ifdef APP-PLUS
barcode: [
plus.barcode.QR
// plus.barcode.EAN13,
// plus.barcode.EAN8,
// plus.barcode.UPCA,
// plus.barcode.UPCE,
// plus.barcode.CODABAR,
// plus.barcode.CODE39,
// plus.barcode.CODE93,
// plus.barcode.CODE128,
// plus.barcode.ITF,
],//码类型
// #endif
};
},
created() {
var statusBarHeight = uni.getSystemInfoSync().windowHeight;//状态栏
var height = statusBarHeight+'px';
var pages = getCurrentPages();
var page = pages[pages.length - 1];
// #ifdef APP-PLUS
var currentWebview = page.$getAppWebview();
this.barcode = plus.barcode.create('barcode', this.barcode, {
background:'#02c17e',
frameColor:'#02c17e',
scanbarColor:'#02c17e',
top: '0',
left: '0px',
width: '100%',
height: height,//这里可以设置扫码框的高度
position: 'static'
});
this.barcode.onmarked = this.onmarked;
currentWebview.append(this.barcode);
const res = uni.getSystemInfoSync();
if(res.platform == 'android'){//安卓机
// this.barcode.setFlash(true)
this.barcode.start();
}
// #endif
var that=this;
// light = new plus.nativeObj.View('light',
// {bottom:'100px',left:'0px',height:'44px',width:'100%'},
// [
// {tag:'font',id:'font',text:'轻触照亮',textStyles:{size:'16px',color:"rgba(255,255,255,0.8)"}}
// ]);
// close = new plus.nativeObj.View('close',
// {bottom:'100px',left:'0px',height:'44px',width:'100%'},
// [
// {tag:'font',id:'font',text:'轻触关闭',textStyles:{size:'16px',color:"rgba(255,255,255,0.8)"}}
// ]);
// light.show();
// light.addEventListener("click", function(){
// light.hide();
// close.show()
// that.barcode.setFlash(true)
// }, false);
// close.addEventListener("click", function(){
// light.show();
// close.hide()
// that.barcode.setFlash(false)
// }, false);
},
destroyed () {
// light.hide()
// close.hide()
},
beforeDestroy() {
uni.$off('setShow')
},
mounted () {
uni.$on('setShow', (data) => {
console.log(data.bol)
if (data.bol) {
setTimeout(() => {
this.barcode.start();
}, 1000)
} else {
this.barcode.cancel();
}
})
},
onUnload() {
clearTimeout(this.t);
},
methods: {
onmarked(type, result) {
this.$emit('getCode',result);
// this.t=setTimeout(() => {
// this.barcode.start();
// // this.barcode.setFlash(true)
// }, 1000)
}
}
}
</script>