index.js 3.4 KB

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