废话 不多少说 ,直接上代码

新建文件 gradual-progress.vue

<!--
* @Author: gfc
* @Date: 2019-11-07 14:00:11
* @LastEditors: gfc
* @LastEditTime: 2019-11-13 10:24:44
* @Description: cp 渐变式进度条
eg:
<cp-progress :percentage="progressnum" style="width:300px"></cp-progress>
-->
<template>
<div class="cp-progress-main">
<div class="cp-progress-bg" :style="{ 'border-radius': bRadius+'px'}">
<div class="cp-progress-bar"
:style="{ width: getPercentage+'%' ,background:getGradient,height:strokeWidth+'px' ,'border-radius': bRadius+'px'}"></div>
</div>
<div class="cp-progress-text" :style="{ 'line-height': (strokeWidth+16)+'px'}">{{getPercentage}}%</div>
</div>
</template>
<script> export default {
data () {
return { }
},
computed: {
// 通过比例 获取 百分比
getPercentage () {
if (this.percentage < 0) {
return 0
} else if (this.percentage > 1) {
return 100
} else {
// console.log(this.percentage)
return parseInt((this.percentage + 0.000006) * 100)
}
},
// 获取 进度条颜色对象
getGradient () {
let linecolor = this.getColorItem(this.percentage)
if (linecolor) {
return 'linear-gradient(90deg,' + linecolor.s + ',' + linecolor.e + ')'
} else {
return ''
}
}
},
methods: {
// 根据进度 获取颜色数组
getColorItem (p) {
let mp = this.getPercentage
for (let sub of this.linearColors) {
if (!sub.ef && mp <= sub.v) {
return sub
} else if (sub.ef && mp < sub.v) {
return sub
}
}
return null
}
},
props: {
// 设置 进度条的 弧度
bRadius: {
type: Number,
default: 4
},
textInside: {
type: Number,
default: 100
},
// 进度条的高度 就是粗细度
strokeWidth: {
type: Number,
default: 8
},
// 进度条 的百分比 [0-1] 的小数
percentage: {
type: Number,
default: 0
},
// 进度条 每个阶段的 颜色组
linearColors: {
type: Array,
default: function () {
return [{ v: 25, s: '#F7564A', e: '#F7564A' }, { v: 50, s: '#F7564A', e: '#F7E04B' }, { v: 100, s: '#F7E04B', e: '#25CCDB', ef: true }, { v: 100, s: '#25CCDB', e: '#25CCDB' }]
}
}
}
}
</script>
<style lang="scss" scoped>
.cp-progress-main {
display: flex;
.cp-progress-bg {
width: 50px;
background: #eaedf4;
flex: 1;
margin: 8px 0;
.cp-progress-bar {
transition: width 1s;
}
}
.cp-progress-text {
width: 50px;
font-size: 12px;
font-weight: 400;
color: #333333; margin-left: 10px;
}
}
</style>

使用方法:

<cp-progress :percentage="progressnum" style="width:300px"></cp-progress>

progressnum : [0-1]

不同的阶段 不同颜色进行设置:已经默认了一组颜色

linearColors
[{ v: 100, s: '#F7E04B', e: '#25CCDB', ef: true }]
v 标识设置的百分比 s为开始颜色 ,e 为结束颜色 ef:标识 包不包含 v这个值,true 标识不包含,默认false包含
v 的值需要从小到大 范围[0-100]

效果:

最新文章

  1. eclipse配置tomcat
  2. @html.ActionLink的几种参数格式
  3. liux vim命令
  4. javascript控制子页面对父页面控件操作
  5. vs自带服务测试工具
  6. U3D 背景音效和事件触发音效
  7. Winform使用DevExpress的WaitDialogForm画面
  8. SQL Server 空间监测
  9. 交互式命令 expect
  10. 终端查询数据库sqlite(创建你自己,或者是coredata创建)那里的东西
  11. iOS UICollectionView高级用法(长按自由移动cell)-新
  12. [译]Selenium Python文档:五、Waits等待
  13. MongoDB环境安装
  14. 12 Nonlinear Transformation
  15. Redis实际开发中常见问题
  16. php 操作数据库
  17. 神州数码OSPF路由汇总配置
  18. JAVA 8 主要新特性 ----------------(四)Lambda函数式接口
  19. Python3基础 while 斐波那契数列
  20. 2018.06.29 NOIP模拟 边的处理(分治+dp)

热门文章

  1. JVM基础回顾记录(一):JVM的内存模型
  2. Django django-cors-headers实现防跨域
  3. redis(二)集群 redis-cluster &amp; redis主从同步
  4. [译]Vulkan教程(14)图形管道基础之固定功能
  5. Python中容易忽视的知识点
  6. Web安全测试学习笔记-DVWA-登录密码爆破(使用Burp Suite)
  7. C#冒泡算法
  8. 基于STM32F429的ADS1115驱动程序
  9. 什么是StatefulSet
  10. C#二位数组 数组矩阵对角线之和