当前位置:网站首页>vant3 +ts 封装简易step进步器组件

vant3 +ts 封装简易step进步器组件

2022-06-12 17:41:00 热忱学习

 

公司需要这样的step 进度条,vant组件提供的有点难改,所以自己就在网上找了一个,做了一些改动

 step 组件 用的时候改变stepActive的值

<template>
    <div style="background-color: white">
        <div class="steps">
            <div class="step" v-for="(i, index) in stepList" :key="index">
                <div class="step-head" :class="
                    activeValue == i.stepIndex || i.stepIndex <= activeValue
                        ? 'step-finish'
                        : 'step-wait'
                ">
                    <div class="step-line" :class="
                        activeValue == i.stepIndex + 1 || i.stepIndex + 1 <= activeValue
                            ? 'step-finish'
                            : 'step-wait'
                    ">
                        <i class="step-line-inner"></i>
                    </div>
                    <div v-if="activeValue==i.stepIndex" class="step-img">
                        <img src="@/assets/img/set_on.png" alt="">
                    </div>
                    <div v-else-if="i.stepIndex + 1 <= activeValue" class="step-img">
                        <img src="@/assets/img/step_su.png" alt="">
                    </div>
                    <div class="step-icon" v-else :class="{ active: activeValue + 1 === i.stepIndex }">
                        <div class="step-icon-text">{
   { i.stepIndex }}</div>
                    </div>
                </div>
                <div class="step-main" :class="
                    activeValue == i.stepIndex || i.stepIndex <= activeValue
                        ? 'step-finish'
                        : 'step-wait'
                ">
                    <div class="step-title" :class="{ active: activeValue + 1 === i.stepIndex }">
                        {
   { i.title }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
import { defineComponent, reactive, ref, toRefs } from 'vue'
interface Props {
    activeValue: number //文件地址-双向绑定
}
const props = withDefaults(defineProps<Props>(), {
    activeValue: 1,

})

// const activeValue = ref(2);
const stepList = ref();
//步骤条步数
stepList.value = [
    {
        stepIndex: 1,
        title: "待处理",
    },
    {
        stepIndex: 2,
        title: "处理中",
    },
    {
        stepIndex: 3,
        title: "已完成",
    },

];




</script>
<style lang="scss" scoped>
.steps {
    display: flex;
    text-align: center;

    .step {
        flex-basis: 33%;
        margin-right: 0px;

        .step-head {
            position: relative;
            width: 100%;

            .step-line {
                left: 67%;
                right: -36%;
                height: 0.1px;
                top: 31px;
                position: absolute;
                border: 1px solid;
                border-color: inherit;
                // background-color: #c0c4cc;

                .step-line-inner {
                    transition-delay: 0ms;
                    // border-width: 1px;
                    width: 100%;
                    display: block;
                    // border: 1px solid;
                    // border-color: inherit;
                    transition: 0.15s ease-out;
                    box-sizing: border-box;
                    width: 0;
                    height: 0;
                }
            }

            .step-icon {
                position: relative;
                z-index: 1;
                display: inline-flex;
                justify-content: center;
                align-items: center;
                width: 20px;
                height: 20px;
                font-size: 12px;
                box-sizing: border-box;
                background: #c8c9cc;
                // transition: 0.15s ease-out;
                border-radius: 50%;
                // border: 2px solid;
                // border-color: inherit;

                &.active {
                    color: #333 !important;
                }

                .step-icon-text {
                    display: inline-block;
                    user-select: none;
                    text-align: center;
                    font-weight: 700;
                    line-height: 1;
                    color: #fff;
                }
            }
            .step-img{
                // display: flex;
                // align-items: center;
                // margin-right: 36px;
                img{
                    // display: inline-block;
                    width: 20px;
                    height: 20px;
                    vertical-align:bottom
                }
            }
        }

        .step-main {
            .step-title {
                font-size: 14px;
                line-height: 38px;
                // font-weight: 700;
                text-align: center;
                color: #6E6E6E;
                &.active {
                    color: #3C3C3C !important;
                }
            }
        }
    }

    .step:last-of-type .step-line {
        display: none;
    }

    //当前所在位置样式
    .step-finish {
        color: #EE0A24;
    }

    .step-wait {
        color: #dcdee0;
    }
}
</style>

 

原网站

版权声明
本文为[热忱学习]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42180156/article/details/125187829