uniapp中使用封装步骤条组件

针对步骤条封装完终于清清楚楚啦

先看效果:

附上代码:使用可直接复用:数据是写在了当前组件中,如有必须,可以使用其中的props传值stepInfos传递相应的数据,根据steps步数就可以控制走到哪一步啦

复制代码
<template>
	<view class="step-bar">
		<view class="step_item" v-for="(item,index) in stepInfo.list" :key="item.id">
			<view :class="stepInfo.step >= index+1 ? 'circle circle-active':'circle'"></view>
			<view :class="stepInfo.step >= index+2 ? 'line line-active':'line'" v-if="index!==stepInfo.list.length-1">
			</view>
			<view class="middle-box">
				<text
					:class="stepInfo.step < index+1 ? 'text1-actived':stepInfo.step == index+1?'text1-active':text1">{{item.name}}</text>
				<text class="text2">{{item.time}}</text>
			</view>
			<view class="status_text"
				:class="stepInfo.step < index+1 ? 'text1-actived':stepInfo.step == index+1?'text1-active':text1">
				{{item.status}}
			</view>
		</view>
	</view>
</template>

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

		},
		data() {
			return {
				stepInfo: {
					step: 3,
					list: [{
						id: 1,
						name: '发起充值',
						time: '2020-12-12 12:47:56',
						status: '已完成'
					}, {
						id: 2,
						name: '处理中',
						time: '2020-12-12 12:47:56',
						status: '进行中'
					}, {
						id: 3,
						name: '到账成功',
						time: '2020-12-12 12:47:56',
						status: '未开始'
					}]
				}
			}
		},
	}
</script>

<style lang="scss" scoped>
	.step_item {
		position: relative;
		height: 144rpx;
		display: flex;

		.line {
			position: absolute;
			top: 40rpx;
			left: 8rpx;
			content: "";
			width: 4rpx;
			height: 100rpx;
			background-color: #E6E8EF;
		}

		.line-active {
			background-color: #FF2B46;
		}
	}

	.circle {
		width: 20rpx;
		height: 20rpx;
		margin-right: 40rpx;
		margin-top: 10rpx;
		border-radius: 50%;
		background-color: #E6E8EF;
	}

	.circle-active {
		background-color: #FF2B46;
	}

	.middle-box {
		display: flex;
		flex-direction: column;

		.text2 {
			color: #999999;
			font-size: 24rpx;
		}
	}


	.text1 {
		color: #666666;
		font-size: 28rpx;
	}

	.text1-active {
		color: #FF2B46;
	}

	.text1-actived {
		color: #333333;
	}

	.status_text {
		flex-grow: 1;
		display: flex;
		justify-content: flex-end;
		font-size: 28rpx;
	}


	.status_text_active {
		// color: #FF2B46;
	}
</style>
相关推荐
Sherry00713 小时前
【译】🔥如何居中一个 Div?看这篇就够了
前端·css·面试
前端小咸鱼一条13 小时前
18. React的受控和非受控组件
前端·react.js·前端框架
一枚前端小能手13 小时前
🛠️ Service Worker API深度解析 - 生命周期、缓存与离线实战
前端·javascript
马卫斌 前端工程师14 小时前
vue3 实现echarts 3D 地图
前端·javascript·echarts
蓝瑟14 小时前
前端测试不再难:Vite+React+Vitest单元测试完整手册
前端·react.js·单元测试
爱分享的鱼鱼14 小时前
Vue中如何实现可切换显示/隐藏侧边栏的按钮
前端
Mike_jia14 小时前
DBdoctor:数据库性能的“AI名医”,诊断效率提升10倍的终极利器
前端
怪可爱的地球人14 小时前
向宇宙发送一枚小可爱
前端
数字元匠_山步14 小时前
一篇笔记彻底搞懂 “脚手架” “框架” “构建工具” 的关系
前端
2501_9159214314 小时前
iOS 虚拟位置设置实战,多工具协同打造精准调试与场景模拟环境
android·ios·小程序·https·uni-app·iphone·webview