(`・ω・´)我自己写的鱼骨图组件(小程序)

效果图在这里,蓝色进度条有动画效果哦

WXML

<view class="progress">

	<!-- 背景条 -->
	<view class="plainBar">
		<!-- 进度条 -->
		<view class="bar" style="width:{{x}}%"></view>
	</view>

	<!-- 进度球 -->
	<view class="stage-container">
		<view class="stage" wx:for="{{statusList}}" wx:key="index">
			<view class="ball {{index<progress?'done':index==progress?'current':'undone'}}">
				<text>{{index}}</text>
			</view>
			<text class="title" style="color: {{index==progress?'var(--color-normal)':''}};">{{item}}</text>
		</view>
	</view>
</view>

TS

Component({
	properties: {
		statusList: Object,
		/** current stage */
		progress: '' as any,
	},
	data: {
		/** num of stages */
		n: 0 as number,
		/** lenth of bar */
		x: 0 as number,
		/** progress on watch */
		progress: 0 as number
	},
	pageLifetimes: {

	},
	//监听订单状态变化
	observers: {
		'progress': function () {
			this.calc(this.properties.statusList)
		}
	},

	methods: {
		/** calculation */
		calc(e: Object) {
			let n = Object.keys(e).length
			let x = (100 / (n + 1)) * this.properties.progress
			this.setData({
				n: n,
				x: this.properties.progress == n ? 100 : x
			})
		}
	}
})

SCSS

.progress {
	width: 100%;
	display: felx;
	// padding: 40px 0;
	height: 80px;
	position: relative;
	flex-direction: column;
	box-sizing: border-box;

	.plainBar {
		top: 37px;
		width: 100%;
		height: 5px;
		position: absolute;
		border-radius: 20px;
		flex-direction: column;
		background-color: var(--color-border-light);

		.bar {
			top: 0;
			left: 0;
			height: 100%;
			border-radius: 20px;
			position: absolute;
			background-color: var(--color-confirm);
			transition: width 1s ease-in-out
		}

	}

	.stage-container {
		top: 30px;
		width: 100%;
		display: flex;
		position: absolute;
		align-items: center;
		justify-content: space-evenly;

		.stage {
			display: flex;
			align-items: center;
			flex-direction: column;

			.ball {
				width: 20px;
				height: 20px;
				display: flex;
				font-size: 12px;
				border-radius: 50%;
				align-items: center;
				justify-content: center;
				color: var(--color-white);
			}

			.done {
				background-color: var(--color-confirm);

			}

			.current {
				background-color: var(--color-confirm);

				animation: shadow 3s infinite ease-in-out;

			}

			@keyframes shadow {
				50% {
					box-shadow: rgba(64, 158, 255, .3) 0 0 3px 4px;
				}
			}

			.undone {
				background-color: var(--color-border-light);
			}

			.title {
				margin-top: 5px;
				color: var(--color-light);
				font-size: 12px;
			}
		}
	}

}

JSON

{
	"component": true,
	"usingComponents": {}
}

使用

<progression statusList="{{状态列表}}" progress="{{状态key}}"></progression>

状态列表数据格式如下:

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值