gaoshp
2024-04-23 88dc89d715828ae485cd00772c0c690b58a7b650
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!--
 * @Date: 2024-04-23 20:03:41
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-23 22:20:35
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/processParam/TimeLine.vue
-->
<template>
    <el-main>
        <el-row>
            <el-col :span="1">
                <el-slider v-model="step" :min="1" :max="4" :step="1" show-stops />
            </el-col>
        </el-row>
        <div class="timeline-box">
            <div class="timeline-box-item" v-for="item in dateList" :key="item.startTime" :style="{
                width: item.width + '%',
                background: item.color
            }">
                {{ item.shiftName }}
            </div>
        </div>
        <div class="timeline-line">
            <div class="timeline-line-item" :class="lines.length - 1 === index ? 'last' : ''"
                v-for="(item, index) in lines" :key="index">
                {{ item.title }}
            </div>
        </div>
    </el-main>
</template>
 
<script>
import moment from 'moment'
export default {
    data() {
        return {
            step: 1,
            params: {},
            dateList: [],
            lines: []
        }
    },
    watch: {
        step() {
            this.setLines()
        }
    },
    methods: {
        init(params) {
            this.params = params
            this.queryTime(params)
            this.setLines()
        },
        getColor(v) {
            if (v.shiftIndex === 1) return { color: 'rgb(211, 174, 248)' }
            return { color: 'rgb(233, 241, 208)' }
        },
        setLines() {
            this.lines = []
            let min = moment(`${this.params.dates[0]} 00:00:00`, 'YYYY-MM-DD HH:mm:ss')
            let max = moment(`${this.params.dates[1]} 24:00:00`, 'YYYY-MM-DD HH:mm:ss')
            let total = max.diff(min)
            let lineNum = total / (this.step * 60 * 60 * 1000)
            console.log(total, lineNum)
            for (let i = 0; i < lineNum; i++) {
                this.lines.push({
                    title: `${i * this.step}:00`
                })
            }
        },
        queryTime(data) {
            if (!data.workstationId) return
            this.$HTTP.post('/api/blade-mdc/process-parameter/all-shift-time', {
                ...data
            }).then(res => {
                if (res.code == 200) {
                    let min = moment(`${this.params.dates[0]} 00:00:00`, 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')
                    let max = moment(`${this.params.dates[1]} 24:00:00`, 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')
                    let full = moment(`${this.params.dates[0]} 00:00:00`, 'YYYY-MM-DD HH:mm:ss').diff(moment(`${this.params.dates[1]} 24:00:00`, 'YYYY-MM-DD HH:mm:ss'))
                    this.dateList = res.data.filter(v => {
                        return moment(v.startTime).isBetween(min, max) || moment(v.endTime).isBetween(min, max)
                    }).map(v => {
                        if (moment(v.startTime).isBetween(min, max) && moment(v.endTime).isBetween(min, max)) {
                            let current = moment(v.startTime, 'YYYY-MM-DD HH:mm:ss').diff(moment(v.endTime, 'YYYY-MM-DD HH:mm:ss'))
                            return {
                                ...v,
                                ...this.getColor(v),
                                width: (current / full * 100).toFixed(2)
                            }
                        } else if (moment(v.startTime).isBetween(min, max)) {
                            let current = moment(v.startTime, 'YYYY-MM-DD HH:mm:ss').diff(moment(max, 'YYYY-MM-DD HH:mm:ss'))
                            return {
                                ...v,
                                ...this.getColor(v),
                                endTime: max,
                                width: (current / full * 100).toFixed(2)
                            }
                        } else {
                            let current = moment(min, 'YYYY-MM-DD HH:mm:ss').diff(moment(v.endTime, 'YYYY-MM-DD HH:mm:ss'))
                            return {
                                ...v,
                                ...this.getColor(v),
                                startTime: min,
                                width: (current / full * 100).toFixed(2)
                            }
                        }
 
                    })
                    console.log(this.dateList, '>>>>>>')
                }
            })
        }
    }
}
</script>
 
<style lang="scss" scoped>
.timeline-box {
    height: 20px;
    display: flex;
 
    &-item {
        text-align: center;
        flex: 0 0 auto;
    }
}
 
.timeline-line {
    display: flex;
    height: 20px;
 
    &-item {
        flex: 1 1 auto;
        padding: 0 3px;
        position: relative;
    }
 
    &-item::before {
        content: "";
        position: absolute;
        left: 0;
        width: 1px;
        height: 10px;
        background: #ccc;
    }
 
    &-item.last::after {
        content: "";
        position: absolute;
        right: 0;
        width: 1px;
        height: 10px;
        background: #ccc;
    }
}
</style>