Commit 56551277 authored by xieyishang's avatar xieyishang

~

parent f0c904ff
......@@ -76,6 +76,9 @@
</div>
<div class="pos_btn">
<!-- <el-button size="large" type="primary" @click="chooseSerial" >连接扫码枪</el-button> -->
<el-button size="large" type="primary" @click="focusfun" >监听扫码枪识别</el-button>
<el-button size="large" type="danger" @click="delAllGoods()">清空购物单</el-button>
<el-button size="large" type="success" @click="checkOut()">结算</el-button>
......@@ -191,6 +194,7 @@ export default {
typingTimeout: null, // 用于判断输入间隔的定时器
port:null,
// 原始数据 购物车
odata: [],
......@@ -560,7 +564,7 @@ export default {
console.log('input.value:', input.value );
if(input.value){
if(input.value && input.value.length>5){
this.childgoods.goods_sn = input.value;
this.childgoods.store_id = 0;
this.addCart("single", "", 1);
......@@ -579,7 +583,7 @@ export default {
this.scannedCode = input.value;
console.log('Scanned code:', this.scannedCode);
if(input.value){
if(input.value && input.value.length>5){
this.childgoods.goods_sn = input.value;
this.childgoods.store_id = 0;
this.addCart("single", "", 1);
......@@ -686,6 +690,58 @@ export default {
selectionChange(selection){
this.selection = selection;
},
//----2.0 扫码枪监听-------------------------------------------------------------------------------
async chooseSerial(){
if ('serial' in navigator) {
try {
this.port = (await navigator.serial.requestPort()) || null;
console.log('选择串口成功');
this.port && this.openSerial();
} catch (e) {
console.log('选择串口失败');
}
} else {
console.log('浏览器不支持serial API');
}
},
//打开串口读取数据
async openSerial() {
console.info("6666");
await this.port.open({ baudRate: 9600 });
try {
const textDecoder = new TextDecoderStream();
this.port.readable.pipeTo(textDecoder.writable);
const reader = textDecoder.readable.getReader();
let data = ''; //扫码数据
while (true) {
const { value, done } = await reader.read();
if (done) {
reader.releaseLock();
break;
}
data=`${data}${value}`
if(value.includes('\r')){//读取结束
let codeData=data;
data="";//清空下次读取不会叠加
console.log(`二维码数据:${codeData}`)
//处理拿到数据逻辑
}
}
} catch (error) {
console.error(error);
this.port = null;
} finally {
try {
reader.releaseLock();
//关闭串口
await this.port.close();
} catch (e) {}
}
this.port = null;
}
//----2.0 扫码枪监听-------------------------------------------------------------------------------
},
};
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment