induction_debug.html 11.7 KB
<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="utf-8">

    <title>{{ _('感应式料架系统') }}-Admin</title>
    <link rel="icon" href="/static/favicon.ico">
    <link href="/static/css/bootstrap.min.css" rel="stylesheet">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/bootstrap.min.js"></script>
    <style>
        .shelf_row {}

        .shelf_box {
            width: 100%;
            border-top: 1px black solid;
            border-bottom: 1px black solid;
            border-right: 1px black solid;
            margin: 5px;
            background-color: gainsboro;
        }

        .shelf_col {

            height: 30px;
            float: left;
            border-left: 1px black solid;



        }

        .align_right {
            width: 100%;
            text-align: right;
        }

        .st {
            font-size: 12px;
            font-weight: bolder;
            transform: scale(0.7);
            word-wrap: break-word;
            line-height: 12px;
            width: 100%;
            height: 100%;
        }

        .t {
            background-color: lightgreen;
        }

        .cla {
            background-color: white;

        }
    </style>
</head>

<body style="font-size:18px;">
    {% set index=5 %}
    {% import 'head.html' as head with context%}
    {{ head }}
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6">
                <h2>{{ _('料架系统') }}</h2>
                <hr class="divider">
                <!-- 灯条测试 -->
                <div class="panel panel-warning">
                    <div class="panel-heading">
                        <h3 class="panel-title">{{ _('料架状态显示') }}</h3>
                    </div>
                    <div class="panel-body">
                        <div class="col-sm-12">
                            <input type="button" value="{{ _('开始扫描库位') }}" id="btn_start" class="btn btn-warning"
                                onclick="startscan()" />
                            <input type="button" value="{{ _('停止扫描库位') }}" id="btn_stop" class="btn btn-warning"
                                onclick="stopscan()" />
                        </div>
                        <div style="clear: both;margin: 5px;width: 100%;"></div>
                        <div id="shelflist"></div>
                        <div style="height: 10px;"></div>
                    </div>
                </div>

            </div>
        </div>

    </div>

    <script>
        $(document).ready(function () {

        });
        //运行中状态
        var isrun = false;
        //站号灯书对应表
        ledcountdict = {};
        //当前扫描站号
        var current_addr = '';
        var current_test_index = 0;
        var checked_test_index = -1;
        //全部站号
        var addrlist = [];
        $("#btn_stop").hide();
        function startscan() {
            if (confirm("进入料架扫描,需要停止料架运行,点击确认停止")) {
                stoppost();
            }
            else
                return;


            isrun = true;
            current_addr = '';
            if ($(".shelf_col").length == 0) {
                $.ajax({
                    url: "/getledcount",
                    type: "get",
                    contentType: "text/json",
                    dataType: 'json',
                    success: function (data) {
                        setshelflist(data)
                    },
                    error: function (e) {
                        alert("error");
                    }
                });
            }
            else {
                $(".shelf_box").removeClass('cla');
                setshelflist([])
            }
        }
        function stopscan() {
            isrun = false;
            starttest("");
            $(".shelf_box").addClass('cla');
            $("#btn_stop").hide();
            $("#btn_start").show();
        }

        function setshelflist(data) {
            $("#btn_stop").show();
            $("#btn_start").hide();
            //$("#shelflist").html('');
            for (var e in data) {
                var ledinfo = data[e];
                var ledcount = ledinfo['ledcount'];
                ledcountdict[e] = ledcount
                var DeviceUniqueID = ledinfo['DeviceUniqueID'];
                var Version = ledinfo['Version'];
                var shelfid = "shelf_" + e;
                addrlist.push(e);
                $("#shelflist").append("<div class='shelf_row'><div>" + e + " - V" + Version + "- <span id='" + shelfid + "_info'></span></div></div><div id='" + shelfid + "' class='shelf_box'></div><div class='align_right'><input type='button' value=\"{{ _('开始顺序测试') }}\" class='btn btn-warning' onclick='starttest(\"" + e + "\")'/></div></div>");
                for (var i = 0; i < ledcount; i++) {
                    var width = 100 / ledcount;
                    $("#" + shelfid).append("<div id='col_" + i + "' class='shelf_col' style='width:" + width + "%'><div class='st'>" + (ledcount - i) + "</div></div>");
                }
                $("#" + shelfid).append("<div style='clear:both'></div>");
            };
            getshelfstate();
        }
        function starttest(addr) {
            current_addr = addr;
            current_test_index = 0;
            checked_test_index = -1;
        }
        function getshelfstate() {
            var addrs = addrlist.join('@');
            if (current_addr.length > 0)
                addrs = currnet_addr
            var data = { "addrs": addrs };
            $.ajax({
                url: "/getshelfstate",
                type: "get",
                contentType: "text/json",
                dataType: 'json',
                data: JSON.stringify(data),
                success: function (data) {
                    try {
                        if (!isrun)
                            return;
                        if (data['msg']) {
                            stoppost();
                            getshelfstate();
                            return;
                        }
                        var addrcopy = addrlist.slice(0);
                        for (var e in data) {
                            shelfid = e;
                            if (shelfid.length == 3)
                                shelfid = "B" + e.substring(2);
                            var shelfdom = $("#shelf_" + shelfid)
                            shelfdom.remove('cla');
                            if (addrcopy.indexOf(shelfid) >= 0) {
                                addrcopy.splice(addrcopy.indexOf(shelfid), 1)
                            }
                            line = data[e];
                            ledcount = ledcountdict[shelfid];
                            if (shelfdom.length == 0)
                                continue;

                            rightledlist = [];
                            badledlist = [];
                            closeledlist = [];
                            shelfdom = shelfdom[0]
                            for (var i = 0; i < ledcount; i++) {
                                var d = $(shelfdom.childNodes[ledcount - 1 - i])
                                if (line[i] == "0") {
                                    if (d.hasClass('t')) {
                                        d.removeClass('t');
                                        closeledlist.push(i + 1);
                                        if (String(checked_test_index) == line[i] && current_test_index == checked_test_index) {
                                            current_test_index++;
                                            setledcolor(e, 'blue', [i + 1]);
                                        }
                                    }

                                } else {
                                    if (!d.hasClass('t')) {
                                        d.addClass('t');

                                        if (String(current_test_index) == line[i]) {
                                            rightledlist.push(i + 1);
                                        } else {
                                            badledlist.push(i + 1);
                                        }
                                    }
                                }
                            }
                            if (ledcount==current_test_index){
                                
                            }
                            if (badledlist.length > 0) {
                                setledcolor(e, 'red', badledlist);
                                setledcolor(e, 'red', rightledlist);
                            } else if (rightledlist.length > 0) {
                                checked_test_index = current_test_index;
                                setledcolor(e, 'green', rightledlist);
                            }

                            //setledcolor(e, 'red', openledlist, closeledlist);
                        }
                        addrcopy.forEach(function (shelfid) {
                            $("#shelf_" + shelfid + "").addClass('cla');
                        })
                    } catch { }
                    finally {
                        if (isrun)
                            setTimeout(getshelfstate(), 1);
                    }
                },
                error: function (e) {
                    if (isrun)
                        setTimeout(getshelfstate(), 1);
                }
            })
        };

        function setledcolor(addr, color, ledlist) {
            if (ledlist.length == 0 && closeledlist.length == 0)
                return;
            var data = {
                "addr": addr,
                "color": color,
                "ledlist": ledlist,
            }
            $.ajax({
                url: "/setledcolor",
                type: "post",
                data: JSON.stringify(data),
                contentType: "application/json",
                dataType: 'json',
                async: false,
                success: function (data) {
                    console.log(data);
                },
                error: function (e) {
                    //alert("error");
                }
            })
        }
        function stoppost() {
            $.ajax({
                url: "/stoppost",
                type: "post",
                async: false,
                // data:form,
                dataType: 'json',
                processData: false,
                contentType: false,
                success: function (data) {
                    //alert(data[0].msg)
                },
                error: function (e) {
                    //alert("{{_('停止失败')}}");
                }
            })
        }
        // auto_calibrate
        function auto_calibrate() {
            if (confirm("{{ _('请谨慎操作') }}")) {
                var addrs = document.getElementById("addr").value;
                addrs = addrs.replace('B', 'A1');
                addrs = addrs.replace('A', '');
                var data = {
                    "addr": addrs,
                    "calibrate": document.getElementById("calibrate").value
                }
                $.ajax({
                    url: "/auto_calibrate",
                    type: "post",
                    data: JSON.stringify(data),
                    contentType: "application/json",
                    dataType: 'json',
                    success: function (data) {
                        // $("#testinfo").html(data.msg)
                        alert(data.msg);
                    },
                    error: function (e) {
                        alert("error");
                    }
                })
            }
        }
    </script>
</body>

</html>