Junjie
2023-04-06 cfb75c26838c2e8dacf663e4083484f3b1047ca1
src/main/webapp/views/console.html
@@ -17,50 +17,19 @@
    </header>
    <main class="main">
        <!--楼层按钮-->
            <button class="floorBtn  btn-16" onclick="changFloor(1)" style="margin-top: 150px">1F</button>
            <button class="floorBtn  btn-16" onclick="changFloor(2)" style="margin-top: 200px">2F</button>
            <button class="floorBtn  btn-16" onclick="changFloor(3)" style="margin-top: 250px">3F</button>
            <button class="floorBtn  btn-16" onclick="testMove()" style="margin-top: 250px">测试移动小车</button>
            <div id="floorBtnBox">
                <button class="floorBtn  btn-16" onclick="changFloor(this,1)" style="margin-top: 150px">1F</button>
                <button class="floorBtn  btn-16" onclick="changFloor(this,2)" style="margin-top: 200px">2F</button>
                <button class="floorBtn  btn-16" onclick="changFloor(this,3)" style="margin-top: 250px">3F</button>
                <button class="floorBtn  btn-16" onclick="changFloor(this,4)" style="margin-top: 300px">4F</button>
            </div>
            <button class="floorBtn  btn-16" onclick="testMove()" style="margin-top: 350px">测试移动车</button>
        <!-- 货架 + 堆垛机 + 入库站点 -->
        <div class="main-part">
            <!-- 第一组 -->
            <div class="lane" id="mapDataId" style="margin-bottom: 280px">
                <div class="sxcar" id="sxcar-1"></div>
                <!-- 货架 -->
<!--                <div class="stock-group">-->
<!--                    <button class="item">1</button>-->
<!--                    <button class="item">2</button>-->
<!--                    <button class="item">3</button>-->
<!--                    <button class="item">4</button>-->
<!--                    <button class="item">5</button>-->
<!--                    <button class="item">6</button>-->
<!--                    <button class="item">7</button>-->
<!--                    <button class="item">8</button>-->
<!--                    <button class="item">9</button>-->
<!--                    <button class="item">10</button>-->
<!--                    <button class="item">11</button>-->
<!--                    <button class="item">12</button>-->
<!--                    <button class="item">13</button>-->
<!--                    <button class="item">14</button>-->
<!--                    <button class="item">15</button>-->
<!--                    <button class="item">16</button>-->
<!--                    <button class="item">17</button>-->
<!--                    <button class="item">18</button>-->
<!--                    <button class="item">19</button>-->
<!--                    <button class="item">20</button>-->
<!--                    <button class="item">21</button>-->
<!--                    <button class="item">22</button>-->
<!--                    <button class="item">23</button>-->
<!--                    <button class="item">24</button>-->
<!--                    <button class="item">25</button>-->
<!--                    <span class="row-no">1#</span>-->
<!--                </div>-->
                <!-- 堆垛机 -->
<!--                <div class="crn">-->
<!--                    <hr class="pathway">-->
<!--                    <div id="crn-1" class="machine"></div>-->
<!--                </div>-->
            </div>
        </div>
    </main>
@@ -373,6 +342,8 @@
    var tData1 = []
    var tData2 = []
    var tData3 = []
    var mapData = [] //地图数据
    var currentLev = 1;//当前地图楼层
    function getCodeData(){
        $.ajax({
            url:baseUrl +'/console/barcode/output/site',
@@ -428,13 +399,37 @@
    $(function (){
        initMap()
        initMap(1)
    })
    setInterval(() => {
        getShuttleStateInfo()
    },1000)
    // 四向穿梭车信息表获取
    function getShuttleStateInfo() {
        $.ajax({
            url: baseUrl+ "/shuttle/table/shuttle/state",
            headers: {'token': localStorage.getItem('token')},
            method: 'POST',
            success: function (res) {
                res.data.forEach((item,index) => {
                    if(item.locNoLev != currentLev){
                        //四向穿梭车楼层和当前地图楼层不一致,删除该车辆
                        $("#sxcar-" + item.shuttleNo).remove()
                    }else {
                        //移动四向穿梭车
                        moveCar(item.shuttleNo,item.locNoX,item.locNoY)
                    }
                })
            }
        });
    }
    //计算四向穿梭车图标位置
    function getCarPosition(x,y) {
        let top = (x * 30) + "px"
        let left = (y * 40 - 40) + "px" //需要减去小车自己所占宽度
        let top = (x * 35 - 35) + "px" //需要减去小车自己所占高度
        let left = (y * 70 - 70) + "px" //需要减去小车自己所占宽度
        return [top,left];
    }
@@ -444,22 +439,21 @@
        let position = getCarPosition(x,y)
        let top = position[0]
        let left = position[1]
        console.log(top,left)
        $("#sxcar-" + id).animate({top: top,left: left}, 1000);
    }
    //初始化地图
    function initMap() {
    function initMap(lev) {
        //母轨道第一次索引,用于定位小车
        let firstMotherIndex = [0,0];
        $("#mapDataId").empty()
        $.ajax({
            type:"get",
            url: baseUrl + "/static/js/map.json",
            success: (data) => {
                mapData = data
                let content = ""
                data.forEach((rowData,index) => {
                    let lastGroup = '<div class="stock-group">'
                    //去掉上下边缘禁区
                    if(!(index == 0 || data.length - 1 == index)){
                        let row = '<div class="stock-group">';
@@ -467,9 +461,8 @@
                            //去掉左右边缘禁区
                            if(!(idx == 0 || rowData.length - 1 == idx)){
                                let col;
                                switch (colData){
                                switch (colData.value){
                                    case -1:
                                        //-1禁区不显示,但是需要占用元素位置
                                        col = '<button class="item" style="visibility: hidden">' + idx + '</button>';
                                        break;
                                    case 3:
@@ -480,32 +473,72 @@
                                            firstMotherIndex = [index,idx]
                                        }
                                        break;
                                    case 4:
                                        //站点
                                        if (lev == 1) {
                                            let data = colData.data;
                                            col = '<div id="site-' + data + '" class="site">' + data + '(9991)</div>';
                                        }else {
                                            //其他楼层只有提升机能显示
                                            let data = colData.data;
                                            if (data == 109) {//其他楼层只有提升机能显示
                                                col = '<div id="site-' + data + '" class="site">' + data + '(9991)</div>';
                                            }else {
                                                col = '<div style="visibility: hidden" id="site-' + data + '" class="site">' + data + '(9991)</div>';
                                            }
                                        }
                                        break;
                                    default:
                                        col = '<button class="item">' + index + '</button>';
                                        col = '<button class="item">' + idx + '</button>';
                                }
                                if(data.length - 2 == index){
                                    //到达真实数据的最后一行,打上行数标记
                                    lastGroup += '<button class="item">' + idx + '#</button>';
                                if(rowData.length - 2 == idx){
                                    //打上行数标记
                                    col += '<span class="row-no">' + index + '#</span>';
                                }
                                row += col
                            }
                        })
                        lastGroup += '</div>';
                        row += lastGroup;
                        row += '</div>';
                        content += row
                    }
                })
                moveCar(1, firstMotherIndex[0], firstMotherIndex[1]);
                $("#mapDataId").append(content)
            }
        })
        $.ajax({
            url: baseUrl+ "/shuttle/table/shuttle/state",
            headers: {'token': localStorage.getItem('token')},
            method: 'POST',
            success: function (res) {
                res.data.forEach((item,index) => {
                    if(lev == item.locNoLev){
                        let carBox = '<div class="sxcar" id="sxcar-' + item.shuttleNo + '"></div>'
                        $("#mapDataId").append(carBox)
                    }
                })
            }
        });
    }
    //将地图数据转换成int二维数组(后续用于请求计算路径时携带地图数据参数使用)
    function getMap2TwoArr() {
        let data = []
        mapData.forEach((item,index) => {
            let data2 = []
            item.forEach((val,idx) => {
                data2.push(val.value)
            })
            data.push(data2)
        })
        return data;
    }
    function testMove() {
        getMap2TwoArr()//测试地图数据转换是否正常
        let json = "[{\n" +
            "\t\t\"x\": 5,\n" +
            "\t\t\"y\": 5\n" +
@@ -659,7 +692,7 @@
</script>
<script type="text/javascript">
    // 弹窗站点信息
    $('.site').on('click',function(){
    $('#mapDataId').on('click','.site',function(){
        var id = this.id.split("-")[1];
        $("#siteWindow").attr("style","display:block;");//显示div
        $("#crnWindow").attr("style","display:none;");
@@ -951,74 +984,6 @@
        }
    }
    // 页面点击事件监听 ---------------------------------------------------------
    // 输送设备点击事件
    // $('.site').on('click', function () {
    //    var id = this.id.split("-")[1];
    //    if (id === undefined) {
    //       return;
    //    }
    //    layer.open({
    //       title: id + " 站点信息详情",
    //       closeBtn: 0,
    //       skin: 'layui-layer-lan',
    //       offset: '180px',
    //       type: 1,
    //       shadeClose: true,
    //       content: $('#siteWindow'),
    //       area: ['35rem', '18rem'],
    //       btn: ['确定', '关闭'],
    //       success: function(layero, index){
    //          http.post(baseUrl+"/console/site/detail", {siteId: id}, function (res) {
    //             for (var val in res.data) {
    //                var find = $("#siteWindow").find(":input[name='" + val + "']");
    //                if (find[0].type==='text') {
    //                   find.val(res.data[val]);
    //                } else if (find[0].type === 'checkbox') {
    //                   find.attr("checked", res.data[val] === 'Y');
    //                }
    //             }
    //          })
    //       },
    //       end: function () {
    //          $(':input', $("#siteWindow")).val('').removeAttr('checked').removeAttr('selected');
    //       }
    //    });
    // });
    // 堆垛机点击事件
    // $('.machine').on('click', function () {
    //    var id = this.id.split("-")[1];
    //    layer.open({
    //       title: id+"号堆垛机",
    //       skin: 'layui-layer-lan',
    //       closeBtn: 0,
    //       type: 1,
    //       offset: '150px',
    //       shadeClose: true,
    //       content: $("#crnWindow"),
    //       area: ['40rem', '20rem'],
    //       btn: ['确定', '关闭'],
    //       success: function(layero, index){
    //          http.post(baseUrl+"/console/crn/detail", {crnNo: id}, function (res) {
    //             for (var val in res.data) {
    //                var find = $("#crnWindow").find(":input[name='" + val + "']");
    //                if (find[0].type==='text') {
    //                   find.val(res.data[val]);
    //                } else if (find[0].type === 'checkbox') {
    //                   find.attr("checked", res.data[val] === 'Y');
    //                }
    //             }
    //          })
    //       },
    //       end: function () {
    //          $(':input', $("#crnWindow")).val('').removeAttr('checked').removeAttr('selected');
    //       }
    //    });
    // });
    // 小车偏移动画
    function carAnimate(id, target) {
        var targetTop = 122;
@@ -1048,29 +1013,14 @@
        $("#site-" + id).animate({top: targetTop+'px'}, 1000);
    }
     //楼层切换按钮
    function changFloor(x) {
        switch (x) {
            case 1:
                $('#fool1').css("display","block")
                $('#fool2').css("display","none")
                $('#fool3').css("display","none")
                return
            case 2:
                $('#fool1').css("display","none")
                $('#fool2').css("display","block")
                $('#fool3').css("display","none")
                return
            case 3:
                $('#fool1').css("display","none")
                $('#fool2').css("display","none")
                $('#fool3').css("display","block")
                return
            default:
                return;
        }
    function changFloor(e,x) {
        $("#floorBtnBox button").each((index,item) => {
            $(item).removeClass("btn-16-active")
        })
        $(e).addClass("btn-16-active")
        currentLev = x
        initMap(currentLev)
    }
</script>