• 动态样式:根据时间长短绘制色块宽度和颜色,鼠标hover显示具体信息


    目标效果:

    在这里插入图片描述

    代码:

    根据时间长短绘制色块宽度和颜色::style="getListStyle(car)"
    鼠标hover显示具体信息:display:none;——>.car:hover{display:block;}

    <template>
        <div class="account">
            <div class="query">
                <div class="center-between">
                    <div class="center-left">
                        <el-form-item label="日期">
                            <el-date-picker v-model="date" type="date" placeholder="选择日期"
                                             value-format="yyyy-MM-dd">
                            el-date-picker>
                        el-form-item>
                        <el-form-item label="值次">
                            <el-select v-model="shift" placeholder="请选择" :options="shiftList">el-select>
                        el-form-item>
                        <el-form-item label="受入侧">
                            <el-select v-model="areaCode" placeholder="请选择" multiple :options="areaCodeList">el-select>
                        el-form-item>
                    div>
                    <div class="center-right">
                        <el-button class="btn" type="primary" @click="handleqQuery()">查询el-button>
                        <el-button class="btn" type="info" plain @click="handleqReset()"> 重置el-button>
                    div>
                div>
            div>
            <div class="list">
                
                <table>
                    <tr v-for="(e,index) of carList">
                        <td class="bg-car">{{ e }}td>
                        <td v-for="(e,index) of numX">td>
                    tr>
                table>
                
                <div class="cars">
                    
                    <div class="car" :style="getListStyle(car)" v-for="(car, index) in carValueList">
                        {{car.srGrpNo}}
                        <div class="car-tip" :class="getListStyle(car)">
                            <div class="tip-title" >{{car.srGrpNo}}div>
                            <div class="tip-text">
                                <span>计划:{{car.arriveTime.substr(11)}} span>
                                <img src="https://img-blog.csdnimg.cn/a2cec2715a81457b823f385d0a291d00.png"/>
                                <span> {{car.departureTime.substr(11)}}span>
                            div>
                            <div v-if="car.actualArriveTime" class="tip-text">
                                <span>实际:{{car.actualArriveTime? car.actualArriveTime.substr(11) : ''}} span>
                                <img src="https://img-blog.csdnimg.cn/a2cec2715a81457b823f385d0a291d00.png"/>
                                <span> {{car.actualDepartureTime ? car.actualDepartureTime.substr(11) : ''}}span>
                            div>
                        div>
                    div>
                div>
            div>
        div>
    template>
    
    <script>
        export default {
            props: {
                context: Object,
                data: {
                    default: ''
                }
            },
            data() {
                return {
                    carMap: {},
                    carList: [],
                    carValueList: [],
                    top: 10, // 色块top值
                    isShowTable: false,
                    date:'',
                    shift: '', // D-白班,N-夜班)
                    areaCode: '',  // 受入侧4(T侧)
                    numX: [1,2,3,4,5,6,7,8,9,10,11,12],// 车位背景图渲染12个空列
                    areaCodeList:[
                        {
                            label: 'T侧',
                            value: '4'
                        }
                    ],
                    shiftList: [
                        {
                            label: '白班',
                            value: 'D'
                        },
                        {
                            label: '夜班',
                            value: 'N'
                        },
                    ],
                    timer: '',
                }
            },
            mounted() {
                this.$nextTick(() => {
                    this.initData()
                    this.onLoop()
                })
            },
            beforeDestroy(){
                clearInterval(this.timer)
            },
            methods: {
                handleqQuery(){
                    // 更新班次
                    let params ={
                        areaCode: this.areaCode,
                        shift: this.shift,
                        date: this.date,
                    }
                    this.getData(params)
                },
                handleqReset() {
                    this.areaCode = ''
                    this.date = ''
                    this.shift = ''
                },
                initData(){
                    let time = new Date();
                    let t1 = new Date(time.toLocaleDateString() + " 20:30:00")
                    let diffMinute = time - t1
                    if(diffMinute >= 0){
                        this.shift = 'N'
                    } else {
                        this.shift = 'D'
                    }
                    // 更新班次
                    this.date = this.formatDate(new Date())
                    let params = {
                        areaCode: this.areaCode,
                        shift: this.shift,
                        date: this.formatDate(new Date()),
                        start: 1,
                        limit: 50,
                    }
                    this.getData(params)
                },
                getData(params){
                    //  整合返回值转换key为车位
                    this.carMap = new Map()
                    this.carList = []
                    this.carValueList = []
                    this.top = 0
                    this.$request.post('your address',params).then(res => {
                        if (res.data.code == 0  && res.data.data) {
                            let resData = res.data.data
                            if(resData.length > 0){
                                for(let item of resData){
                                    this.carMap.set(item.carCode, item)
                                }
                                this.top = 10
                                //  整合返回值转换key为车位
                                this.carList = [...this.carMap.keys()]
                                for(let k = 0; k < this.carList.length; k++){
                                    for(let j = 0; j < resData.length; j++){
                                        if( this.carList[k] == resData[j].carCode){
                                            resData[j].top = 10 + k * 60
                                            this.carValueList.push(resData[j])
                                        }
                                    }
                                }
                                console.log('carValueList',this.carValueList)
                            }
                        }
    
                    })
                },
                onLoop() {
                    this.timer = setInterval(this.handleqQuery, 300000)
                },
                formatDate(val){
                    let d = new Date(val)
                    let month = (d.getMonth() +1).toString()
                    let day = (d.getDate()).toString()
                    let year = d.getFullYear()
                    if(month.length < 2) month = '0' + month
                    if(day.length < 2) day = '0' + day
                    return [year, month, day].join('-')
                },
                getListStyle(item) {
                    // 计算色块宽度
                    let arriveTime = new Date(item.arriveTime)
                    let departureTime = new Date(item.departureTime)
                    let width = (departureTime - arriveTime)/1000/60
                    // 计算色块开始位置
                    let start = ''
                    let t1 = new Date(arriveTime.toLocaleDateString() + " 8:30:00")
                    let t2 = new Date(arriveTime.toLocaleDateString() + " 20:30:00") // 若时间超过24点则不能用t2做差,此时t2日期已经加一
                    let t3 = new Date(arriveTime.toLocaleDateString() + " 20:30:00") // 复制t2,避免引用类型联动改变t2
                    t3.setDate((t3.getDate()-1)) // t2基础上时间减1天
                    if(this.shift === 'N'){ // 超过20:30
                        if(arriveTime < t1){
                            start = (arriveTime - t3)/1000/60
                        }else {
                            start = (arriveTime - t2)/1000/60
                        }
                    }else{
                        start = (arriveTime - t1)/1000/60
                    }
                    // 计算颜色
                    let color = ''
                    switch (item.type){
                        case '0':
                            color = '#C6CBD8'
                            break
                        case '1':
                            color = '#67B662'
                            break
                        case '2':
                            color = ' #5AB9ED'
                            break
                        case '5':
                            color = '#E03523'
                            break
                        case '3':
                            color = ' #FFE329'
                            break
                        case '4':
                            color = '#FFE329'
                            break
                    }
                    return `left: ${start*2}px; top: ${item.top}px; width: ${width}px; background-color: ${color};`
                }
            },
    
        }
    script>
    
    <style>
        .account{
            width: 100%;
            height: 100%;
            position: absolute;
            overflow: hidden;
    
        }
        /*=====================================查询部分*/
        .account .query{
            width: 100%;
            height: 13%;
        }
        .account .center-between{
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            font-family: MicrosoftYaHei;
            font-size: 20px;
            color: #2E3B4C;
            letter-spacing: 0.71px;
            font-weight: 400;
        }
        .account .center-left{
            width: 45%;
            padding-left: 2%;
            display: flex;
            flex-direction: row;
            justify-content: space-between;
        }
        .account .center-right{
            width: 55%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: flex-end;
            padding-right: 3%;
        }
        .account .btn{
            width: 15%;
            height: 42%;
            border-radius: 8px;
            font-size: 20px;
            font-weight: 400;
        }
        /*=====================================车次展示部分*/
        .account .list {
            width: 100%;
            height: 87%;
            position: relative;
        }
        /*空白表格背景*/
        .account table{
            /*width: 93%;*/
            border: 1px solid rgba(181,188,198,0.70);
            border-collapse: collapse;
            margin: 5% auto;
        }
        .account table tr{
            height: 60px;
        }
        .account table td {
            width: 120px;
            border-right: 1px dashed #B5BCC6;
        }
        .account table tr:nth-child(even)
        {
            background: #EDEFF2;
        }
        .account table tr:nth-child(odd)
        {
            background: #fff;
        }
        .account .list .bg-car{
            background-image: url("https://img-blog.csdnimg.cn/5ca5eabffec2497c9265ec11d117fed2.png");
            background-position: center;
            background-repeat: no-repeat;
            color: white;
            font-size: 22px;
            text-align: center;
        }
        /* 彩色车次展示*/
        .account .list .cars {
            width: 75%;
            height: 74%;
            position: absolute;
            /*background: #EDEFF2;*/
            top: 0;
            left: 298px;
        }
        .account .list .car {
            position: absolute;
            border-radius: 3px;
            height: 38px;
        }
        /*鼠标悬停显示详情*/
        .account .car .car-tip{
            width: 200px;
            height: 100px;
            display: none;
            background: #FFFFFF;
            box-shadow: 0 10px 20px 0 rgba(183,175,175,0.30);
            border-radius: 4px;
            padding: 15px 10px;
        }
        .account .car:hover .car-tip{ 
            /* 鼠标经过时展示从none变为block */
            display: block; 
        }
        .account .car .car-tip .tip-title{
            font-family: MicrosoftYaHei-Bold;
            font-size: 16px;
            color: #2E3B4C;
            letter-spacing: 0;
            font-weight: 700;
            border-left: 4px solid #3A64E8;
            padding-left: 5px;
            line-height: 16px;
            margin-bottom: 5px;
        }
        .account .car .car-tip .tip-text{
            font-family: MicrosoftYaHei;
            font-size: 14px;
            color: #2E3B4C;
            letter-spacing: 0;
            font-weight: 400;
        }
    
    style>
    
    
    • 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
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
  • 相关阅读:
    Linux编译器 -- gcc/g++ 调试器 -- gdb
    支付宝电脑网站支付
    .NET Reactor简单使用教程
    b2b2c o2o 多商家入驻商城 直播带货商城 电子商务
    ST‐LINK V2 使用说明(安装,调试,烧录)
    1034. 边界着色-深度优先遍历
    pygame实现飞机大战游戏
    redisson分布式锁
    焦炉加热系统简述
    SAP中维修备件(库存物料)可以向一次性供应商采购吗?
  • 原文地址:https://blog.csdn.net/weixin_43361722/article/details/126001747