mobileSwiperScroll.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view>
  3. <!-- #ifdef APP-PLUS -->
  4. <swiper
  5. :current="tabIndex"
  6. :style="{
  7. height: scrollHeight + 'px',
  8. }"
  9. @change="$emit('tabIndexChange', $event.detail.current)"
  10. >
  11. <swiper-item
  12. v-for="(item, index) in tabList"
  13. :key="index + 'tabList'"
  14. >
  15. <list
  16. :style="{
  17. height: scrollHeight + 'px',
  18. }"
  19. class="contentList"
  20. show-scrollbar
  21. :index="index"
  22. :id="`contentList_${index}`"
  23. :fixFreezing="true"
  24. ref="mob_list"
  25. >
  26. <refresh
  27. v-if="item.canRefreshing"
  28. class="refreshView"
  29. @refresh="$emit('refresh', index)"
  30. @pullingdown="$emit('pullingdown', { event: $event, index })"
  31. :display="item.isRefreshing ? 'show' : 'hide'"
  32. >
  33. <view class="content">
  34. <template v-if="item.refreshType == 'waitPullUp'">
  35. <text class="statusText">↓下拉刷新</text>
  36. </template>
  37. <template v-if="item.refreshType == 'waitRelease'">
  38. <text class="statusText">松手刷新</text>
  39. </template>
  40. <template v-if="item.refreshType == 'refreshing'">
  41. <text class="statusText">刷新中...</text>
  42. </template>
  43. <template v-if="item.refreshType == 'success'">
  44. <text class="statusText">刷新成功</text>
  45. </template>
  46. <template v-if="item.refreshType == 'error'">
  47. <text class="statusText">刷新失败</text>
  48. </template>
  49. </view>
  50. </refresh>
  51. <slot
  52. :item="item"
  53. :index="index"
  54. ></slot>
  55. <cell ref="mob_list_end">
  56. <view></view>
  57. </cell>
  58. </list>
  59. </swiper-item>
  60. </swiper>
  61. <!-- #endif -->
  62. <!-- #ifndef APP-PLUS -->
  63. <scroll-view
  64. scroll-y
  65. :style="{
  66. height: scrollHeight + 'px',
  67. }"
  68. :scroll-top="scrollTop"
  69. >
  70. <slot
  71. :item="tabList[tabIndex]"
  72. :index="tabIndex"
  73. ></slot>
  74. </scroll-view>
  75. <!-- #endif -->
  76. </view>
  77. </template>
  78. <script>
  79. export default {
  80. props: {
  81. /**
  82. * 分类索引
  83. */
  84. tabIndex: {
  85. type: Number,
  86. default: 0,
  87. },
  88. /**
  89. * tab列表
  90. */
  91. tabList: {
  92. type: Array,
  93. default: () => [],
  94. },
  95. /**
  96. * 滚动高度
  97. */
  98. scrollHeight: {
  99. type: Number,
  100. default: 1000,
  101. },
  102. },
  103. data() {
  104. return {
  105. /**
  106. * 滚动位置
  107. */
  108. scrollTop: 0,
  109. };
  110. },
  111. methods: {
  112. /**
  113. * 滚动到列表底部
  114. */
  115. scrollToBottom() {
  116. let that = this;
  117. // #ifdef APP-PLUS
  118. const dom = weex.requireModule("dom");
  119. dom.scrollToElement(that.$refs.mob_list_end[that.tabIndex]);
  120. // #endif
  121. // #ifndef APP-PLUS
  122. that.scrollTop = 999999999 + Math.random();
  123. // #endif
  124. },
  125. },
  126. };
  127. </script>
  128. <style lang="scss" scoped>
  129. .contentList {
  130. display: flex;
  131. flex-direction: column;
  132. align-items: center;
  133. width: 750rpx;
  134. .cell {
  135. display: flex;
  136. flex-direction: row;
  137. justify-content: center;
  138. margin-top: 20rpx;
  139. width: 750rpx;
  140. }
  141. }
  142. .refreshView {
  143. background-color: #fff;
  144. width: 750rpx;
  145. display: flex;
  146. flex-direction: row;
  147. align-items: center;
  148. justify-content: center;
  149. position: absolute;
  150. top: 0px;
  151. left: 0px;
  152. height: 100rpx;
  153. .content {
  154. height: 100rpx;
  155. width: 750rpx;
  156. display: flex;
  157. flex-direction: row;
  158. align-items: center;
  159. justify-content: center;
  160. }
  161. }
  162. .statusText {
  163. color: #8799a3;
  164. font-size: 24rpx;
  165. margin-left: 10rpx;
  166. }
  167. </style>