index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="container">
  3. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption"
  4. @up="upCallback">
  5. <view class="help cont-box b-f" v-for="(item, index) in list.data" :key="index">
  6. <view class="title">
  7. <text>{{ item.title }}</text>
  8. </view>
  9. <view class="content">
  10. <text>{{ item.content }}</text>
  11. </view>
  12. </view>
  13. </mescroll-body>
  14. </view>
  15. </template>
  16. <script>
  17. import MescrollMixin from '@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins'
  18. import * as HelpApi from '@/api/help'
  19. import { getEmptyPaginateObj, getMoreListData } from '@/core/app'
  20. const pageSize = 15
  21. export default {
  22. mixins: [MescrollMixin],
  23. data() {
  24. return {
  25. // 列表数据
  26. list: getEmptyPaginateObj(),
  27. // 上拉加载配置
  28. upOption: {
  29. // 首次自动执行
  30. auto: true,
  31. // 每页数据的数量; 默认10
  32. page: { size: pageSize },
  33. // 数量要大于12条才显示无更多数据
  34. noMoreSize: 12,
  35. // 空布局
  36. empty: {
  37. tip: '亲,暂无相关数据'
  38. }
  39. }
  40. }
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad(options) {},
  46. methods: {
  47. /**
  48. * 上拉加载的回调 (页面初始化时也会执行一次)
  49. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  50. * @param {Object} page
  51. */
  52. upCallback(page) {
  53. const app = this
  54. // 设置列表数据
  55. app.getHelpList(page.num)
  56. .then(list => {
  57. const curPageLen = list.data.length
  58. const totalSize = list.data.total
  59. app.mescroll.endBySize(curPageLen, totalSize)
  60. })
  61. .catch(() => app.mescroll.endErr())
  62. },
  63. // 获取帮助列表
  64. getHelpList(pageNo = 1) {
  65. const app = this
  66. return new Promise((resolve, reject) => {
  67. HelpApi.list({ page: pageNo })
  68. .then(result => {
  69. // 合并新数据
  70. const newList = result.data.list
  71. app.list.data = getMoreListData(newList, app.list, pageNo)
  72. resolve(newList)
  73. })
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .help {
  81. border-bottom: 1rpx solid #f6f6f9;
  82. .title {
  83. font-size: 32rpx;
  84. color: #333;
  85. margin-bottom: 10rpx;
  86. }
  87. .content {
  88. font-size: 26rpx;
  89. color: #666;
  90. }
  91. }
  92. </style>