tn-line-progress.vue 3.3 KB

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