步骤条的使用

 粘贴 直接看效果

 子组件

<template>
  <div class="m-steps-area">
    <div class="m-steps">
      <div :class="['m-steps-item',
          { 'finished': current > n,
            'process': current === n && n !== totalSteps,
            'last-process': current === totalSteps && n === totalSteps,
            'middle-wait': current < n && n !== totalSteps,
            'last-wait': current < n && n === totalSteps,
          }
        ]" v-for="n in totalSteps" :key="n" @click="onChange(n)">
        <div class="m-steps-icon">
          <span class="u-icon" v-if="current<=n">{{ n }}</span>
          <span class="u-icon" v-else>✓</span>
        </div>
        <div class="m-steps-content">
          <div class="u-steps-title">{{ stepsLabel[n-1]  }}</div>
          <div class="u-steps-description">{{ stepsDesc[n-1]  }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'Steps',
  props: {
    stepsLabel: { // 步骤title数组
      type: Array,
      default: () => {
        return []
      }
    },
    stepsDesc: { // 步骤description数组
      type: Array,
      default: () => {
        return []
      }
    },
    totalSteps: { // 总的步骤数
      type: Number,
      default: 3
    },
    currentStep: { // 当前选中的步骤
      type: Number,
      default: 1
    }
  },
  data () {
    return {
      // 若当前选中步骤超过总步骤数,则默认选择步骤1
      current: this.currentStep > this.totalSteps ? 1 : this.currentStep
    }
  },


  watch: {
    currentStep: {
      handler (val) {
        if (val) {
          this.current = val
        }
      },
      deep: true,
      immediate: true
    }
  },

  methods: {
    onChange (index) { // 点击切换选择步骤
      // console.log('index:', index)
      if (this.current !== index) {
        this.current = index
        this.$emit('change', index)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.m-steps-area {
  // width: 1100px;
  width: 800px;
  margin: 0px auto;

  .m-steps {
    // padding: 30px 0;
    display: flex;

    .m-steps-item {
      display: inline-block;
      flex: 1; // 弹性盒模型对象的子元素都有相同的长度,且忽略它们内部的内容
      overflow: hidden;
      font-size: 16px;
      line-height: 32px;

      .m-steps-icon {
        display: inline-block;
        margin-right: 8px;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        text-align: center;
      }

      .m-steps-content {
        display: inline-block;
        vertical-align: top;
        padding-right: 16px;

        .u-steps-title {
          position: relative;
          display: inline-block;
          padding-right: 16px;
        }

        .u-steps-description {
          font-size: 14px;
          max-width: 140px;
        }
      }
    }

    .finished {
      margin-right: 16px;
      cursor: pointer;

      &:hover {
        .m-steps-content {
          .u-steps-title {
            color: #1890ff;
          }

          .u-steps-description {
            color: #1890ff;
          }
        }
      }

      .m-steps-icon {
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.25);
        border-color: #1890ff;

        .u-icon {
          color: #1890ff;
        }
      }

      .m-steps-content {
        color: rgba(0, 0, 0, 0.65);

        .u-steps-title {
          color: rgba(0, 0, 0, 0.65);

          &:after {
            background: #1890ff;
            position: absolute;
            top: 16px;
            left: 100%;
            display: block;
            width: 9999px;
            height: 1px;
            content: '';
          }
        }

        .u-steps-description {
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }

    .process {
      margin-right: 16px;

      .m-steps-icon {
        background: #1890ff;
        border: 1px solid rgba(0, 0, 0, 0.25);
        border-color: #1890ff;

        .u-icon {
          color: #fff;
        }
      }

      .m-steps-content {
        color: rgba(0, 0, 0, 0.65);

        .u-steps-title {
          font-weight: 600;
          color: rgba(0, 0, 0, 0.85);

          &:after {
            background: #e8e8e8;
            position: absolute;
            top: 16px;
            left: 100%;
            display: block;
            width: 9999px;
            height: 1px;
            content: '';
          }
        }

        .u-steps-description {
          color: rgba(0, 0, 0, 0.65);
        }
      }
    }

    .last-process {
      margin-right: 0;

      .m-steps-icon {
        background: #1890ff;
        border: 1px solid rgba(0, 0, 0, 0.25);
        border-color: #1890ff;

        .u-icon {
          color: #fff;
        }
      }

      .m-steps-content {
        color: rgba(0, 0, 0, 0.65);

        .u-steps-title {
          font-weight: 600;
          color: rgba(0, 0, 0, 0.85);
        }

        .u-steps-description {
          color: rgba(0, 0, 0, 0.65);
        }
      }
    }

    .middle-wait {
      margin-right: 16px;
      cursor: pointer;

      &:hover {
        .m-steps-icon {
          border: 1px solid #1890ff;

          .u-icon {
            color: #1890ff;
          }
        }

        .m-steps-content {
          .u-steps-title {
            color: #1890ff;
          }

          .u-steps-description {
            color: #1890ff;
          }
        }
      }

      .m-steps-icon {
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.25);

        .u-icon {
          color: rgba(0, 0, 0, 0.25);
        }
      }

      .m-steps-content {
        color: rgba(0, 0, 0, 0.65);

        .u-steps-title {
          color: rgba(0, 0, 0, 0.45);

          &:after {
            background: #e8e8e8;
            position: absolute;
            top: 16px;
            left: 100%;
            display: block;
            width: 9999px;
            height: 1px;
            content: '';
          }
        }

        .u-steps-description {
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }

    .last-wait {
      margin-right: 0;
      cursor: pointer;

      &:hover {
        .m-steps-icon {
          border: 1px solid #1890ff;

          .u-icon {
            color: #1890ff;
          }
        }

        .m-steps-content {
          .u-steps-title {
            color: #1890ff;
          }

          .u-steps-description {
            color: #1890ff;
          }
        }
      }

      .m-steps-icon {
        background: #fff;
        border: 1px solid rgba(0, 0, 0, 0.25);

        .u-icon {
          color: rgba(0, 0, 0, 0.25);
        }
      }

      .m-steps-content {
        color: rgba(0, 0, 0, 0.65);

        .u-steps-title {
          color: rgba(0, 0, 0, 0.45);
        }

        .u-steps-description {
          color: rgba(0, 0, 0, 0.45);
        }
      }
    }
  }
}
</style>

父组件 使用组件的页面

  <Steps :currentStep="currentStep" :totalSteps="4" :stepsLabel="stepsLabel" />
  data () {
    return {
      currentStep: 1,
      stepsLabel: ['初审', '复核', '负责人审核', '审批人审核'],
    }
  },
  components: {
    steps: () => import('@/components/8.Steps/index.vue')
  }
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值