bodyCenter.vue 7.48 KB
<template>
    <div>
        <div class="stuts-style" style="padding-top: 2px;">
            <span class="div-span-title">生产订单进度(当天)</span>
            <div class="inner-div">
                <!-- 运行状态 -->
                <div class="status-item run">
                    <div class="status-dot run"></div>
                    <span class="status-text">运行</span>
                </div>
                <div class="status-item standby">
                    <div class="status-dot standby"></div>
                    <span class="status-text">空闲</span>
                </div>
                <!-- 故障状态 -->
                <div class="status-item error">
                    <div class="status-dot error"></div>
                    <span class="status-text">故障</span>
                </div>
            </div>
        </div>
        <div id="planLine" style="width: 100%;height: 83%;"></div>
    </div>
</template>

<!--趋势图-->
<script>

export default {
    data() {
        return {
            // 各自动仓库状况
            baseUrlOff: 'http://127.0.0.1:6001/api/BulletinBoard/Mes/V1/ReadData5',
            baseUrlOnLine: window.appConfig.baseUrlOnLine5,

            sysData: {
                getwarehouseHealth: null,
            },
            tempEcharts: [
                { name: 'SRM32', index: null },
                { name: 'SRM31', index: null },
                { name: 'SRM21', index: null },
                { name: 'SRM11', index: null },
                { name: 'SRM41', index: null },
                { name: 'SRM11_PLCHeatBeat', index: null },
                { name: 'SRM21_PLCHeatBeat', index: null },
                { name: 'SRM31_PLCHeatBeat', index: null },
                { name: 'SRM32_PLCHeatBeat', index: null },
                { name: 'SRM41_PLCHeatBeat', index: null },
            ],
            getwarehouseHealth: null,
            planLineOption: planLineOption,
            info: {
                CutQuantity: 0,
                PipeQuantity: 0
            }
        }
    },
    methods: {
        // 中间柱状图
        getData() {
            let opt = {
                urlSuffix: window.baseOnLineOrOff ? this.baseUrlOnLine : this.baseUrlOff,
                logTitle: '中间柱状图',
                isUrlALL: true,
                headers: window.baseOnLineOrOff,
                // header: window.baseOnLineOrOff,
            }
            let callBackFn = (res) => {
                if (!this.ajaxSuccessDataBefore(res, opt.logTitle)) return
                this.sysData.getwarehouseHealth = res.data.data
                // this.dataAnalysis(res.data.data)
                this.getwarehouseHealthbar(res.data.data)
            }
            ''.ajax(this, opt, callBackFn)
        },
        dataAnalysis(data) {
            //获取数据下标,用于数据对应name渲染
            data.x.forEach((x, index) => {
                if (x == 'SRM32') {
                    this.tempEcharts[0].index = index
                }
                if (x == 'SRM31') {
                    this.tempEcharts[1].index = index
                }
                if (x == 'SRM21') {
                    this.tempEcharts[2].index = index
                }
                if (x == 'SRM11') {
                    this.tempEcharts[3].index = index
                }
                if (x == 'SRM41') {
                    this.tempEcharts[4].index = index
                }
                if (x == 'SRM11_PLCHeatBeat') {
                    this.tempEcharts[5].index = index
                }
                if (x == 'SRM21_PLCHeatBeat') {
                    this.tempEcharts[6].index = index
                }
                if (x == 'SRM31_PLCHeatBeat') {
                    this.tempEcharts[7].index = index
                }
                if (x == 'SRM32_PLCHeatBeat') {
                    this.tempEcharts[8].index = index
                }
                if (x == 'SRM41_PLCHeatBeat') {
                    this.tempEcharts[9].index = index
                }
            })
        },
        // 中间柱状图
        getwarehouseHealthbar(rawData) {
            // const dates = rawData.map(item => item.CurryDate);
            // const quantities = rawData.map(item => item.Quantity);
            let myChart = this.$echarts.init(document.getElementById('planLine'))
            // this.warehouseHealthOption.xAxis.data = dates
            // this.warehouseHealthOption.series[0].data = quantities
            myChart.clear()
            myChart.setOption(this.planLineOption)
            window.addEventListener('resize', () => {
                myChart.resize();
            });
        },
        setInfo(data) {
            this.info = data;
        },
        sortedData(data) {
            return data.slice().sort((a, b) => {
                return new Date(a.CurryDate) - new Date(b.CurryDate); // 升序:早 → 晚
                // return new Date(b.CurryDate) - new Date(a.CurryDate); // 降序:晚 → 早
            });
        },
        monthDayDates(data) {
            return data.map(date => {
                const [year, month, day] = date.split('-');
                return `${month}-${day}`;
            });
        },
        ajaxSuccessDataBefore(res, title) {
            if (res.data == null || res.data.data.length == 0) {
                ''.Log(title + '无数据', 'getData')
                return false
            }
            return true
        },
    },
    mounted() {
        // this.getData()
        // const item = {
        //     x: ['1号堆垛机', '1号RGV', '2号RGV'],
        //     running: [50, 40, 44],
        //     free: [49, 59, 55],
        //     error: [1, 1, 0.9],
        // }
        this.getwarehouseHealthbar()
    },
}
</script>

<style lang="less" scoped>
.stuts-style {
    display: flex;
    height: 5vh;
    font-weight: 800;
    font-size: 1vw;
    color: aliceblue;
    text-indent: 1vw;
    box-sizing: border-box;

    .div-span-title {
        font-size: 2vh;
        font-weight: 600;
        margin-top: 0.6vh;
    }

    /* 右侧小div容器 */
    .inner-div {
        width: 50%;
        /* 占大div的50%宽度 */
        height: 100%;
        /* 与大div同高 */
        margin-left: auto;
        /* 靠右对齐 */
        display: flex;
        /* 启用flex布局,用于内部子元素排列 */
    }

    /* 三个子div的共同样式 */
    .status-item {
        flex: 1;
        /* 均等分配宽度 */
        height: 100%;
        /* 与父元素同高 */
        display: flex;
        /* 内部flex布局,用于排列方块和文字 */
        align-items: center;
        /* 垂直居中 */
        justify-content: center;
        /* 水平居中 */
        padding: 0 4px;
        /* 减少左右内边距,使整体更紧凑 */
    }

    /* 状态指示小方块 - 缩小与文字的间距 */
    .status-dot {
        width: 10px;
        /* 方块宽度 */
        height: 10px;
        /* 方块高度 */
        margin-right: -6px;
        /* 减小右外边距(原6px),拉近与文字的距离 */
        border-radius: 1px;
        /* 轻微圆角 */
    }

    /* 运行状态的绿色方块 */
    .status-dot.run {
        background-color: #00d485;
        /* 深绿色 */
    }

    /* 待机状态的黄色方块 */
    .status-dot.standby {
        background-color: #ffab20;
        /* 深黄色 */
    }

    /* 故障状态的红色方块 */
    .status-dot.error {
        background-color: #ff5447;
        /* 深红色 */
    }

    // .status-text {
    //     color: #0eadfc;
    // }
}
</style>