index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import { getArticleCategoryList, getArticleList, getArticleHotList, getArticleBannerList } from '../../api/api.js'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. parameter: {
  9. navbar: '1',
  10. return: '1',
  11. title: '文档资讯',
  12. color: false
  13. },
  14. imgUrls: [],
  15. articleList: [],
  16. indicatorDots: false,
  17. circular: true,
  18. autoplay: true,
  19. interval: 3000,
  20. duration: 500,
  21. navList: [],
  22. active: 0,
  23. page: 1,
  24. limit: 8,
  25. status: false,
  26. scrollLeft: 0
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {},
  32. getArticleHot: function () {
  33. var that = this
  34. getArticleHotList().then(res => {
  35. that.setData({
  36. articleList: res.data
  37. })
  38. })
  39. },
  40. getArticleBanner: function () {
  41. var that = this
  42. getArticleBannerList().then(res => {
  43. that.setData({
  44. imgUrls: res.data
  45. })
  46. })
  47. },
  48. getCidArticle: function () {
  49. var that = this
  50. if (that.data.active == 0) return
  51. var limit = that.data.limit
  52. var page = that.data.page
  53. var articleList = that.data.articleList
  54. if (that.data.status) return
  55. getArticleList(that.data.active, {
  56. page: page,
  57. limit: limit
  58. }).then(res => {
  59. var articleListNew = []
  60. var len = res.data.length
  61. articleListNew = articleList.concat(res.data)
  62. that.data.page++
  63. that.setData({
  64. articleList: articleListNew,
  65. status: limit > len,
  66. page: that.data.page
  67. })
  68. })
  69. },
  70. getArticleCate: function () {
  71. var that = this
  72. getArticleCategoryList().then(res => {
  73. that.setData({
  74. navList: res.data
  75. })
  76. })
  77. },
  78. tabSelect(e) {
  79. this.setData({
  80. active: e.currentTarget.dataset.id,
  81. scrollLeft: (e.currentTarget.dataset.id - 1) * 50
  82. })
  83. if (this.data.active == 0) this.getArticleHot()
  84. else {
  85. this.setData({
  86. articleList: [],
  87. page: 1,
  88. status: false
  89. })
  90. this.getCidArticle()
  91. }
  92. },
  93. /**
  94. * 生命周期函数--监听页面初次渲染完成
  95. */
  96. onReady: function () {},
  97. /**
  98. * 生命周期函数--监听页面显示
  99. */
  100. onShow: function () {
  101. this.getArticleHot()
  102. this.getArticleBanner()
  103. this.getArticleCate()
  104. this.setData({
  105. status: false,
  106. page: 1,
  107. articleList: []
  108. })
  109. this.getCidArticle()
  110. },
  111. /**
  112. * 生命周期函数--监听页面隐藏
  113. */
  114. onHide: function () {},
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload: function () {},
  119. /**
  120. * 页面相关事件处理函数--监听用户下拉动作
  121. */
  122. onPullDownRefresh: function () {},
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom: function () {
  127. this.getCidArticle()
  128. },
  129. /**
  130. * 用户点击右上角分享
  131. */
  132. onShareAppMessage: function () {}
  133. })