条码网站交互

发布于 2024-09-28 05:12:36 字数 1471 浏览 0 评论 0原文

我正在设计一个 Web 应用程序,并且正在考虑合并一些条形码读取功能以方便数据输入。假设我有一份快递员需要完成的任务列表。我想打印类似于下页的内容:

+----------------------------------------------------------------------+
| Task List                                   || || |||| || || ||| (a) |
|                                                                      |
| Task One                                    ||| || |||||| || ||| (b) |
| Task Two                                    ||| || || | | || ||| (c) |
| Task Three                                  | |||||| || ||| |||| (d) |
|                                                                      |
|                                             ||||| |||| || || ||| (e) |
+----------------------------------------------------------------------+

条形码由 ||||| 表示| ||| || (x) 在每行的末尾。使用条形码 servlet 来打印页面应该是直接的。我希望有一种通用方法来拦截这些条形码并在 jQuery 中执行操作。例如:

  • 条形码 (a) 可以是 goto:/tasklist/123:
  • 条形码 (b)、(c) 和 (d) 可以是 add:31222:, < code>add:31223 和 add:31224:
  • 条形码 (e) 可能是 submit::

当扫描条形码(a) 时,我会转到该页面。扫描条形码 (b)、(c)、(d) 时,我会在页面中填充文本输入。当扫描条形码(e)时,我会提交表格。我正在考虑在每个页面上提供某种形式的 jQuery 侦听器,我可以根据条形码的第一个命令向其注册操作。我知道我可以对条形码设备进行编程以合并一些逻辑,但想避免它,这样任何条形码都可以,而我不必对它们进行编程。

我什至认为每个条形码可能都必须以一些魔术标记开头,以区分常规输入和条形码输入。也许类似于 $**$:goto:/tasklist/123:。那么问题是我将如何执行 jQuery 来拦截这组命令,以及为我创建的不同操作注册处理程序的正确方法是什么(例如: $**$:add:31222:< /代码>)?

I'm in the process of designing a web application and I'm thinking about incorporating some barcode reading to facilitate data input. Let's suppose I have a list of tasks a courier needs to do. I would like to print something similar to the following page:

+----------------------------------------------------------------------+
| Task List                                   || || |||| || || ||| (a) |
|                                                                      |
| Task One                                    ||| || |||||| || ||| (b) |
| Task Two                                    ||| || || | | || ||| (c) |
| Task Three                                  | |||||| || ||| |||| (d) |
|                                                                      |
|                                             ||||| |||| || || ||| (e) |
+----------------------------------------------------------------------+

The barcodes are represented by the ||||| | ||| || (x) at the end of every line. Printing the page should be straight forward using a barcode servlet as barbecue. I would like to have a general way to intercept those barcodes and do stuff in jQuery. For example:

  • barcode (a) could be goto:/tasklist/123:
  • barcodes (b), (c) and (d) could be add:31222:, add:31223, and add:31224:
  • barcode (e) could be submit::

When scanning barcode(a) I would go to that page. When scanning barcodes (b), (c), (d) I would populate text inputs in the page. When scanning barcode (e) I would submit the form. I'm thinking of having some form of jQuery listener that is available on every page to which I can register actions based on the first command of the barcode. I know I can do programming of the barcode device to incorporate some of the logic, but would like to avoid it, so that any barcode would do and I don't have to deal with programming them.

I have even thought that each barcode might have to start with some magic token to distinguish between regular input and barcode input. Perhaps something like $**$:goto:/tasklist/123:. The question is then how would I go about doing the jQuery to intercept this set of commands and what would be the correct way to register handlers for the different actions I create (e.g.: $**$:add:31222:)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

殊姿 2024-10-05 05:12:36

我已经完成了类似的应用程序,所以这是我的两分钱。

USB 扫描仪的工作原理基本上类似于 USB 键盘。大多数设备会发送回车键作为终止字符,但这可以在大多数设备上进行配置。我依靠终止符来驱动 UI 中的操作。 (默认情况下,Enter 将提交当前选定的表单。)

另一个问题是,如果这是一个移动应用程序,您确实希望尽可能避免与服务器的往返。我通过在 UI 中添加大量应用程序逻辑来解决这个问题,但是所有业务逻辑仍然在服务器上,因此为了使操作生效,用户需要连接并能够 POST 到服务器。

所以,到你问题的核心。考虑这样的事情:

var state = 'WAITING'; # super simple state

function add(data) {
    # courier checks an item, 'data' contains the data from the scanner
}

function input_handler(input) {
    if (state == 'WAITING') {
        if (input == 'DONE' || input == 'EXIT') {
            state = 'DONE';
            # abort, whatnot
        } else {
            state = 'SCAN';
            input_handler(input); # recurse, with new state
        }
    } else {
        add(input);
    }
}

这基本上是一个手动编码的状态机。当快递员检查“我想开始扫描此订单”条形码时,您将进入一种模式,其中每个输入都会进入您的扫描处理程序。当他扫描“我完成了”条形码时,您验证结果等。这可以通过实际使用真实状态机来改进。

您应该使条形码尽可能简单。像“SCAN”、“EXIT”、“NOTHING_MORE_TO_SCAN”这样的命令都很好,因为它们是通用的,您的应用程序不需要解析条形码的含义。

保持简单的另一个原因是,您将遇到标签已损坏且无法扫描的情况。那么用户必须能够手动输入数据,而无需花费额外的时间查找特殊字符等。

I've done a similar application, so here are my two cents.

The USB scanner basically works like a USB keyboard. Most will send an enter key as termination character, but this can be configured on most devices. I relied on the termination character for driving actions in my UI. (Enter will by default submit the currently selected form.)

Another problem is that if this is a mobile application, you really want to avoid roundtrips to the server as much as possible. I solved this by having tons of application logic in the UI, however all business logic was still on the server so for actions to have effect, the user needed to be connected and able to POST to the server.

So, to the core of your problem. Consider something like this:

var state = 'WAITING'; # super simple state

function add(data) {
    # courier checks an item, 'data' contains the data from the scanner
}

function input_handler(input) {
    if (state == 'WAITING') {
        if (input == 'DONE' || input == 'EXIT') {
            state = 'DONE';
            # abort, whatnot
        } else {
            state = 'SCAN';
            input_handler(input); # recurse, with new state
        }
    } else {
        add(input);
    }
}

This is basically a state machine, coded manually. When the courier checks the 'I want to start scanning for this order'-barcode, you enter a mode where every input goes to your scanning handler. When he scans the "I'm done"-barcode, you validate the result, etc. This could be improved by actually using a real state machine.

You should keep the barcodes as simple as possible. Commands like 'SCAN', 'EXIT', 'NOTHING_MORE_TO_SCAN' are good, because they are generic and your application need not parse the barcode for meaning.

Another reason for keeping them simple, is that you will run into a situation where the label has been damaged and is impossible to scan. Then the user must be able to manually enter the data without spending extra time finding special characters, etc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文