春风项目四线(合箱线、总装线)
yyt
2024-06-03 5030f3d30ccc1bd16db371c6970a48103aff9191
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
  <div style="height: 100%;width: 100%">
    <el-card class="box-card">
      <el-form size="large" :inline="true" label-width="68px" @submit.native.prevent>
        <el-form-item label-width="200" label="箱体码" :prop="barcode"  style="align-content: center">
          <input v-model="barcode"
               ref="inputdata"
               style="height: 39px; width: 300px"
               placeholder="请扫描箱体码"
          />
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
export default {
  data(){
    return {
      scannerFlag: false,
      barcode: "",
    };
  },
 
  mounted() {
    this.setFocus()
    this.$refs.inputdata.addEventListener('keydown',this.handleScannerInput)
  },
  beforeDestroy() {
    this.$refs.inputdata.removeEventListener('keydown',this.handleScannerInput)
  },
  methods: {
    refresh() {
      location.reload();
    },
    setFocus(){
      this.$nextTick(()=>{
        this.$refs.inputdata.focus()
      })
    },
    handleScannerInput(event){
      if (this.scannerFlag){
        this.barcode = ''
        this.$refs.inputdata.value = ''
        this.scannerFlag = false
      }
      const input = event.target
      const inputValue = input.value
      this.barcode = inputValue
      if (event.key === 'Enter'){
        this.scannerFlag = true
        console.log('条码:',this.barcode)
        //扫描完成
      }
    },
  },
}
</script>
<style scoped lang="scss">
</style>