gaoshp
2024-04-25 35e855008db4be8a859d674ff937db4131760903
甘特图
已修改1个文件
288 ■■■■ 文件已修改
src/views/mdc/processParam/index.vue 288 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/mdc/processParam/index.vue
@@ -1,7 +1,7 @@
<!--
 * @Date: 2024-04-09 22:11:21
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-24 23:41:35
 * @LastEditTime: 2024-04-25 21:53:21
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/processParam/index.vue
 实时看板
-->
@@ -23,7 +23,7 @@
                    <el-main v-show="list.length > 0">
                        <el-row>
                            <el-col :span="4">
                                <el-switch v-model="isShowTable" class="mb-2" active-text="数据表" inactive-text="统计图" />
                                <!-- <el-switch v-model="isShowTable" class="mb-2" active-text="数据表" inactive-text="统计图" /> -->
                            </el-col>
                            <el-col :span="20" style='text-align: right;'>
                                <el-date-picker :max-range="3" :clearable="false" value-format="YYYY-MM-DD"
@@ -39,21 +39,14 @@
                                <div>
                                    <el-button>查看数据</el-button>
                                </div>
                                <scEcharts style="width:100%" height="300px" :option="dayCharts">
                                <scEcharts v-if="item?.dayCharts?.xAxis" style="width:100%" height="300px"
                                    :option="item?.dayCharts">
                                </scEcharts>
                                <!-- <scTable v-show="isShowTable" ref="table0" row-key="id" border :apiObj="item.apiObj"
                                    stripe>
                                    <el-table-column prop="alarmCode" label="报警代码" />
                                    <el-table-column prop="alarmMsg" label="报警信息" />
                                    <el-table-column prop="count" label="报警次数" />
                                </scTable> -->
                            </el-collapse-item>
                        </el-collapse>
                    </el-main>
                    <el-main v-show="list.length == 0">
                        <!-- <el-empty description="暂无数据" /> -->
                        <scEcharts style="width:100%" height="300px" :option="dayCharts">
                        </scEcharts>
                        <el-empty description="暂无数据" />
                    </el-main>
                </el-container>
            </el-container>
@@ -66,42 +59,42 @@
import scEcharts from '@/components/scEcharts';
import TimeLine from './TimeLine.vue'
import MYTree from '../MYTree.vue'
const rawData = [
    [100],
    [320],
    [220],
    [150],
    [820]
]
const totalData = [];
for (let i = 0; i < rawData[0].length; ++i) {
    let sum = 0;
    for (let j = 0; j < rawData.length; ++j) {
        sum += rawData[j][i];
    }
    totalData.push(sum);
}
const series = [
    '运行',
    '运行',
    '运行',
    '待机',
    '运行'
].map((name, sid) => {
    return {
        name,
        type: 'bar',
        stack: 'total',
        barWidth: '20px',
        label: {
            show: true,
            formatter: (params) => Math.round(params.value * 1000) / 10 + '%'
        },
        data: rawData[sid].map((d, did) =>
            totalData[did] <= 0 ? 0 : d / totalData[did]
        )
    };
});
// const rawData = [
//     [100],
//     [320],
//     [220],
//     [150],
//     [820]
// ]
// const totalData = [];
// for (let i = 0; i < rawData[0].length; ++i) {
//     let sum = 0;
//     for (let j = 0; j < rawData.length; ++j) {
//         sum += rawData[j][i];
//     }
//     totalData.push(sum);
// }
// const series = [
//     '运行',
//     '运行',
//     '运行',
//     '待机',
//     '运行'
// ].map((name, sid) => {
//     return {
//         name,
//         type: 'bar',
//         stack: 'total',
//         barWidth: '20px',
//         label: {
//             show: true,
//             formatter: (params) => Math.round(params.value * 1000) / 10 + '%'
//         },
//         data: rawData[sid].map((d, did) =>
//             totalData[did] <= 0 ? 0 : d / totalData[did]
//         )
//     };
// });
// let data = {
//     "collectItem": "设备状态",
//     "collectRealItem": "DeviceStatus",
@@ -153,7 +146,7 @@
//     zlevel: -1,
//     data: [item.time]
// }))
console.log('>>>>>>>>????', series)
// console.log('>>>>>>>>????', series)
export default {
    components: {
        TimeLine,
@@ -169,13 +162,14 @@
        },
        timeRange(val) {
            console.log(val, '>>>>>>>???/')
            this.queryChart()
        }
    },
    data() {
        return {
            isShowTable: false,
            list: [],
            activeList: [0],
            activeList: [0, 1, 2, 3, 4, 5, 6, 7, 8],
            timeRange: '',
            treeChecked: [],
            timeStart: moment().format('YYYY-MM-DD'),
@@ -185,27 +179,21 @@
                let min = moment(this.timeStart, 'YYYY-MM-DD').subtract(3, 'd').format('YYYY-MM-DD')
                return !moment(Date).isBetween(min, max);
            },
            dayCharts: {
                legend: [
                ],
                title: {
                    text: '设备状态统计图',
                    subtext: '',
                },
                yAxis: {
                    type: 'category',
                    data: ['']
                },
                xAxis: {
                    type: 'value',
                },
                series
            }
            dayCharts1: {
            },
            dayCharts2: {
            },
            dayCharts3: {
            },
            dayCharts4: {
            },
            dayCharts5: {
            },
        }
    },
    created() {
        console.log('---------')
        console.log(series)
        // console.log(series)
    },
    methods: {
        init() {
@@ -223,81 +211,105 @@
            this.$HTTP.get('/api/blade-mdc/process-parameter/param', { workstationId: this.treeChecked.toString() }).then(res => {
                if (res.code === 200) {
                    this.list = res.data
                    // this.queryChart(res.data[0])
                    this.queryChart()
                }
            })
        },
        queryChart(dmpDTO) {
            // this.$HTTP.post('/api/blade-mdc/process-parameter/chart/dmp-item', {
            //     methodEnum: "HOUR",
            //     startTime: this.timeRange.startTime,
            //     endTime: this.timeRange.endTime,
            //     workstationId: this.treeChecked.toString(),
            //     dmpDTO
            // })
            let data = {
                "collectItem": "设备状态",
                "collectRealItem": "DeviceStatus",
                "data": [
                    {
                        "time": "2024-04-24 10:00:00",
                        "name": "运行",
                        "color": "#73D13D",
                        "value": "2"
                    },
                    {
                        "time": "2024-04-24 10:30:00",
                        "name": "运行",
                        "color": "#73D13D",
                        "value": "2"
                    },
                    {
                        "time": "2024-04-24 11:30:00",
                        "name": "运行",
                        "color": "#73D13D",
                        "value": "2"
                    },
                    {
                        "time": "2024-04-24 11:40:00",
                        "name": "待机",
                        "color": "#FFC53D",
                        "value": "3"
                    },
                    {
                        "time": "2024-04-24 12:00:00",
                        "name": "待机",
                        "color": "#FFC53D",
                        "value": "3"
                    },
                    {
                        "time": "2024-04-24 12:00:00",
                        "name": "运行",
                        "color": "#73D13D",
                        "value": "2"
        queryChart() {
            this.queryChart1()
        },
        queryChart1() {
            this.dayCharts = {}
            this.$HTTP.post('/api/blade-mdc/process-parameter/chart/dmp-item', {
                methodEnum: "HOUR",
                startTime: this.timeRange.startTime,
                endTime: this.timeRange.endTime,
                workstationId: this.treeChecked.toString(),
                workstationName: '461',
                dmpDTO: {
                    "collectItem": "设备状态",
                    "collectRealItem": "DeviceStatus",
                    "legend": null,
                    "chartType": "line",
                    "id": "1699225758611169281",
                    "dmpDeviceId": "591",
                    "name": "DeviceStatus",
                    "description": "设备状态",
                    "dataType": 3,
                    "wcsDataType": 1,
                    "processParameter": true,
                    "data": [],
                    "timeRange": [
                        "2024-04-25 00:00:00",
                        "2024-04-25 02:00:00"
                    ]
                }
            }).then(res => {
                let data = res.data
                let total = Math.abs(moment(this.timeRange.startTime).diff(moment(this.timeRange.endTime)))
                let start = this.timeRange.startTime
                let series = data.data.map((item, i) => {
                    let current = Math.abs(moment(start).diff(moment(item.time)))
                    console.log(current, total)
                    start = item.time
                    let name = i === 0 ? '' : data.data[i - 1].name
                    let color = !name ? 'transparent' : data.data[i - 1].color
                    return {
                        name,
                        type: 'bar',
                        stack: 'total',
                        barWidth: '20px',
                        data: [current / total * 60],
                        label: {
                            show: true,
                            position: 'center',
                            color: '#FFF',
                            formatter: params => {
                                if (i == 0) return ''
                                return `开始时间${moment(data.data[i - 1].time).format('HH:mm')}-${moment(item.time).format('HH:mm')}`
                            }
                        },
                        itemStyle: {
                            color, // 这一行固定的颜色值需要删除或注释
                            borderColor: '#FFF',
                            borderWidth: 1
                        },
                    }
                ]
            }
            // {
            //     name: '运行',
            //         type: 'bar',
            //             stack: 'duration',
            //                 itemStyle: {
            //         color: '#007acc',
            //             borderColor: '#fff',
            //                 borderWidth: 1
            //     },
            //     zlevel: -1,
            //         data: ['2024-04-24 10:00:00'] // 结束时间
            // }
            // this.dayCharts.series = [...data.data.map(item => ({
            //     name: item.name,
            //     stack: 'duration',
            //     itemStyle: {
            //         color: item.color,
            //     },
            //     zlevel: -1,
            //     data: [item.time]
            // }))]
                })
                let arr = [12, 8, 9, 4]
                let splitNumber = arr[Math.abs(moment(this.timeRange.startTime).diff(moment(this.timeRange.endTime))) / 3600000 - 1]
                let dayCharts = {
                    legend: [
                    ],
                    title: {
                        text: '设备状态统计图',
                        subtext: '',
                    },
                    yAxis: {
                        type: 'category',
                        data: ['']
                    },
                    series,
                    xAxis: {
                        type: 'value',
                        splitNumber,
                        axisLabel: {
                            formatter: (value, index) => {
                                let start = moment(this.timeRange.startTime)
                                let ms = Math.abs(moment(this.timeRange.startTime).diff(moment(this.timeRange.endTime))) / splitNumber * index
                                // console.log(ms, index, '>>>>>>>>>刻度', Math.abs(moment(this.timeRange.startTime).diff(moment(this.timeRange.endTime))))
                                return ''
                            }
                        },
                    },
                }
                let index = this.list.findIndex(item => item.name === 'DeviceStatus')
                this.list[index] = Object.assign({
                    ...this.list[index],
                    dayCharts
                })
                console.log('>>>>>>>>>>>>>>.......', series)
            })
        },
        change(e) {
            this.timeStart = e[0] || moment().format('YYYY-MM-DD')