美文网首页
获取pda扫码枪 扫描的数据

获取pda扫码枪 扫描的数据

作者: CoolBoy_52e5 | 来源:发表于2021-03-02 17:48 被阅读0次

1.扫码枪是模拟键盘输入的,输入一连串数字后加一个enter键。所以可以监听键盘事件。

  • 新建一个隐藏的 input 用来接收数据,不然扫码枪会自动获取页面存在的一个input的焦点,并将数据显示在input框中。
<template>
  <el-input
    type="text"
    v-model="myvalue"
    id="inputId"
    placeholder=""
    size="normal"
    clearable
    class="inputShow"
  ></el-input>
</template>

// 隐藏 input
.inputShow {
  height: 0;
  width: 0;
  margin: 0;
  padding: 0;
}
::v-deep {
  .el-input .el-input__inner {
    height: 0 !important;
    width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
}
  • 在实际开发中需要区分是扫描枪输入还是用户键盘手动输入,区别在于扫码枪输入很快。
data(){
  return {
    code: "", // 扫码数据
    myvalue: "", // 
    lastTime: "",
    nextTime: "",
    lastCode: "",
    nextCode: "",
  }
}
// 退出页面时清空 避免在下一个页面还会生效
beforeDestroy() {
  document.onkeypress = "";
},
mounted() {
  this.scanCode();
},
// 扫码
scanCode() {
  document.onkeypress = (e) => {
    this.nextCode = e.which;
    if (e.which === 13) {
      if (this.code.length < 5) {
        //手动输入的时间不会让code的长度大于2,所以这里只会对扫码枪有效
        this.lastTime = null;
        this.lastCode = null;
        console.log("手动");
        this.code = "";
        return;
      }
      // 扫码的 值
      this.myvalue = this.code;
      // 在此处写需要调用的接口
      this.fun()
   
      console.log("自动");
      this.lastTime = null;
      this.lastCode = null;
      this.code = "";
      return;
    }
    this.nextTime = new Date().getTime();
    if (!this.lastTime && !this.lastCode) {
      this.code += e.key;
    }
    if (
      this.lastCode != null &&
      this.lastTime != null &&
      this.nextTime - this.lastTime <= 100
    ) {
      // 将焦点放在 隐藏的 input 框中
      document.getElementById("inputId").focus();
      document.getElementById("inputId").blur();
      this.code += e.key;
    } else if (
      this.lastCode != null &&
      this.lastTime != null &&
      this.nextTime - this.lastTime > 100
    ) {
      //当扫码前有keypress事件时,防止首字缺失
      // this.code = e.key;
    }
    this.lastCode = this.nextCode;
    this.lastTime = this.nextTime;
  };
},

相关文章

  • 2019-06-28

    什么是物流PDA? 物流PDA,又叫物流条码扫描枪,物流手持机设备或物流扫码枪,中转场/仓库数据采集,通过扫描快件...

  • 获取pda扫码枪 扫描的数据

    1.扫码枪是模拟键盘输入的,输入一连串数字后加一个enter键。所以可以监听键盘事件。 新建一个隐藏的 input...

  • js获取扫码枪输入

    场景:扫码枪扫码,获取信息,js代码如何获取扫描信息呢? 原理:扫码枪输入会触发键盘输入事件。扫码枪输入的时间间隔...

  • pda扫码枪

    pda扫码枪是指具有操作系统、内存、CPU、显卡、屏幕和键盘,具备数据传输处理能力,配置有电池,可以移动使用的数据...

  • 2019-06-28

    什么是物流扫描枪? 物流扫描枪,又叫物流数据采集器,物流扫码采集器或物流条码把枪,中转场/仓库数据采集,通过扫描快...

  • Android监听扫描枪内容(一)

    在之前的文章,我已经写过了一篇关于扫描枪数据获取通常处理的文章,大家有兴趣的话可以参看PDA扫描获取内容的通常处理...

  • 2019-06-28

    什么是物流数据采集器? 物流数据采集器,又叫物流扫码枪,物流条码扫描枪或物流移动把枪,中转场/仓库数据采集,通过扫...

  • Android使用AccessibilityService实现U

    android单屏机,通过扫码枪扫描二维码的场景非常多,扫码枪的种类也有蓝牙、USB、串口等等 目前USB的扫码枪...

  • 数据采集是无线PDA的特点

    数据采集是无线PDA最大的特点,较为常见的是条码扫描、二维码扫描等,通过PDA的扫描来读取信息。作为数据采集终端,...

  • Android 项目中的小需求

    1.硬件扫描二维码登录 参考Android 无 EditText 情况下接受扫码枪扫描数据 需求:硬件设备有二维码...

网友评论

      本文标题:获取pda扫码枪 扫描的数据

      本文链接:https://www.haomeiwen.com/subject/scrsfltx.html