css实现圆环展示百分比,根据值动态展示所占比例

代码如下

javascript 复制代码
<view class="">
	<view class="circle-chart">
		<view v-if="!!num" class="pie-item" :style="{
				  background: `conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%)`,
				}"></view>
		<view v-else class="pie-item-copy" :style="{
				  background:'#E9E6F1',
				}"></view>
		<view v-if="!!degNum" class="pie-item" :style="{
				        background: `conic-gradient(var(--two-color) 0%,transparent ${20}%)`,
				        transform: `scaleX(-1) rotate(${degNum}deg)`,
				      }"></view>
		<view class="biaopan">
			<view class="biaopanCot">
				<view class="">
					93
				</view>
				<view class="">
					6小时42分钟
				</view>
			</view>
		</view>
	</view>
</view>
<script>
	export default {
		data() {
			return {
				num: 85, //圆环数值百分比
				degNum: '', //旋转的角度
			}
		},
		watch: {
			num: {
				handler(newValue) {
					if (!!this.num) {
						this.degNum = 360 * (100 - newValue) / 100
					} else {
						this.degNum = ''
					}
				},
				deep: true,
				immediate: true,
			},
		},
	}
</script>
<style scoped lang="scss">
	.circle-chart {
		position: relative;
		--one-color: #11D64C;
		--two-color: #c5ffd7a1;
		width: 460rpx;
		height: 460rpx;
		margin: 0 auto;

		
	}
	.circle-chart .pie-item-copy {
		position: absolute;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		mask: radial-gradient(transparent,
				transparent 174rpx,
				#000 176rpx,
				#000 176rpx,
				#000 100%);
	}
	
	.circle-chart .pie-item {
		position: absolute;
		width: 100%;
		height: 100%;
		border-radius: 50%;
		mask: radial-gradient(transparent,
				transparent 174rpx,
				#000 176rpx,
				#000 176rpx,
				#000 100%);
	
		
	}
	.pie-item:nth-child(1)::before {
		background: linear-gradient(90deg,
				var(--one-color) 50%,
				transparent 51%,
				transparent 100%);
	}
		
	.pie-item:nth-child(2)::before {
		background: linear-gradient(90deg,
				var(--two-color) 50%,
				transparent 51%,
				transparent 100%);
	}
		
	.pie-item::before {
		content: '';
		position: absolute;
		inset: 0;
		width: 56rpx;
		height: 56rpx;
		top: 0;
		left: 202rpx;
		border-radius: 50%;
	}

	.biaopan {
		position: absolute;
		left: 68rpx;
		right: 68rpx;
		top: 68rpx;
		bottom: 68rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.biaopanCot{
		text-align: center;
	}

	< /style>
相关推荐
YaHuiLiang3 分钟前
小微互联网公司与互联网创业公司 -- 学历之殇
前端·后端·面试
用户26124583401616 分钟前
vue学习路线(11.watch对比computed)
前端·vue.js
CAD老兵12 分钟前
前端 Source Map 原理与结构详解
前端
gnip16 分钟前
markdown预览自定义扩展实现
前端·javascript
大猫会长27 分钟前
mac中创建 .command 文件,执行node服务
前端·chrome
旧时光_27 分钟前
Zustand 状态管理库完全指南 - 进阶篇
前端·react.js
snakeshe101029 分钟前
深入理解useState:批量更新与非函数参数支持
前端
windliang29 分钟前
Cursor 排查 eslint 问题全过程记录
前端·cursor
boleixiongdi30 分钟前
# Bsin-App Uni:面向未来的跨端开发框架深度解析
前端
G等你下课33 分钟前
AJAX请求跨域问题
前端·javascript·http