1
Huangxiaoqiang-03
2024-11-11 d100db102ded4dc2047f1b92f4ed0ed4c18d8ee4
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
  <view
    class="tn-line-progress-class tn-line-progress"
    :style="[progressStyle]"
  >
    <view
      class="tn-line-progress--active"
      :class="[
        $t.color.getBackgroundColorInternalClass(activeColor),
        striped ? stripedAnimation ? 'tn-line-progress__striped tn-line-progress__striped--active' : 'tn-line-progress__striped' : '',
      ]"
      :style="[progressActiveStyle]"
    >
      <slot v-if="$slots.default || $slots.$default"></slot>
      <block v-else-if="showPercent">{{ percent + '%' }}</block>
    </view>
  </view>
</template>
 
<script>
  export default {
    name: 'tn-line-progress',
    props: {
      // 进度(百分比)
      percent: {
        type: Number,
        default: 0,
        validator: val => {
          return val >= 0 && val <= 100
        }
      },
      // 高度
      height: {
        type: Number,
        default: 0
      },
      // 是否显示为圆角
      round: {
        type: Boolean,
        default: true
      },
      // 是否显示条纹
      striped: {
        type: Boolean,
        default: false
      },
      // 条纹是否运动
      stripedAnimation: {
        type: Boolean,
        default: true
      },
      // 激活部分颜色
      activeColor: {
        type: String,
        default: ''
      },
      // 非激活部分颜色
      inactiveColor: {
        type: String,
        default: ''
      },
      // 是否显示进度条内部百分比值
      showPercent: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      progressStyle() {
        let style = {}
        style.borderRadius = this.round ? '100rpx' : 0
        if (this.height) {
          style.height = this.$t.string.getLengthUnitValue(this.height)
        }
        if (this.inactiveColor) {
          style.backgroundColor = this.inactiveColor
        }
        return style
      },
      progressActiveStyle() {
        let style = {}
        style.width = this.percent + '%'
        if (this.$t.color.getBackgroundColorStyle(this.activeColor)) {
          style.backgroundColor = this.$t.color.getBackgroundColorStyle(this.activeColor)
        }
        return style
      }
    },
    data() {
      return {
        
      }
    },
    
  }
</script>
 
<style lang="scss" scoped>
  
  .tn-line-progress {
    /* #ifndef APP-NVUE */
    display: inline-flex;
    /* #endif */
    align-items: center;
    width: 100%;
    height: 28rpx;
    overflow: hidden;
    border-radius: 100rpx;
    background-color: $tn-progress-bg-color;
    
    &--active {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-items: flex-end;
      justify-content: space-around;
      width: 0;
      height: 100%;
      font-size: 20rpx;
      color: #FFFFFF;
      background-color: $tn-main-color;
      transition: all 0.3s ease;
    }
    
    &__striped {
      background-image: linear-gradient(45deg, rgba(255, 255, 255, 0.15) 25%, transparent 25%, transparent 50%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0.15) 75%, transparent 75%, transparent);
      background-size: 80rpx 80rpx;
      
      &--active {
        animation: progress-striped 2s linear infinite;
      }
    }
  }
  
  @keyframes progress-striped {
    0% {
      background-position: 0 0;
    }
    100% {
      background-position: 80rpx 0;
    }
  }
</style>