scroll.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <script>
  2. import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js'
  3. export default {
  4. name: 'scroll',
  5. mixins: [MescrollMixin],
  6. props: {
  7. downOpt: {
  8. // 下拉刷新配置
  9. default: () => ({})
  10. },
  11. upOpt: {
  12. // 上拉加载配置
  13. default: () => ({})
  14. },
  15. isPart: Boolean,
  16. isSticky: Boolean,
  17. height: {
  18. type: [String, Number],
  19. default: ''
  20. },
  21. top: {
  22. type: [String, Number],
  23. default: 0
  24. },
  25. bottom: {
  26. type: [String, Number],
  27. default: 0
  28. }
  29. },
  30. inject: {
  31. downCb: {
  32. default: 'no Function'
  33. },
  34. getList: {
  35. default: () => 0
  36. }
  37. },
  38. methods: {
  39. // 下拉刷新的回调
  40. downCbHandle() {
  41. if (typeof this.downCb !== 'function') {
  42. // mescroll mixin 默认方法
  43. this.downCallback()
  44. } else {
  45. // 从父组件传递的方法
  46. this.downCb()
  47. }
  48. },
  49. async upCallback(page) {
  50. try {
  51. const curPageLen = await this.getList({ page: page.num, limit: page.size })
  52. this.mescroll.endSuccess(curPageLen)
  53. // this.mescroll.endSuccess(curPageLen, hasNext)
  54. } catch (e) {
  55. this.mescroll.endErr()
  56. }
  57. },
  58. reload(isShowLoading = true) {
  59. this.mescroll.resetUpScroll(isShowLoading)
  60. }
  61. }
  62. }
  63. </script>
  64. <template>
  65. <!-- <view :class="{ partAutoHeight: isPart }">-->
  66. <view>
  67. <slot name="top"></slot>
  68. <!-- 页面级滚动 -->
  69. <mescroll-body
  70. v-if="!isPart"
  71. ref="mescrollRef"
  72. @init="mescrollInit"
  73. @down="downCbHandle"
  74. @up="upCallback"
  75. :down="downOpt"
  76. :up="upOpt"
  77. :sticky="isSticky"
  78. :top="top"
  79. :bottom="bottom"
  80. :bottombar="false"
  81. >
  82. <slot></slot>
  83. </mescroll-body>
  84. <!-- 局部滚动 -->
  85. <mescroll-uni
  86. v-else
  87. ref="mescrollRef"
  88. @init="mescrollInit"
  89. @down="downCbHandle"
  90. @up="upCallback"
  91. :down="downOpt"
  92. :up="upOpt"
  93. :sticky="isSticky"
  94. :top="top"
  95. :bottom="bottom"
  96. :bottombar="false"
  97. :fixed="false"
  98. :height="height"
  99. >
  100. <!-- // 此处除了不能写原生组件,其他的与 mescroll-body 的一致 -->
  101. <slot></slot>
  102. </mescroll-uni>
  103. <slot name="bottom"></slot>
  104. </view>
  105. </template>
  106. <style lang="scss" scoped>
  107. .partAutoHeight {
  108. height: 100%;
  109. }
  110. </style>