LiveChange事件上的条形码扫描Autotrigger



我的SAPUI5应用程序具有条形码扫描功能。首先,用户将看到一个可以进行条形码扫描的弹出窗口,如果扫描条形码正确,它将触发下一个按钮,然后依次显示下一个条形码扫描的另一个弹出窗口。对于第一个条形码,用户必须在第二个条形码上扫描6-7位数字,应该是5。我的问题是拳头条形码的自动架。当用户扫描7位数字时,它会触发下一个2倍。有没有办法知道扫描条形码文本的最后长度?

这是我的textInput的LiveChange事件

                        liveChange: function(oEvent) {
                        sText = oEvent.getParameter('value');
                        parent1 = oEvent.getSource().getParent();
                            if ((typeof sText != 'undefined') && (sText.length >= 6) )
                            {
                                sap.ui.getCore().byId(t.createId("costCenterInput")).setValue(sText);
                                setTimeout(function() { 
                                    console.log(parent1.getBeginButton());
                                    if (parent1.getBeginButton() != null){
                                    parent1.getBeginButton().firePress(oEvent); 
                                    }
                                    }, 5000);
                            }
                    }

此代码的问题是外部条形码扫描仪充当一次输入数据的蓝牙键盘。因此,说我们扫描1234567,进入6时,即使超时也将触发,并且在输入7时会再次触发。

新代码

    onScanAddressMobile: function(){
    var t = this;
    t.oBundle = this.oApplicationFacade.getResourceBundle();
    var dialog = new sap.m.Dialog(t.createId("ccDialog"), {
            title: t.oBundle.getText("COST_CENTER"),
            type: 'Message',
            content: [
                new sap.m.Text({ text: t.oBundle.getText("SCAN_COST_CENTER")}),
                new sap.m.Input(t.createId("costCenterInput"), {
                    type: "Number",
                    liveChange: 
                    function(oEvent){
                        t.onLiveChange(oEvent);
                    }
                }),
      .....some more code here...
      },
      onLiveChange : function(event) {
        //alert("onLiveChange");
                    var value = event.getParameter("value");
                    if (value && value.length === 6) {
                        alert("6 character");
                        this.timer = setTimeout(this.gotoNextPage(value), 4000);  
                    } else if (value && value.length > 6) {
                        alert("6 or more");
                        if (this.timer) {
                          clearTimeout(this.timer);
                        }
                        this.gotoNextPage(value);
                    }
    },

通常,可以将条形码扫描仪配置为在扫描字符的末尾(或任何其他字符)发送'return'值,但是CHR(13)最常见当被划分为输入字段

时,可以立即提交表格

查看您是否可以配置自己的,然后只需检查最后一个字符(返回)

用作蓝牙键盘的条形码扫描仪将非常迅速地"键"键"。如果您收到了6位数字,然后可能没有收到250毫秒的任何东西,则可以考虑条形码完整并跳到下一页。

如果您收到了7位数字,您甚至不需要等待,但是可以立即跳到下一页。

所以我想您的代码必须看起来像这样:

onLiveChange : function(event) {
    var value = event.getParameter("value");
    if (value && value.length === 6) {
        this.timer = setTimeout(this.gotoNextPage, 250)  
    } else if (value && value.length > 6) {
        if (this.timer) {
          clearTimeout(this.timer);
        }
        this.gotoNextPage();
    }
}

请在此jsbin中找到一个稍长时间的示例:http://jsbin.com/kolacez/1/edit?html,output

这将发生:

  • char 1:没有什么
  • char 2:没有什么
  • char 3:没有什么
  • char 4:没有什么
  • char 5:没有什么
  • char 6:设置了一个计时器,如果在特定时间范围内未收到字符7,则假定条形码已完成,并且它将启动gotOnextpage。
  • char 7:计时器已取消,直接启动了gotOnextPage。

因此,如果收到了7个chars条形码,则执行Char 6和Char 7的逻辑,但是由于Char 6的计时器效法被取消,因此仅启动了一次gotOnextPage方法。

<</p> <</p>

最新更新