37 lines
874 B
Vue
37 lines
874 B
Vue
<template>
|
|
<el-button @click="chooseSerial">选择扫码枪串口</el-button>
|
|
<el-input ref="inputRef" v-model="printValue" @keyup.enter="enterHandle" @input="inputHandle"></el-input>
|
|
</template>
|
|
|
|
<script setup>
|
|
import _ from 'lodash'
|
|
import { ref, onMounted } from 'vue';
|
|
|
|
const inputRef = ref(null)
|
|
|
|
const printValue = ref('')
|
|
|
|
function enterHandle() {
|
|
console.log('回车了')
|
|
}
|
|
|
|
const inputHandle = _.debounce(function (e) {
|
|
console.log('扫码枪输入完了', e)
|
|
}, 100)
|
|
|
|
//选择串口设备
|
|
const chooseSerial = async () => {
|
|
if ('serial' in navigator) {
|
|
// await port.close();
|
|
console.log('当前浏览器支持serial')
|
|
const port = await navigator.serial.requestPort()
|
|
await port.open({ baudRate: 9600 })
|
|
}
|
|
};
|
|
|
|
onMounted(() => {
|
|
setTimeout(() => {
|
|
inputRef.value.focus()
|
|
}, 1000)
|
|
})
|
|
</script> |