基于Vue2超简单实现DIY定制的步骤条

简介: 这篇文章介绍了如何在Vue 2中实现一个自定义设计的步骤条组件,包括子组件的设计和在父页面中的使用示例。

前言

由于一些定制化的需求无法在网上直接找到可用插件来实现,只能DIY设计实现,如以下步骤条。

一、首先设计子组件

(1)【/src/Example/DiyStep/component/SkyStep.vue】

<template>
  <div>
    <ul class="diy-steps">
      <li v-for="(item, index) in stepList" :key="index">
        <div class="diy-step">
          <div class="diy-step-line_left" v-if="index === 0 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #ffffff, #bbbbbb)'"/>
          <div class="diy-step-line_left" v-if="index === 0 && item.status !== 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #ffffff, #4cb45b)'"/>
          <div class="diy-step-line_left" v-else-if="index !== 0 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '0deg' + ', #bbbbbb, #bbbbbb)'"/>
          <div class="diy-step-line_left" v-else-if="index !== 0 && item.status !== 'undone'" :style="'background-image: linear-gradient(' + '0deg' + ', #4cb45b, #4cb45b)'"/>

          <div class="diy-step-box diy-step__success" v-if="item.status === 'success'">
            <span>
              <i class="el-icon-check"></i>
            </span>
            <strong>{
  
  { item.label }}</strong>
          </div>

          <div class="diy-step-box diy-step__fail" v-else-if="item.status === 'fail'">
            <span>
              <i class="el-icon-close"></i>
            </span>
            <strong>{
  
  { item.label }}</strong>
          </div>

          <div class="diy-step-box diy-step__doing" v-else-if="item.status === 'doing'">
            <span>
              <i class=""></i>
            </span>
            <strong>{
  
  { item.label }}</strong>
          </div>

          <div class="diy-step-box diy-step__undone" v-else-if="item.status === 'undone'">
            <span>
              <i class=""></i>
            </span>
            <strong>{
  
  { item.label }}</strong>
          </div>

          <div class="diy-step-line_right" v-if="index === stepList.length - 1 && item.status === 'success'" :style="'background-image: linear-gradient(' + '90deg' + ', #4cb45b, #ffffff)'"/>
          <div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'fail'" :style="'background-image: linear-gradient(' + '90deg' + ', #4cb45b, #ffffff)'"/>
          <div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'doing'" :style="'background-image: linear-gradient(' + '90deg' + ', #bbbbbb, #ffffff)'"/>
          <div class="diy-step-line_right" v-else-if="index === stepList.length - 1 && item.status === 'undone'" :style="'background-image: linear-gradient(' + '90deg' + ', #bbbbbb, #ffffff)'"/>
          <div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status === 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status === 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #bbbbbb, #bbbbbb)'"/>
          <div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status !== 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status === 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #bbbbbb, #bbbbbb)'"/>
          <div class="diy-step-line_right" v-else-if="index !== stepList.length - 1 && item.status !== 'undone' && (index + 1 <= stepList.length - 1) && stepList[index + 1].status !== 'undone' " :style="'background-image: linear-gradient(' + '180deg' + ', #4cb45b, #4cb45b)'"/>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
    
    
  props: ['stepList'],
  data: () => ({
    
    
    // stepList : [
    //   {label: '准备好所有的食材', status: 'success'},
    //   {label: '把茶叶和白砂糖放入锅中', status: 'success'},
    //   {label: '将其翻炒至冒泡', status: 'fail'},
    //   {label: '加入白开水煮沸', status: 'doing'},
    //   {label: '倒入纯牛奶', status: 'undone'},
    //   {label: '滤出茶叶就好了', status: 'undone'}
    // ],
  })
}
</script>

<style lang="less">
  .diy-steps {
    
    
    display: flex;
    width: 100%;
    height: 55px;
    margin: 15px auto 0 auto;
    padding: 0;
    position: relative;
    font-family: "微软雅黑";
    overflow: hidden;
  }

  .diy-steps li {
    
    
    width: auto;
    height: 100%;
    flex: 1;
    list-style-type: none;
    font-size: 12px;
    text-align: center;
    position: relative;
    float: left;
  }

  .diy-steps li .diy-step {
    
    
    width: 100%;
    display: inline-block;
    position: relative;
    z-index: 1;
  }

  .diy-step-line_left {
    
    
    border-bottom: 1px solid transparent;
    background-image: linear-gradient(90deg, #bbbbbb, #4cb45b);
    width: 50%;
    height: 1px;
    display: inline-block;
    position: absolute;
    top: 9px;
    left: 0;
    z-index: 0;
  }

  .diy-step-line_right {
    
    
    border-bottom: 1px solid transparent;
    background-image: linear-gradient(180deg, #bbbbbb, #4cb45b);
    width: 50%;
    height: 1px;
    display: inline-block;
    position: absolute;
    top: 9px;
    right: 0;
    z-index: 0;
  }

  .diy-steps li .diy-step .diy-step-box {
    
    
    position: relative;
    z-index: 1;
  }

  .diy-steps li .diy-step .diy-step-box span {
    
    
    display: block;
    width: 13px;
    height: 13px;
    border-radius: 100%;
    color: #fff;
    /* transform: scale(1.2); */
    text-align: center;
    margin: 0 auto 8px auto;
  }

  .diy-steps li .diy-step .diy-step-box span i {
    
    
    display: block;
    width: 13px;
    height: 13px;
    border-radius: 100%;
    line-height: 13px;
  }

  .diy-steps li .diy-step .diy-step-box strong {
    
    
    letter-spacing: 0.5px;
  }

  /* diy-step__success */
  .diy-step__success span {
    
    
    border: rgba(55, 171, 71, 0.2) 4px solid;
    border: rgb(215 238 218) 4px solid;
  }

  .diy-step__success span i {
    
    
    background-color: #37ab47;
  }

  .diy-step__success strong {
    
    
    color: #37ab47;
  }
  /* / diy-step__success */

  /* diy-step__fail */
  .diy-step__fail span {
    
    
    border: rgba(252, 94, 90, 0.2) 4px solid;
    border: rgb(254 223 222) 4px solid;
  }

  .diy-step__fail span i {
    
    
    background-color: #fc5e5a;
  }

  .diy-step__fail strong {
    
    
    color: #fc5e5a;
  }
  /* / diy-step__fail */

  /* diy-step__doing */
  .diy-step__doing span {
    
    
    border: rgba(94, 124, 224, 0.2) 4px solid;
    border: rgb(223 229 249) 4px solid;
  }

  .diy-step__doing span i {
    
    
    background-color: #5e7ce0;
  }

  .diy-step__doing strong {
    
    
    color: #5e7ce0;
  }
  /* / diy-step__doing */

  /* diy-step__undone */
  .diy-step__undone span {
    
    
    border: rgba(153, 153, 153, 0.2) 4px solid;
    border: rgb(235 235 235) 4px solid;
  }

  .diy-step__undone span i {
    
    
    background-color: #999999;
  }

  .diy-step__undone strong {
    
    
    color: #999999;
  }
  /* / diy-step__undone */
</style>

二、然后实现父页面

(2)【/src/Example/DiyStep/index.vue】

<template>
  <div>
    <SkyStep :stepList="stepList1"/>
    <SkyStep :stepList="stepList2"/>
    <SkyStep :stepList="stepList3"/>
    <SkyStep :stepList="stepList4"/>
    <SkyStep :stepList="stepList5"/>
    <SkyStep :stepList="stepList6"/>
    <SkyStep :stepList="stepList7"/>
  </div>
</template>

<script>
import SkyStep from './components/SkyStep.vue'

export default {
    
    
  components: {
    
    
    SkyStep
  },
  data: () => ({
    
    
    stepList1: [
      {
    
     label: '准备好所有的食材', status: 'doing' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'undone' },
      {
    
     label: '将其翻炒至冒泡', status: 'undone' },
      {
    
     label: '加入白开水煮沸', status: 'undone' },
      {
    
     label: '倒入纯牛奶', status: 'undone' },
      {
    
     label: '滤出茶叶就好了', status: 'undone' }
    ],

    stepList2: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'doing' },
      {
    
     label: '将其翻炒至冒泡', status: 'undone' },
      {
    
     label: '加入白开水煮沸', status: 'undone' },
      {
    
     label: '倒入纯牛奶', status: 'undone' },
      {
    
     label: '滤出茶叶就好了', status: 'undone' }
    ],

    stepList3: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'fail' },
      {
    
     label: '将其翻炒至冒泡', status: 'doing' },
      {
    
     label: '加入白开水煮沸', status: 'undone' },
      {
    
     label: '倒入纯牛奶', status: 'undone' },
      {
    
     label: '滤出茶叶就好了', status: 'undone' }
    ],

    stepList4: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'success' },
      {
    
     label: '将其翻炒至冒泡', status: 'fail' },
      {
    
     label: '加入白开水煮沸', status: 'doing' },
      {
    
     label: '倒入纯牛奶', status: 'undone' },
      {
    
     label: '滤出茶叶就好了', status: 'undone' }
    ],

    stepList5: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'success' },
      {
    
     label: '将其翻炒至冒泡', status: 'success' },
      {
    
     label: '加入白开水煮沸', status: 'fail' },
      {
    
     label: '倒入纯牛奶', status: 'doing' },
      {
    
     label: '滤出茶叶就好了', status: 'undone' }
    ],

    stepList6: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'success' },
      {
    
     label: '将其翻炒至冒泡', status: 'success' },
      {
    
     label: '加入白开水煮沸', status: 'success' },
      {
    
     label: '倒入纯牛奶', status: 'fail' },
      {
    
     label: '滤出茶叶就好了', status: 'doing' }
    ],

    stepList7: [
      {
    
     label: '准备好所有的食材', status: 'success' },
      {
    
     label: '把茶叶和白砂糖放入锅中', status: 'success' },
      {
    
     label: '将其翻炒至冒泡', status: 'success' },
      {
    
     label: '加入白开水煮沸', status: 'success' },
      {
    
     label: '倒入纯牛奶', status: 'success' },
      {
    
     label: '滤出茶叶就好了', status: 'success' }
    ]
  })
}
</script>

<style lang="less" scoped>

</style>

三、运行效果

目录
相关文章
|
移动开发 JavaScript 小程序
uView Steps 步骤条
uView Steps 步骤条
640 0
|
编解码 前端开发 JavaScript
摄像头web网页播放功能: ffmeg和nginx实现
摄像头web网页播放功能: ffmeg和nginx实现
1295 0
|
开发者 iOS开发
【Markdown小技巧】 整理小图标和表情符号
让博客变得更加优美,你需要这些萌萌的、好看的表情符号。以下是我收集的一些表情符号和小图标,分享给大家。
【Markdown小技巧】 整理小图标和表情符号
|
11月前
|
人工智能 自然语言处理 安全
Claude Code 插件登陆 VS Code:开发者迎来 AI 编程新利器
Anthropic正式发布Claude Code——VS Code官方插件,支持多语言智能补全、代码解释、错误诊断与安全重构。隐私优先、长上下文(200K tokens)处理能力强,显著优于Copilot的可解释性与代码质量,已获开发者广泛好评。(239字)
9561 5
Vue2步骤条(Steps)
这是一个基于 Vue3 的步骤条(Steps)组件,支持高度自定义。主要属性包括步骤标题数组(stepsLabel)、步骤描述数组(stepsDesc)、步骤总数(totalSteps,默认为3)、当前选中的步骤(currentStep,默认为1)、步骤条总宽度(totalWidth,默认为900px)和描述文本最大宽度(descMaxWidth,默认为140px)。组件通过不同的样式展示已完成、进行中和未开始的状态,并支持点击切换步骤。可在需要的页面中引入并传入相关初始数据。
654 1
Vue2步骤条(Steps)
|
JavaScript 前端开发 开发者
Vue 自定义进度条组件封装及使用方法详解
这是一篇关于自定义进度条组件的使用指南和开发文档。文章详细介绍了如何在Vue项目中引入、注册并使用该组件,包括基础与高级示例。组件支持分段配置(如颜色、文本)、动画效果及超出进度提示等功能。同时提供了完整的代码实现,支持全局注册,并提出了优化建议,如主题支持、响应式设计等,帮助开发者更灵活地集成和定制进度条组件。资源链接已提供,适合前端开发者参考学习。
980 17
|
前端开发
文字显示在div 最下面,css怎么写
文字显示在div 最下面,css怎么写
896 0
|
JavaScript 前端开发 API
vue3 v-md-editor markdown编辑器(VMdEditor)和预览组件(VMdPreview )的使用
本文介绍了如何在Vue 3项目中使用v-md-editor组件库来创建markdown编辑器和预览组件。文章提供了安装步骤、如何在main.js中进行全局配置、以及如何在页面中使用VMdEditor和VMdPreview组件的示例代码。此外,还提供了一个完整示例的链接,包括编辑器和预览组件的使用效果和代码。
vue3 v-md-editor markdown编辑器(VMdEditor)和预览组件(VMdPreview )的使用
|
移动开发 资源调度 JavaScript
Vue移动端网页(H5)预览pdf文件(pdfh5和vue-pdf)
这篇文章介绍了在Vue移动端网页中使用`pdfh5`和`vue-pdf`两个插件来实现PDF文件的预览,包括滚动查看、缩放、添加水印、分页加载、跳转指定页数等功能。
12188 1
Vue移动端网页(H5)预览pdf文件(pdfh5和vue-pdf)
Vue3步骤条(Steps)
这是一个基于 Vue2 的步骤条(Steps)组件,支持多种自定义属性,如步骤数组、宽度、大小、垂直显示、标签位置等。通过 `v-model` 可实现步骤的动态切换和点击交互。提供了丰富的样式调整选项,适用于各种场景下的多步骤流程引导。组件内详细展示了如何创建和使用步骤条,并提供了多个示例代码片段。
2360 4
Vue3步骤条(Steps)