lyy-progress.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="ly-progress" :style="{height:height+'px',fontSize:height+'px',borderRadius:round?parseFloat(height)/2+'px':'0px'}">
  3. <view class="ly-progress-bar"
  4. :style="{
  5. backgroundColor:bColor,
  6. border:`1px solid ${bColor}`,
  7. width:width,
  8. borderRadius:round?parseFloat(height)/2+'px':'0px',
  9. transition:'0.5s width'
  10. }">
  11. </view>
  12. <text v-if="showInfo" class="ly-progress-text" :style="{lineHeight:height+'px'}">{{percent+'%'}}</text>
  13. </view>
  14. </template>
  15. <script>
  16. export default{
  17. name:'lyyProgress',
  18. props:{
  19. percent:{
  20. type:[Number,String],
  21. default:0
  22. },
  23. height:{
  24. type:[Number,String],
  25. default:10
  26. },
  27. round:{
  28. type:Boolean,
  29. default:false
  30. },
  31. showInfo:{
  32. type:Boolean,
  33. default:false
  34. },
  35. colors:{
  36. type:Array,
  37. default:()=>['#1989FA']
  38. }
  39. },
  40. computed: {
  41. width() {
  42. if (parseFloat(this.percent) < 0) {
  43. return '0%'
  44. } else if (parseFloat(this.percent) > 100) {
  45. return '100%'
  46. } else {
  47. return parseFloat(this.percent) + '%'
  48. }
  49. },
  50. bColor(){
  51. var len = this.colors.length
  52. if(len<1){
  53. return '#1989FA'
  54. }else if(len===1){
  55. return this.colors[0]
  56. }else{
  57. var per = 1/len*100
  58. var num = Math.ceil(this.percent/per)
  59. if(num<len){
  60. return this.colors[num-1]
  61. }else{
  62. return this.colors[len-1]
  63. }
  64. }
  65. }
  66. }
  67. }
  68. </script>
  69. <style lang="scss">
  70. .ly-progress{
  71. position: relative;
  72. min-width: 100%;
  73. display: flex;
  74. align-items: center;
  75. border: 1px solid #dedede;
  76. background-color: #efefef;
  77. .ly-progress-bar{
  78. height: 100%;
  79. width: 0%;
  80. background-color: #1989FA;
  81. border: 1px solid #1989FA;
  82. }
  83. .ly-progress-text{
  84. position: absolute;
  85. top: 0;
  86. right: 5px;
  87. color: black;
  88. }
  89. }
  90. </style>