VUE篇之时间切片案例

效果如图

思路:

1.首先是时间的切片渲染圆圈和线

2.下一行渲染文本,这里为了让文本居中,转做了一层poastion的定位

<template>
    <div class="root">
        <!-- <textarea v-autosize></textarea> -->
        <div class="box">
            <div v-for="(item, index) in list" :key="index" class="list">
                <el-tooltip class="item" effect="dark" :content="item.start" placement="top">
                    <div :class="['point', { 'small': index % 4 != 0 }, { 'date': date == item.start }]"> </div>
                </el-tooltip>
                <div v-show="index != list.length - 1" class="line"></div>
            </div>
        </div>
        <div class="text">
            <span v-for="(item, index) in list" :key="index" class="word"
                :style="`--width:${index % 4 == 0 ? '22px' : '18px'}`">
                <span> {{ index == list.length - 1 ? item.start : (index % 8 == 0 ? item.start : '') }}</span>
            </span>
        </div>
    </div>
</template>
<script>
import autosize from 'v-autosize';
import moment from 'moment';
export default {
    directives: {
        autosize,
    },
    data() {
        return {
            dialogVisible: false,
            value: '',
            num: 24 * 60 / 15,
            form: {
                start: '2025-01-06 00:00:00',
                end: '2025-01-06 23:59:59'
            },
            list: [],
            date: '08:00'//后端返回值
        }
    },
    mounted() {
        this.time();
    },
    methods: {
        time() {
            const start = moment(this.form.start);
            const end = moment(this.form.end);
            const diff = 1440;
            console.log('时间差', diff);
            const step = Math.floor(diff / this.num);
            console.log('步长', step);
            const list = [];
            for (let index = 0; index < this.num; index++) {
                const s = start.clone().add(index *
                    step, 'minute').format('HH:mm'); const e = start.clone().add((index + 1) *
                        step, 'minute').format('HH:mm'); list.push({ start: s, end: e, });
            }
            this.list = list;
            console.log('时间段', list)
        }
    }
} </script>
<style lang="scss">
.el-textarea__inner {
    height: auto;
}

.root {
    background-color: beige;
    padding: 50px;
    box-sizing: border-box;
}

.box {
    width: 100%;
    box-sizing: border-box;
    display: flex;

    .list {
        display: flex;
        align-items: center;
        height: 12px;

        .point {
            width: 12px;
            height: 12px;
            background-color: white;
            border: 1px solid blue;
            box-sizing: border-box;
            border-radius: 50%;
            cursor: pointer;

            &:hover {
                background-color: pink;
                border-color: pink;
            }
        }

        .small {
            width: 8px;
            height: 8px;
        }

        .date {
            background-color: red;
            border-color: red;

            &:hover {
                background-color: red;
                border-color: red;
            }
        }

        .line {
            width: 10px;
            height: 2px;
            background-color: blue;
        }
    }
}

.text {
    display: flex;
    flex-direction: row;

    .word {
        width: var(--width);
        position: relative;

        span {
            position: absolute;
            left: -50%;
            top: 0;
        }
    }
}
</style>

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值