STKMonitor.js 6.4 KB
layui.config({
    base: "/js/"
}).use(['layer', 'jquery'], function () {
    var layer = layui.layer,
        $ = layui.jquery

    var width = 60;
    var height = 20;
    var STKheight = 40;
    var X = 60;
    var Y = 60;
    var Y2 = Y + (height + STKheight);
    var STK;
    var list = [];
    var STKstate = 1;

    //立库和堆垛机俯视图
    function GetSTK(stk) {
        STK = stk;
        $.ajax({
            async: false,
            url: "/monitor/STKMonitor/GetRow",
            type: "post",
            data: { Roadway: stk },
            dataType: "json",
            success: function (data) {
                list = [];
                arr = data.data;
                arr.forEach(function (e) {
                    $('canvas').drawRect({
                        layer: true,
                        name: "L" + e.Roadway + "" + e.Row + "1",
                        strokeStyle: '#000',
                        strokeWidth: 1,
                        x: X + (width * (e.Row - 1)), y: Y,
                        width: width,
                        height: height,
                    })
                        .drawText({
                            layer: true,
                            name: "T" + e.Roadway + "" + e.Row + "1",
                            fillStyle: '#9cf',
                            strokeStyle: '#25a',
                            strokeWidth: 2,
                            x: X + (width * (e.Row - 1)), y: Y,
                            fontSize: 20,
                            fontFamily: 'Verdana, sans-serif',
                            text: e.Row
                        });
                    $('canvas').drawRect({
                        layer: true,
                        name: "L" + e.Roadway + "" + e.Row + "2",
                        strokeStyle: '#000',
                        strokeWidth: 1,
                        x: X + (width * (e.Row - 1)), y: Y2,
                        width: width,
                        height: height,
                    })
                        .drawText({
                            layer: true,
                            name: "T" + e.Roadway + "" + e.Row + "2",
                            fillStyle: '#9cf',
                            strokeStyle: '#25a',
                            strokeWidth: 2,
                            x: X + (width * (e.Row - 1)), y: Y2,
                            fontSize: 20,
                            fontFamily: 'Verdana, sans-serif',
                            text: e.Row
                        });
                    list.push("L" + e.Roadway + "" + e.Row + "1");
                    list.push("L" + e.Roadway + "" + e.Row + "2");
                    list.push("T" + e.Roadway + "" + e.Row + "1");
                    list.push("T" + e.Roadway + "" + e.Row + "2");
                });
                //堆垛机
                $('canvas').addLayer({
                    type: 'image',
                    name: 'STK' + stk,
                    source: "/images/STK.gif",
                    x: X + (width * (1 - 1)) - (width * 0.7), y: Y + height - (height * 0.4),
                    width: width + (width * 0.5),
                    height: STKheight * 0.8,
                    fromCenter: false
                })
                //报错灯
                $('canvas').addLayer({
                    type: 'arc',
                    name: 'D' + stk,
                    x: X + (width * (1 - 1)), y: Y + 1.5 * height,
                    radius: STKheight * 0.2,
                    opacity: 0,
                    fillStyle: function (layerArc) {
                        if (STKstate == 2) {
                            layerArc.opacity = 0.5;
                            return 'red';
                        }
                    }
                })
            }
        });

        var x = 0;
        setInterval(function () {
            x += 1;
            if (x > 2) {
                STKstate = 2;
            }
            if (STKstate == 2) {
                layer.msg(stk + "号堆垛机超宽!", { icon: 5, shade: 0, time: 2000, shadeClose: true, offset: 'lt', id: 1 });
                $('canvas').animateLayer('D' + stk, {
                    radius: STKheight * 1.5
                }, 1000, function (layer) {
                    $(this).animateLayer(layer, {
                        radius: STKheight * 0.2
                    }, 1000);
                });
            }
        }, 3000);
    }

    function GetStkEcharts(stk) {
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        var option = {
            title: {
                text: stk + '号堆垛机'
            },
            series:
                [{
                    type: 'gauge', radius: '75%', min: 0, max: 10, detail: { fontWeight: 'bold' }, axisLine: {lineStyle: { color: [[0.3, '#91c7ae'], [0.7, '#63869e'], [1, '#c23531']] }} , splitNumber :5, data: [{
                        name: stk + '号状态',
                        value: 2
                    }]
                }
                ]
        };
        myChart.setOption(option);
    }

    $("#STK").change(function () {
        clearInterval(interval);
        Clear();
        GetSTK($("#STK").val());
    });

    function Clear() {
        list.forEach(function (e) {
            $('canvas').removeLayer(e).drawLayers();
        });
        $('canvas').removeLayer("STK" + STK).drawLayers();
        $('canvas').removeLayer("D" + STK).drawLayers();
    }

    function STKMove(stk) {
        for (var i = 2; i < 7; i++) {
            $('canvas').animateLayer('STK' + stk, {
                x: X + (width * (i - 1)) - (width * 0.7), y: Y + height - (height * 0.4),
            }, 1000);
            $('canvas').animateLayer('D' + stk, {
                x: X + (width * (i - 1)), y: Y + 1.5 * height,
            }, 1000);
        }
    }

    $(document).on("click", "#move", function () {
        STKMove($("#STK").val())
    });

    $(document).ready(function () {
        //var connection = new signalR.HubConnectionBuilder()
        //    .withUrl("wss://localhost:44323/chatHub", {
        //        skipNegotiation: true,
        //        transport: signalR.HttpTransportType.WebSockets
        //    })
        //    .build();

        //connection.start().then(function () {
        //}).catch(function (err) {
        //    return console.error(err.toString());
        //});
        GetSTK(1);
        GetStkEcharts(1)
    });
});