gui-progress-scrollview.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <view class="">
  3. <scroll-view
  4. :scroll-x="true"
  5. class="gui-scroll-x"
  6. @scroll="scrolling"
  7. @scrolltolower="scrolltolower"
  8. @scrolltoupper="scrolltoupper"
  9. :show-scrollbar="false">
  10. <slot></slot>
  11. </scroll-view>
  12. <view class="gui-psv-progress"
  13. v-if="progressWidth > 0"
  14. :style="{
  15. width : progressWidth+'rpx',
  16. height : progressHeight+'rpx',
  17. borderRadius : progressRadius+'rpx',
  18. backgroundColor : progressBG
  19. }">
  20. <view class="gui-psv-progress-bar"
  21. v-if="progressWidth > 0"
  22. :style="{
  23. width : progressBarWidth+'rpx',
  24. height : progressHeight+'rpx',
  25. borderRadius : progressRadius+'rpx',
  26. backgroundColor : progressBarBG,
  27. marginLeft : marginLeft +'rpx'
  28. }"></view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. name : "gui-progress-scrollview",
  35. data() {
  36. return {
  37. warpWitdh : 350,
  38. marginLeft : 0
  39. }
  40. },
  41. props : {
  42. width : {
  43. type : Number,
  44. default : 700
  45. },
  46. progressWidth : {
  47. type : Number,
  48. default : 200
  49. },
  50. progressHeight : {
  51. type : Number,
  52. default : 10
  53. },
  54. progressRadius : {
  55. type : Number,
  56. default : 10
  57. },
  58. progressBG : {
  59. type : String,
  60. default : '#D1D1D1'
  61. },
  62. progressBarWidth : {
  63. type : Number,
  64. default : 60
  65. },
  66. progressBarBG : {
  67. type : String,
  68. default : '#008AFF'
  69. }
  70. },
  71. created:function(){
  72. this.warpWitdh = uni.upx2px(this.width);
  73. },
  74. methods:{
  75. scrolling : function (event) {
  76. let scrollLeft = event.detail.scrollLeft ;
  77. let scrllWidth = event.detail.scrollWidth - this.warpWitdh;
  78. let percentage = scrollLeft / scrllWidth;
  79. percentage *= 100;
  80. percentage = parseInt(percentage);
  81. if(percentage > 90){percentage = 100;}
  82. if(percentage < 0){percentage = 0;}
  83. this.percentage = percentage;
  84. let marginLeft = (this.progressWidth - this.progressBarWidth) * this.percentage;
  85. this.marginLeft = parseInt(marginLeft / 100);
  86. this.$emit('scrolling', scrllWidth, scrollLeft, percentage);
  87. },
  88. scrolltolower : function () {
  89. setTimeout(()=>{
  90. this.percentage = 100;
  91. this.marginLeft = this.progressWidth - this.progressBarWidth;
  92. this.$emit('scrolltolower');
  93. },300);
  94. },
  95. scrolltoupper : function () {
  96. setTimeout(()=>{
  97. this.percentage = 0;
  98. this.marginLeft = 0;
  99. this.$emit('scrolltoupper');
  100. },300);
  101. }
  102. }
  103. }
  104. </script>
  105. <style scoped>
  106. .gui-psv-progress{background-color:#F8F8F8; border-radius:30rpx;}
  107. .gui-psv-progress-bar{}
  108. </style>