微信小程序中进度条总结

一、概述
  1. 总结进度条的使用的几种排版和样式风格,包括:拖动(空心或实心样式)、进度条粗细、进度条的排版...
二、完整代码实现
bash 复制代码
Page({
	data: {
		// 可拖动进度条数据
		progress1: 30,
		progress2: 60,
		customColor: "#f28e16",

		// 听力维度进度条数据
		socialProgress: 45,
		emotionProgress: 30,
		noiseProgress: 20,

		// 30天康复计划进度条数据
		rehabTotalDays: 30,
		rehabCurrentDay: 12,
		rehabStage: "第2周 · 适应生活",
		get rehabPercent() {
			return Math.round((this.rehabCurrentDay / this.rehabTotalDays) * 100);
		}
	},

	// 拖动事件
	onProgress1Change(e) {
		this.setData({
			progress1: e.detail.value
		});
	},

	onProgress2Change(e) {
		this.setData({
			progress2: e.detail.value
		});
	}
})
bash 复制代码
<view class="page-container">
	<!-- 30天康复计划进度条 -->
	<view class="rehab-plan-card">
		<view class="rehab-header">
			<text class="rehab-title">30天康复计划</text>
			<text class="rehab-stage">{{rehabStage}}</text>
		</view>
		<view class="rehab-progress-bar-bg">
			<view class="rehab-progress-bar-fill" style="width: {{rehabPercent}}%"></view>
		</view>
		<view class="rehab-footer">
			<text class="rehab-day">第{{rehabCurrentDay}} / {{rehabTotalDays}}天</text>
			<text class="rehab-percent">已完成 {{rehabPercent}}%</text>
		</view>
	</view>

	<!-- 听力维度粗进度条区域 -->
	<view class="static-progress-card">
		<text class="card-title">听力维度改善分析</text>

		<view class="static-progress-item">
			<text class="item-label">社交/环境适应</text>
			<view class="progress-row">
				<view class="progress-bar-bg">
					<view class="progress-bar-fill" style="width: {{socialProgress}}%"></view>
				</view>
				<text class="progress-percent">+{{socialProgress}}%</text>
			</view>
		</view>
		<view class="static-progress-item">
			<text class="item-label">情感/心理状态</text>
			<view class="progress-row">
				<view class="progress-bar-bg">
					<view class="progress-bar-fill" style="width: {{emotionProgress}}%"></view>
				</view>
				<text class="progress-percent">+{{emotionProgress}}%</text>
			</view>
		</view>
		<view class="static-progress-item">
			<text class="item-label">噪声环境下辨析</text>
			<view class="progress-row">
				<view class="progress-bar-bg">
					<view class="progress-bar-fill" style="width: {{noiseProgress}}%"></view>
				</view>
				<text class="progress-percent">+{{noiseProgress}}%</text>
			</view>
		</view>
	</view>

	<!-- 可拖动进度条卡片 -->
	<view class="slider-card">
		<view class="slider-item">
			<!-- 关键:标题和百分比在同一行,用flex左右对齐+垂直居中 -->
			<view class="slider-header">
				<text class="slider-label">基础进度条</text>
				<text class="slider-percent">当前进度:{{progress1}}%</text>
			</view>
			<slider value="{{progress1}}" bindchange="onProgress1Change" activeColor="#f28e16" backgroundColor="#e5e5e5" />
		</view>

		<view class="slider-item">
			<view class="slider-header">
				<text class="slider-label">自定义颜色进度条</text>
				<text class="slider-percent">当前进度:{{progress2}}%</text>
			</view>
			<slider value="{{progress2}}" bindchange="onProgress2Change" activeColor="{{customColor}}"
				backgroundColor="#f0f0f0" block-color="#f28e16" />
		</view>
	</view>
</view>
bash 复制代码
/* index.wxss */
.page-container {
  padding: 40rpx;
  background-color: #f5f7fa;
  min-height: 100vh;
}

/* ========== 30天康复计划进度条样式 ========== */
.rehab-plan-card {
  background: #ffffff;
  border-radius: 24rpx;
  padding: 36rpx;
  margin-bottom: 32rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}

.rehab-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24rpx;
}

.rehab-title {
  font-size: 34rpx;
  font-weight: 600;
  color: #1f2937;
}

.rehab-stage {
  font-size: 26rpx;
  color: #6b7280;
}

.rehab-progress-bar-bg {
  height: 16rpx;
  background-color: #eef2ff;
  border-radius: 8rpx;
  overflow: hidden;
  margin-bottom: 20rpx;
}

.rehab-progress-bar-fill {
  height: 100%;
  background-color: #1677ff;
  border-radius: 8rpx;
  transition: width 0.3s ease;
}

.rehab-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.rehab-day {
  font-size: 26rpx;
  color: #6b7280;
}

.rehab-percent {
  font-size: 26rpx;
  font-weight: 500;
  color: #1677ff;
}

/* ========== 粗进度条卡片样式 ========== */
.static-progress-card {
  background: #ffffff;
  border-radius: 24rpx;
  padding: 36rpx;
  margin-bottom: 32rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}

.card-title {
  display: block;
  font-size: 38rpx;
  font-weight: 600;
  color: #1f2937;
  margin-bottom: 48rpx;
}

.static-progress-item {
  margin-bottom: 48rpx;
}

.static-progress-item:last-child {
  margin-bottom: 0;
}

.item-label {
  display: block;
  font-size: 30rpx;
  color: #4b5563;
  margin-bottom: 18rpx;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 24rpx;
}

.progress-bar-bg {
  flex: 1;
  height: 20rpx;
  background-color: #eef2ff;
  border-radius: 10rpx;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background-color: #1677ff;
  border-radius: 10rpx;
  transition: width 0.3s ease;
}

.progress-percent {
  font-size: 30rpx;
  font-weight: 500;
  color: #1677ff;
  white-space: nowrap;
}


/* 可拖动进度条样式 */

.slider-card {
  background: #ffffff;
  border-radius: 24rpx;
  padding: 36rpx;
  box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
}

.slider-item {
  margin-bottom: 60rpx;
}

.slider-item:last-child {
  margin-bottom: 0;
}

/* 关键:flex布局实现左右文字完美对齐 */
.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center; /* 垂直居中 */
  margin-bottom: 20rpx;
}

.slider-label {
  font-size: 30rpx;
  color: #333;
  line-height: 1;
}

.slider-percent {
  font-size: 30rpx; /* 和标题字号一致,视觉上更统一 */
  color: #333;
  line-height: 1;
}

.slider-card slider {
  width: 100%;
  margin: 0;
}
三、总结
  1. 【30 天康复计划进度条】

    优势:纯 CSS 双层 View + 数据绑定,实现简单、性能好的静态进度条,不依赖第三方组件

    实现方式:通过style="width: {{rehabPercent}}%",把 JS 里计算好的百分比数值,动态绑定到上层填充条的宽度上,

  2. 【听力维度改善分析粗进度条】

    基于1种的技术实现的基础上,额外加了 Flex 布局:用display: flex把进度条和右侧的 "+45%" 文字放在同一行,实现左右排列,纯静态展示、可以自由控制进度条的粗细、圆角、颜色,比原生组件更灵活,

  3. 【底部两个可拖动的滑块进度条】

    优势:微信小程序官方提供的组件

    实现方式:直接使用小程序官方提供的标签,无需手动写事件实现拖动和进度的计算

相关推荐
考拉讲支付16 小时前
延迟分账 / 核销分账的技术实现方案:服务完成后再分钱,到底怎么设计?
大数据·运维·人工智能·微信小程序·小程序·系统架构
科威网络2 天前
小程序开发性能优化:分包、预加载与启动时间
性能优化·微信小程序·小程序
互联网+人工智能观察2 天前
微信小程序私有化定制、源码交付方案选型|SaaS / 模板二开 / 定制方案技术对比
微信小程序·小程序
爱勇宝4 天前
小红花成长更新了:孩子想要什么,也应该有机会自己说出来
微信小程序·产品·小程序·云开发
andrsted4 天前
企业培训时间难统一?练题簿让在线免费刷题与培训考核更好安排
学习·微信小程序·小程序·学习方法·刷题
拖孩4 天前
一个人 + AI 做的小程序,今天,正式回本了
前端·后端·微信小程序
李纲明4 天前
微信小程序 wx.uploadFile 上传失败:合法域名、临时路径与 HTTPS 证书排查
微信小程序·小程序·uploadfile·devdiy·上传失败
冬奇Lab4 天前
一天一个开源项目(第247篇):wxa-runner —— 让小程序在普通浏览器里用微信官方基础库跑起来,直接接 Playwright 做无头 E2E
微信小程序·开源
andrsted5 天前
练题簿在线免费刷题:让整理过的资料,变成能反复练习的题库
学习·微信小程序·小程序·学习方法·刷题·1024程序员节
梅雅达编程笔记5 天前
Day 17 | uni-app 小程序:前端从零搭建
微信小程序·typescript·uni-app·vue3·pinia·前端开发·全栈