z-paging-swiper-item.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <!-- z-paging -->
  2. <!-- github地址:https://github.com/SmileZXLee/uni-z-paging -->
  3. <!-- dcloud地址:https://ext.dcloud.net.cn/plugin?id=3935 -->
  4. <!-- 反馈QQ群:790460711 -->
  5. <!-- 滑动切换选项卡swiper-item,此组件支持easycom规范,可以在项目中直接引用 -->
  6. <template>
  7. <view class="zp-swiper-item-container">
  8. <z-paging ref="paging" :fixed="false"
  9. :useVirtualList="useVirtualList" :useInnerList="useInnerList" :cellKeyName="cellKeyName" :innerListStyle="innerListStyle"
  10. :preloadPage="preloadPage" :cellHeightMode="cellHeightMode" :virtualScrollFps="virtualScrollFps" :virtualListCol="virtualListCol"
  11. @query="_queryList" @listChange="_updateList" :mounted-auto-call-reload="false" style="height: 100%;">
  12. <slot />
  13. <template v-slot:header>
  14. <slot name="header"/>
  15. </template>
  16. <template v-slot:cell="{item,index}">
  17. <slot name="cell" :item="item" :index="index"/>
  18. </template>
  19. <template v-slot:footer>
  20. <slot name="footer"/>
  21. </template>
  22. </z-paging>
  23. </view>
  24. </template>
  25. <script>
  26. import zPaging from '../z-paging/z-paging'
  27. export default {
  28. name: "z-paging-swiper-item",
  29. components: {
  30. zPaging
  31. },
  32. data() {
  33. return {
  34. firstLoaded: false
  35. }
  36. },
  37. props: {
  38. //当前组件的index,也就是当前组件是swiper中的第几个
  39. tabIndex: {
  40. type: Number,
  41. default: function() {
  42. return 0
  43. }
  44. },
  45. //当前swiper切换到第几个index
  46. currentIndex: {
  47. type: Number,
  48. default: function() {
  49. return 0
  50. }
  51. },
  52. //是否使用虚拟列表,默认为否
  53. useVirtualList: {
  54. type: Boolean,
  55. default: false
  56. },
  57. //是否在z-paging内部循环渲染列表(内置列表),默认为否。若use-virtual-list为true,则此项恒为true
  58. useInnerList: {
  59. type: Boolean,
  60. default: false
  61. },
  62. //内置列表cell的key名称,仅nvue有效,在nvue中开启use-inner-list时必须填此项
  63. cellKeyName: {
  64. type: String,
  65. default: ''
  66. },
  67. //innerList样式
  68. innerListStyle: {
  69. type: Object,
  70. default: function() {
  71. return {};
  72. }
  73. },
  74. //预加载的列表可视范围(列表高度)页数,默认为7,即预加载当前页及上下各7页的cell。此数值越大,则虚拟列表中加载的dom越多,内存消耗越大(会维持在一个稳定值),但增加预加载页面数量可缓解快速滚动短暂白屏问题
  75. preloadPage: {
  76. type: [Number, String],
  77. default: 7
  78. },
  79. //虚拟列表cell高度模式,默认为fixed,也就是每个cell高度完全相同,将以第一个cell高度为准进行计算。可选值【dynamic】,即代表高度是动态非固定的,【dynamic】性能低于【fixed】。
  80. cellHeightMode: {
  81. type: String,
  82. default: 'fixed'
  83. },
  84. //虚拟列表列数,默认为1。常用于每行有多列的情况,例如每行有2列数据,需要将此值设置为2
  85. virtualListCol: {
  86. type: [Number, String],
  87. default: 1
  88. },
  89. //虚拟列表scroll取样帧率,默认为60,过高可能出现卡顿等问题
  90. virtualScrollFps: {
  91. type: [Number, String],
  92. default: 60
  93. },
  94. },
  95. watch: {
  96. currentIndex: {
  97. handler(newVal, oldVal) {
  98. if (newVal === this.tabIndex) {
  99. //懒加载,当滑动到当前的item时,才去加载
  100. if (!this.firstLoaded) {
  101. this.$nextTick(()=>{
  102. let delay = 5;
  103. // #ifdef MP-TOUTIAO
  104. delay = 100;
  105. // #endif
  106. setTimeout(() => {
  107. this.$refs.paging.reload();
  108. }, delay);
  109. })
  110. }
  111. }
  112. },
  113. immediate: true
  114. }
  115. },
  116. methods: {
  117. reload(data) {
  118. this.$refs.paging.reload(data);
  119. },
  120. complete(data) {
  121. this.firstLoaded = true;
  122. this.$refs.paging.complete(data);
  123. },
  124. _queryList(pageNo, pageSize, from) {
  125. this.$emit('query', pageNo, pageSize, from);
  126. },
  127. _updateList(list) {
  128. this.$emit('updateList', list);
  129. }
  130. }
  131. }
  132. </script>
  133. <style scoped>
  134. .zp-swiper-item-container {
  135. /* #ifndef APP-NVUE */
  136. height: 100%;
  137. /* #endif */
  138. /* #ifdef APP-NVUE */
  139. flex: 1;
  140. /* #endif */
  141. }
  142. </style>