春风项目四线(合箱线、总装线)
wujian
2024-10-23 2c65c31aceb16c1d06c692266e3fb555ecafdfb5
提交 | 用户 | 时间
5030f3 1 <template>
Y 2   <div style="height: 100%;width: 100%">
3     <el-card class="box-card">
4       <el-form size="large" :inline="true" label-width="68px" @submit.native.prevent>
5         <el-form-item label-width="200" label="箱体码" :prop="barcode1"  style="align-content: center">
6           <input v-model="barcode1"
7                  ref="inputdata1"
8                  style="height: 39px; width: 300px"
9                  placeholder="请扫描箱体码"
10           />
11         </el-form-item>
12
13         <el-form-item label-width="200" label="宝码" :prop="barcode2"  style="align-content: center">
14           <input v-model="barcode2"
15                  ref="inputdata2"
16                  style="height: 39px; width: 300px"
17                  placeholder="请扫描宝码"
18           />
19         </el-form-item>
20       </el-form>
21     </el-card>
22   </div>
23 </template>
24 <script>
25 export default {
26   data(){
27     return {
28       scannerFlag: false,
29       barcode1: "",
30       barcode2: "",
31     };
32   },
33
34   mounted() {
35     this.setFocus()
36     this.$refs.inputdata1.addEventListener('keydown',this.handleScannerInput1)
37     this.$refs.inputdata2.addEventListener('keydown',this.handleScannerInput2)
38   },
39   beforeDestroy() {
40     this.$refs.inputdata1.removeEventListener('keydown',this.handleScannerInput1)
41     this.$refs.inputdata2.removeEventListener('keydown',this.handleScannerInput2)
42   },
43   methods: {
44     refresh() {
45       location.reload();
46     },
47     setFocus(){
48       this.$nextTick(()=>{
49         this.$refs.inputdata1.focus()
50       })
51     },
52     handleScannerInput1(event){
53       if (this.scannerFlag){
54         this.barcode1 = ''
55         this.$refs.inputdata1.value = ''
56         this.scannerFlag = false
57       }
58       const input = event.target
59       const inputValue = input.value
60       this.barcode1 = inputValue
61       if (event.key === 'Enter'){
62         this.scannerFlag = true
63         console.log('条码1:',this.barcode1)
64         this.$refs.inputdata2.focus();
65         //扫描完成
66       }
67     },
68     handleScannerInput2(event){
69       if (this.scannerFlag){
70         this.barcode2 = ''
71         this.$refs.inputdata2.value = ''
72         this.scannerFlag = false
73       }
74       const input = event.target
75       const inputValue = input.value
76       this.barcode2 = inputValue
77       if (event.key === 'Enter'){
78         this.scannerFlag = true
79         console.log('条码2:',this.barcode2)
80         this.$refs.inputdata1.focus();
81         //扫描完成
82       }
83     },
84   },
85 }
86 </script>
87 <style scoped lang="scss">
88 </style>
89
90
91
92
93