gui-progress-scrollview.vue 2.8 KB

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