vue 实现水波进度条和环形进度条效果

2023-10-13 20:59

本文主要是介绍vue 实现水波进度条和环形进度条效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一. 水波进度条具体效果

请添加图片描述
先说下具体实现思路
首选使用div画出一个圆, 把外轮廓画出来
下面是是html结构

在这里插入图片描述

颜色可以根据自己的需要设置, 具体波浪实现思路是, 画一个带有圆角的div, 定位到这个原型的上面,然后使用css动画来进行无限旋转即可
在这里插入图片描述

然后贴上全部代码

<!-- eslint-disable vue/multi-word-component-names -->
<template><divclass="wave_content":style="{height: height + 'px', background: styles.compConfig.type === 'dark' ? '#2f3d65' : '#f5f5f5'}"><div class="wave_progress"><divclass="wave":style="{background: color}"><div id="number_contnet"><div> {{ percent }} </div><div>{{ title }}</div></div></div><div:id="'wave_mask' + index"class="wave_mask":style="{top: 100 - percentage === 0 ? (-90000 + '%') : 100 - percentage + '%'}"/></div><div style="margin-top: 14px; display:flex; flex-wrap:wrap"><spanv-show="showActual"style="font-weight: 500;margin-right: 10px">实际: {{ actual }}</span><spanv-show="showObjective"style="font-weight: 500">目标: {{ objective }}</span></div></div>
</template><script>
export default {props: {data: {type: Object,default: () => {}},height: { // 可以动态设置高度type: [Number, String],default: 230},index: { // 使用v-for渲染时 index要唯一type: [String, Number],default: 0},percentage: { // 进度为 0 - 100 type: [Number],default: 0},percent: { // 自己计算的百分比type: [Number, String],default: 0},title: {type: String,default: ''},actual: { // 实际值type: String,default: ''},objective: { // 目标值type: String,default: ''},showActual: {type: Boolean,default: true},showObjective: {type: Boolean,default: true},color: { // 背景颜色type: String,default: ''}},data() {return {styles: this.data.styles,};},mounted() {},destroyed() {},methods: {}
};
</script><style lang="less" scoped>
@keyframes spin {50% {transform: translate(-50%, -101%) rotate(500deg);}100% {transform: translate(-50%, -101%) rotate(1000deg);}
}
.wave_content {width: 100%;display: flex;justify-content: center;flex-direction: column;align-items: center;padding: 0 10px;box-sizing: border-box;
}
.wave_progress {width: 140px;height: 140px;border-radius: 50%;background: #ffffff;overflow: hidden;position: relative;border: 3px solid #e4e7ef;padding: 4px;box-sizing: border-box;.wave {position: relative;width: 100%;height: 100%;// background-image: linear-gradient(-180deg, #07c2b7 13%, #07c2b7 100%);border-radius: 50%;display: flex;flex-direction: column;align-items: center;justify-content: center;box-sizing: border-box;}.wave_mask {position: absolute;width: 200%;height: 200%;top: 0;left: 50%;border-radius: 40%;transform: translate(-50%, -101%) rotate(0);animation-name: spin;animation-timing-function: linear;animation-delay: 0s;animation-duration: 16s;animation-iteration-count: infinite;z-index: 20;background-color: #f5f5f5;}
}
#number_contnet {position: absolute;color: #000;font-size: 16px;font-weight: bold;text-align: center;z-index: 100;
}
</style>

二. 环形进度条

实现效果
在这里插入图片描述

实现思路是使用echarts的pie扇形图来绘制
主要是设置radius: [‘75%’, ‘90%’],来实现镂空效果

贴上代码

<!-- eslint-disable vue/multi-word-component-names -->
<template><divclass="percentloop":style="{height: height + 'px',background: styles.compConfig.type === 'dark' ? '#2f3d65' : '#f5f5f5'}"><div:id="forId(index)":ref="forId(index)":key="index"style="height: 140px;width: 140px"class="chart-box"/><div style="margin-top: 14px; display:flex; flex-wrap:wrap"><spanv-show="showActual"style="font-weight: 500;margin-right: 10px">实际: {{ actual }}</span><spanv-show="showObjective"style="font-weight: 500">目标: {{ objective }}</span></div></div>
</template><script>
// import echarts from 'src/utils/echartsLoader.js'; 
import echarts from 'echarts';export default {props: {data: {type: Object,default: () => {}},height: {type: [Number, String],default: 230},index: { // 使用时要保证index 唯一type: [String, Number],default: 0},percentage: { // 进度不必是0-100,值随意, 因为下面有处理type: [Number],default: 0},percent: { // 百分比type: [Number, String],default: 0},title: {type: String,default: ''},actual: { // 实际值type: String,default: ''},objective: { // 目标值type: String,default: ''},showActual: {type: Boolean,default: true},showObjective: {type: Boolean,default: true},color: {type: String,default: ''},},data () {return {styles: this.data.styles};},watch: {percent: { // 百分比变化重新绘制, 可根据业务自行修改要监听的数据handler() {this.$nextTick(() => {this.init();});}},color: { // 颜色变化重新绘制handler() {this.$nextTick(() => {this.init();});}},},mounted() {this.init(); // 渲染完成后绘制},methods: {handlerNumber(num) {  // 函数可处理带% 和千分位的数据, 转化成number给echarts使用, 因为echarts 只能接收number 类型的数据let strNum = JSON.parse(JSON.stringify(num));if (strNum.includes(',')) {strNum = strNum.split(',').reduce((pre, item) => {return pre += item;}, '');}if (strNum.includes('%')) {strNum = strNum.split('%')[0] / 100;}return +strNum;},init() {const actual = this.handlerNumber(this.actual);const objective = this.handlerNumber(this.objective);// console.log('还原的数', actual, objective);// const dom = this.$refs[this.forId(this.index)];const dom = document.getElementById(this.forId(this.index));const chart = echarts.init(dom);// 使用镂空饼图模拟进度条chart.setOption({color: [this.color, '#dbdbdb'],tooltip: {show: false,trigger: 'item',formatter: '{b} : {c} ({d}%)',},legend: {show: false,},series: [{name: '详情',type: 'pie',radius: ['75%', '90%'],hoverAnimation: false,label: {show: true,position: 'center',normal: {show: true,position: 'center',formatter: () => {const str = `${this.percent}\n${this.title}`; // 图中间内容 \n 进行换行return str;},rich: {b: {fontSize: 20,color: 'green',fontWeight: 'bold',},c: {fontSize: 13,color: 'skyblue',lineHeight: 30,},},textStyle: {fontSize: 16,fontWeight: 600,color: '#000',},},},data: [{value: actual, // 实际值},{// 如果实际值为0 则直接用目标值的进度沾满整个进度条value: actual !== 0 ? objective - actual < 0 ? 0 : objective - actual : 100, // 目标值}],silent: true,// emphasis: {//   itemStyle: {//     shadowBlur: 10,//     shadowOffsetX: 0,//     shadowColor: 'rgba(0, 0, 0, 0.5)',//   },// },},],});},forId(index) { // 主要是为了创建唯一id, 可根据业务自行调整return this.data.i + index;},}
};
</script><style scoped lang="less">
.percentloop {width: 100%;display: flex;flex-direction: column;align-items: center;justify-content: center;background: #f5f5f5;
}
</style>

这篇关于vue 实现水波进度条和环形进度条效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/205844

相关文章

Flutter实现文字镂空效果的详细步骤

《Flutter实现文字镂空效果的详细步骤》:本文主要介绍如何使用Flutter实现文字镂空效果,包括创建基础应用结构、实现自定义绘制器、构建UI界面以及实现颜色选择按钮等步骤,并详细解析了混合模... 目录引言实现原理开始实现步骤1:创建基础应用结构步骤2:创建主屏幕步骤3:实现自定义绘制器步骤4:构建U

SpringBoot中四种AOP实战应用场景及代码实现

《SpringBoot中四种AOP实战应用场景及代码实现》面向切面编程(AOP)是Spring框架的核心功能之一,它通过预编译和运行期动态代理实现程序功能的统一维护,在SpringBoot应用中,AO... 目录引言场景一:日志记录与性能监控业务需求实现方案使用示例扩展:MDC实现请求跟踪场景二:权限控制与

Android实现定时任务的几种方式汇总(附源码)

《Android实现定时任务的几种方式汇总(附源码)》在Android应用中,定时任务(ScheduledTask)的需求几乎无处不在:从定时刷新数据、定时备份、定时推送通知,到夜间静默下载、循环执行... 目录一、项目介绍1. 背景与意义二、相关基础知识与系统约束三、方案一:Handler.postDel

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

Python实现微信自动锁定工具

《Python实现微信自动锁定工具》在数字化办公时代,微信已成为职场沟通的重要工具,但临时离开时忘记锁屏可能导致敏感信息泄露,下面我们就来看看如何使用Python打造一个微信自动锁定工具吧... 目录引言:当微信隐私遇到自动化守护效果展示核心功能全景图技术亮点深度解析1. 无操作检测引擎2. 微信路径智能获

Python中pywin32 常用窗口操作的实现

《Python中pywin32常用窗口操作的实现》本文主要介绍了Python中pywin32常用窗口操作的实现,pywin32主要的作用是供Python开发者快速调用WindowsAPI的一个... 目录获取窗口句柄获取最前端窗口句柄获取指定坐标处的窗口根据窗口的完整标题匹配获取句柄根据窗口的类别匹配获取句

在 Spring Boot 中实现异常处理最佳实践

《在SpringBoot中实现异常处理最佳实践》本文介绍如何在SpringBoot中实现异常处理,涵盖核心概念、实现方法、与先前查询的集成、性能分析、常见问题和最佳实践,感兴趣的朋友一起看看吧... 目录一、Spring Boot 异常处理的背景与核心概念1.1 为什么需要异常处理?1.2 Spring B

Python位移操作和位运算的实现示例

《Python位移操作和位运算的实现示例》本文主要介绍了Python位移操作和位运算的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1. 位移操作1.1 左移操作 (<<)1.2 右移操作 (>>)注意事项:2. 位运算2.1

如何在 Spring Boot 中实现 FreeMarker 模板

《如何在SpringBoot中实现FreeMarker模板》FreeMarker是一种功能强大、轻量级的模板引擎,用于在Java应用中生成动态文本输出(如HTML、XML、邮件内容等),本文... 目录什么是 FreeMarker 模板?在 Spring Boot 中实现 FreeMarker 模板1. 环

Qt实现网络数据解析的方法总结

《Qt实现网络数据解析的方法总结》在Qt中解析网络数据通常涉及接收原始字节流,并将其转换为有意义的应用层数据,这篇文章为大家介绍了详细步骤和示例,感兴趣的小伙伴可以了解下... 目录1. 网络数据接收2. 缓冲区管理(处理粘包/拆包)3. 常见数据格式解析3.1 jsON解析3.2 XML解析3.3 自定义