u-line-progress.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <view class="u-progress" :style="{
  3. borderRadius: round ? '100rpx' : 0,
  4. height: height + 'rpx',
  5. backgroundColor: inactiveColor
  6. }">
  7. <view :class="{'u-striped': striped, 'u-striped-active': striped && stripedActive}" class="u-active" :style="[progressStyle]">{{showPercent ? percent + '%' : ''}}</view>
  8. </view>
  9. </template>
  10. <script>
  11. /**
  12. * lineProgress 线型进度条
  13. * @description 展示操作或任务的当前进度,比如上传文件,是一个线形的进度条。
  14. * @tutorial https://www.uviewui.com/components/lineProgress.html
  15. * @property {String Number} percent 进度条百分比值,为数值类型,0-100
  16. * @property {Boolean} round 进度条两端是否为半圆(默认true)
  17. * @property {String} type 如设置,active-color值将会失效
  18. * @property {String} active-color 进度条激活部分的颜色(默认#19be6b)
  19. * @property {String} inactive-color 进度条的底色(默认#ececec)
  20. * @property {Boolean} show-percent 是否在进度条内部显示当前的百分比值数值(默认true)
  21. * @property {String Number} height 进度条的高度,单位rpx(默认28)
  22. * @property {Boolean} striped 是否显示进度条激活部分的条纹(默认false)
  23. * @property {Boolean} striped-active 条纹是否具有动态效果(默认false)
  24. * @example <u-line-progress :percent="70" :show-percent="true"></u-line-progress>
  25. */
  26. export default {
  27. name: "u-line-progress",
  28. props: {
  29. // 两端是否显示半圆形
  30. round: {
  31. type: Boolean,
  32. default: true
  33. },
  34. // 主题颜色
  35. type: {
  36. type: String,
  37. default: ''
  38. },
  39. // 激活部分的颜色
  40. activeColor: {
  41. type: String,
  42. default: '#19be6b'
  43. },
  44. inactiveColor: {
  45. type: String,
  46. default: '#ececec'
  47. },
  48. // 进度百分比,数值
  49. percent: {
  50. type: Number,
  51. default: 0
  52. },
  53. // 是否在进度条内部显示百分比的值
  54. showPercent: {
  55. type: Boolean,
  56. default: true
  57. },
  58. // 进度条的高度,单位rpx
  59. height: {
  60. type: [Number, String],
  61. default: 28
  62. },
  63. // 是否显示条纹
  64. striped: {
  65. type: Boolean,
  66. default: false
  67. },
  68. // 条纹是否显示活动状态
  69. stripedActive: {
  70. type: Boolean,
  71. default: false
  72. }
  73. },
  74. data() {
  75. return {
  76. }
  77. },
  78. computed: {
  79. progressStyle() {
  80. let style = {};
  81. style.width = this.percent + '%';
  82. if (['success', 'error', 'info', 'primary', 'warning'].indexOf(this.type) >= 0) style.backgroundColor = this.$u.color[
  83. this.type];
  84. else style.backgroundColor = this.activeColor;
  85. return style;
  86. }
  87. },
  88. methods: {
  89. }
  90. }
  91. </script>
  92. <style lang="scss" scoped>
  93. .u-progress {
  94. overflow: hidden;
  95. height: 15px;
  96. display: inline-flex;
  97. align-items: center;
  98. width: 100%;
  99. border-radius: 100rpx;
  100. }
  101. .u-active {
  102. width: 0;
  103. height: 100%;
  104. align-items: center;
  105. display: flex;
  106. justify-items: flex-end;
  107. justify-content: space-around;
  108. font-size: 20rpx;
  109. color: #ffffff;
  110. transition: all 0.4s ease;
  111. }
  112. .u-striped {
  113. 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);
  114. background-size: 39px 39px;
  115. }
  116. .u-striped-active {
  117. animation: progress-stripes 2s linear infinite;
  118. }
  119. @keyframes progress-stripes {
  120. 0% {
  121. background-position: 0 0;
  122. }
  123. 100% {
  124. background-position: 39px 0;
  125. }
  126. }
  127. </style>