cl-progress.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view class="cl-progress">
  3. <view class="cl-progress-bar" v-if="type === 'line'">
  4. <view class="cl-progress-bar__outer" :style="{ height }">
  5. <view
  6. class="cl-progress-bar__inner"
  7. :style="{
  8. backgroundColor,
  9. width
  10. }"
  11. ></view>
  12. </view>
  13. </view>
  14. <slot name="text">
  15. <view class="cl-progress__text" v-if="showText">
  16. <template v-if="!status">{{ value }}%</template>
  17. <text class="cl-progress__icon" v-else :class="icon"></text>
  18. </view>
  19. </slot>
  20. </view>
  21. </template>
  22. <script>
  23. import { getCurrentColor } from "../../utils";
  24. /**
  25. * progress 进度条
  26. * @description 支持多种颜色显示
  27. * @tutorial https://docs.cool-js.com/uni/components/view/progress.html
  28. * @property {Number} value 绑定值
  29. * @property {String} type 类型
  30. * @property {String} strokeWidth 线条宽度
  31. * @property {String} showText 是否显示文本
  32. * @property {String} color 线条颜色, 支持多色
  33. * @property {String} status 状态
  34. * @property {Boolean} icon 尾部图标
  35. * @example <cl-progress :value="40"></cl-progress>
  36. */
  37. export default {
  38. name: "cl-progress",
  39. props: {
  40. // 绑定值
  41. value: {
  42. type: Number,
  43. default: 0,
  44. required: true
  45. },
  46. // 类型
  47. type: {
  48. type: String,
  49. default: "line"
  50. },
  51. // 线条宽度
  52. strokeWidth: {
  53. type: Number,
  54. default: 12
  55. },
  56. // 是否显示文本
  57. showText: {
  58. type: Boolean,
  59. default: true
  60. },
  61. // 线条颜色, 支持多色
  62. color: {
  63. type: [String, Array],
  64. default: ""
  65. },
  66. // 状态
  67. status: {
  68. type: Boolean
  69. },
  70. // 尾部图标
  71. icon: String
  72. },
  73. computed: {
  74. height() {
  75. return this.strokeWidth + "rpx";
  76. },
  77. width() {
  78. return (
  79. (() => {
  80. if (this.value > 100) {
  81. return 100;
  82. } else if (this.value < 0) {
  83. return 0;
  84. } else {
  85. return this.value;
  86. }
  87. })() + "%"
  88. );
  89. },
  90. backgroundColor() {
  91. return getCurrentColor({
  92. value: this.value,
  93. color: this.color,
  94. max: 100
  95. });
  96. }
  97. }
  98. };
  99. </script>