gui-progress-scrollview.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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
  17. class="gui-psv-progress"
  18. :class="progressClass"
  19. v-if="progressWidth > 0"
  20. :style="{
  21. width : progressWidth+'rpx',
  22. height : progressHeight+'rpx',
  23. borderRadius : progressRadius+'rpx'
  24. }">
  25. <view
  26. class="gui-psv-progress-bar"
  27. :class="progressBarClass"
  28. v-if="progressWidth > 0"
  29. :style="{
  30. width : progressBarWidth+'rpx',
  31. height : progressHeight+'rpx',
  32. borderRadius : progressRadius+'rpx',
  33. marginLeft : marginLeft +'rpx'
  34. }"></view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. export default {
  41. name : "gui-progress-scrollview",
  42. data() {
  43. return {
  44. warpWitdh : 350,
  45. marginLeft : 0
  46. }
  47. },
  48. props : {
  49. width : {
  50. type : Number,
  51. default : 700
  52. },
  53. progressWidth : {
  54. type : Number,
  55. default : 200
  56. },
  57. progressHeight : {
  58. type : Number,
  59. default : 10
  60. },
  61. progressRadius : {
  62. type : Number,
  63. default : 10
  64. },
  65. progressClass : {
  66. type : Array,
  67. default : function(){
  68. return ['gui-bg-gray'];
  69. }
  70. },
  71. progressBarWidth : {
  72. type : Number,
  73. default : 60
  74. },
  75. progressBarClass : {
  76. type : Array,
  77. default : function(){
  78. return ['gui-bg-primary'];
  79. }
  80. },
  81. progressPosition : {
  82. type:String,
  83. default:'start'
  84. }
  85. },
  86. created:function(){
  87. this.warpWitdh = uni.upx2px(this.width);
  88. },
  89. methods:{
  90. scrolling : function (event) {
  91. let scrollLeft = event.detail.scrollLeft ;
  92. let scrllWidth = event.detail.scrollWidth - this.warpWitdh;
  93. let percentage = scrollLeft / scrllWidth;
  94. percentage *= 100;
  95. percentage = parseInt(percentage);
  96. if(percentage > 90){percentage = 100;}
  97. if(percentage < 0){percentage = 0;}
  98. this.percentage = percentage;
  99. let marginLeft = (this.progressWidth - this.progressBarWidth) * this.percentage;
  100. this.marginLeft = parseInt(marginLeft / 100);
  101. this.$emit('scrolling', scrllWidth, scrollLeft, percentage);
  102. },
  103. scrolltolower : function () {
  104. setTimeout(()=>{
  105. this.percentage = 100;
  106. this.marginLeft = this.progressWidth - this.progressBarWidth;
  107. this.$emit('scrolltolower');
  108. },300);
  109. },
  110. scrolltoupper : function () {
  111. setTimeout(()=>{
  112. this.percentage = 0;
  113. this.marginLeft = 0;
  114. this.$emit('scrolltoupper');
  115. },300);
  116. }
  117. },
  118. emits : ['scrolling', 'scrolltoupper', 'scrolltolower']
  119. }
  120. </script>
  121. <style scoped>
  122. .gui-psv-progress{background-color:#F8F8F8; border-radius:30rpx;}
  123. .gui-psv-progress-bar{}
  124. </style>