u-line-progress.vue 4.1 KB

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