vue自己封装一个步骤条组件

实现效果如图:

 代码如下:

子组件:

<!-- Step.vue  -->
<template>
	<div class="stepOut">
		<ul style="list-style: none;display: flex;">
			<li class="stepItem" v-for="(stepItem, index) in stepInfo.list" :key="index">
				<!-- 模拟步骤条的节点,此处为圆圈 -->
				<div :class="stepInfo.step >= index+1 ? 'icon active':'icon'"></div>
				<!-- 模拟步骤条连接线,动态显示  -->
				<div :class="stepInfo.step >= index+2 ? 'line lineActive':'line'"
					v-show="index!==stepInfo.list.length-1"></div>
				<!-- 步骤名称  -->
				<div :class="stepInfo.step >= index+1 ? 'stepStatus':'stepStatus2'">{{stepItem.name}}</div>
			</li>
		</ul>
	</div>
</template>

<script>
	export default {
		name: 'steps',
		props: {
			// 传递步骤参数
			stepInfo: {
				type: Object,
				default: function() {
					return {
						list: [],
						step: 0
					}
				}
			}
		}
	}
</script>

<style scoped>
	.stepOut {
		padding-top: 20px;
		width: 100%;
		display: flex;
		justify-content: space-between;
	}

	/* 两点间间距 */
	.stepOut .stepItem {
		width: 400px;
		height: 70px;
		float: left;
		font-size: 16px;
		position: relative;
	}

	.stepOut .stepItem .icon {
		width: 15px;
		height: 15px;
		border-radius: 50%;
		background: #e2e2e2;
		/* margin: 0 auto; */
		position: relative;
		z-index: 888;
	}

	.stepOut .stepItem .active {
		background-color: #F05D4B;
	}

	/* 线条 */
	.stepOut .stepItem .line {
		position: absolute;
		top: 6px;
		left: 30px;
		border-bottom: 2px solid #e9e9e9;
		width: 350px;
		z-index: 111;
	}

	.stepOut .stepItem .lineActive {
		border-bottom: 2px solid #F05D4B;
	}
	/* 下面字体颜色 */
	.stepOut .stepItem .stepStatus {
		color: #F05D4B;
		line-height: 36px;
	}
	.stepOut .stepItem .stepStatus2 {
		color: #999999;
		line-height: 36px;
	}
</style>

父组件中:

<template>
  <div>
    <!-- 步骤条-->
	<steps :stepInfo="stepInfo"></steps>
  </div>
</template>
<script>
	import steps from "../../../components/steps.vue"
	export default {
		components: {
			steps,
		},
		data() {
			return {
				// 步骤条内容
				stepInfo: {
					list: [{
							name: '发现故障'
						},
						{
							name: '派发工单'
						},
						{
							name: '故障处理'
						},
					],
                   //步骤条进度
					step: 2
				},
</script>

在原基础上又根据UI需求搞了个更花里胡哨一点的:

代码如下:

<!-- Step.vue  -->
<template>
	<div class="stepOut">
		<ul style="list-style: none;display: flex;">
			<li class="stepItem" v-for="(stepItem, index) in stepInfo.list" :key="index">
				<!-- 模拟步骤条的节点,此处为圆圈 -->
				<div :class="stepInfo.step >= index+1 ? index=='0'?'icon active':index=='1'?'icon active1':'icon active2' :'icon'"></div>
				<!-- 模拟步骤条连接线,动态显示  -->
				<div :class="stepInfo.step >= index+2 ? index=='0'?'line lineActive':'line lineActive1':'line'"
					v-show="index!==stepInfo.list.length-1"></div>
				<!-- 步骤名称  -->
				<div :class="stepInfo.step >= index+1 ?  index=='0'?'stepStatus':index=='1'?'stepStatus1':'stepStatus2' :'stepStatus3'">{{stepItem.name}}</div>
			</li>
		</ul>
	</div>
</template>

<script>
	export default {
		name: 'steps',
		props: {
			// 传递步骤参数
			stepInfo: {
				type: Object,
				default: function() {
					return {
						list: [],
						step: 0
					}
				}
			}
		}
	}
</script>

<style scoped>
	.stepOut {
		padding-top: 20px;
		width: 100%;
		display: flex;
		justify-content: space-between;
	}

	/* 两点间间距 */
	.stepOut .stepItem {
		width: 400px;
		height: 70px;
		float: left;
		font-size: 16px;
		position: relative;
	}

	.stepOut .stepItem .icon {
		width: 15px;
		height: 15px;
		border-radius: 50%;
		background: #e2e2e2;
		/* margin: 0 auto; */
		position: relative;
		z-index: 888;
	}

	.stepOut .stepItem .active {
		background-color: #F05D4B;
	}
	.stepOut .stepItem .active1 {
		background-color: #F29927;
	}
	.stepOut .stepItem .active2 {
		background-color: #02C6A3;
	}
	/* 线条 */
	.stepOut .stepItem .line {
		position: absolute;
		top: 6px;
		left: 22px;
		border-bottom: 2px solid #e9e9e9;
		width: 370px;
		z-index: 111;
	}

	.stepOut .stepItem .lineActive {
		border-bottom: 2px solid #F29927 ;
	}
	.stepOut .stepItem .lineActive1{
		border-bottom: 2px solid #02C6A3  ;
	}
	/* 下面字体颜色 */
	.stepOut .stepItem .stepStatus {
		color: #F05D4B;
		line-height: 36px;
	}
	.stepOut .stepItem .stepStatus1 {
		color: #F29927;
		line-height: 36px;
	}
	.stepOut .stepItem .stepStatus2 {
		color: #02C6A3;
		line-height: 36px;
	}
	.stepOut .stepItem .stepStatus3 {
		color: #999999;
		line-height: 36px;
	}
</style>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阁下何不同风起?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值