This commit is contained in:
gyq
2024-03-11 14:34:17 +08:00
parent 11290d1505
commit 0fbc614c61
13 changed files with 156 additions and 217 deletions

View File

@@ -1,37 +1,20 @@
<template>
<el-button @click="chooseSerial">选择扫码枪串口</el-button>
<el-input ref="inputRef" v-model="printValue" @keyup.enter="enterHandle" @input="inputHandle"></el-input>
<el-button @click="chooseSerial">打印</el-button>
</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)
import { ipcRenderer } from 'electron'
//选择串口设备
const chooseSerial = async () => {
if ('serial' in navigator) {
// await port.close();
console.log('当前浏览器支持serial')
const port = await navigator.serial.requestPort()
await port.open({ baudRate: 9600 })
let printNum = localStorage.getItem('printNum')
if (!printNum) {
printNum = 1
localStorage.setItem('printNum', printNum)
} else {
printNum++
localStorage.setItem('printNum', printNum)
}
ipcRenderer.send('printStart', printNum)
};
onMounted(() => {
setTimeout(() => {
inputRef.value.focus()
}, 1000)
})
</script>