项目中自定义进度条的实现

先看效果:

 

直接上代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
let arr = [0,1,16]
function setProcessStyle(arr = [1, 2, 3]) { 
      // 待生产
      // 已组模完成
      // 隐蔽验收
      // 已浇筑
      // 已浇筑
      let num1 = arr[0];
      let num2 = num1 + arr[1];
      let num3 = num2 + arr[2];
      let styleArr = [
      toPercentage(num1 / num3) ,
      toPercentage(num2 / num3),
        '100%'
      ];
      console.log(styleArr)
      let colors = ['#1b54f4', '#ff8600', '#00c800', '#5c0a98', '#021e66'];     
      let str = `linear-gradient(to right,${colors[0]} 0%,${colors[0]} ${styleArr[0]},${colors[1]} ${styleArr[0]},${colors[1]} ${styleArr[1]},${colors[2]} ${styleArr[1]},${colors[2]} ${styleArr[2]})`;          
      return str          
    }<br>   
    function toPercentage(data) {
      var str = Number(data * 100).toFixed(1);
      str += '%';
      return str;
    }<br><br>    state.processStyle =  setProcessStyle(arr)

  

1
<div :style="{ background:processStyle }" class="process"></div>

 

1
&::before  &::after  是为了让  el-popover  组件的触发区域更大
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
.process {
              position: relative;
              cursor: pointer;
              width: 100%;
              height: 4px;
              margin-top: 20px;
              border-radius: 4px;
              &::before {
                width: 100%;
                top: -4px;
                left: 0;
                content: '';
                position: absolute;
                height: 4px;
              }
              &::after {
                width: 100%;
                top: 4px;
                left: 0;
                content: '';
                position: absolute;
                height: 4px;
              }
            }

  

 

posted @   福超  阅读(42)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
点击右上角即可分享
微信分享提示