knowledge.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. // pages/knowledge/knowledge.js
  2. const app = getApp()
  3. var host = app.globalData.host;
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. array:['阅读量','转发量','发布时间'],
  10. val: ['read_num', 'forward_num','publish_time'],
  11. index:0,
  12. act:0,
  13. list:[],
  14. list1: [],
  15. show:0,
  16. keyword:'',
  17. total:0,
  18. page:1,
  19. total1: 0,
  20. page1: 1
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function () {
  26. this.setData({
  27. list: [],
  28. total: 0,
  29. page: 1
  30. })
  31. this.getData()
  32. this.getData1()
  33. },
  34. tab: function (e) {
  35. this.setData({
  36. act: e.target.dataset.id
  37. })
  38. // if (e.target.dataset.id == 0){
  39. // this.getData()
  40. // }else{
  41. // this.getData1()
  42. // }
  43. },
  44. search:function(e){
  45. this.setData({
  46. keyword: e.detail.value,
  47. list:[],
  48. page:1,
  49. list1: [],
  50. page1: 1,
  51. })
  52. this.getData();
  53. this.getData1();
  54. },
  55. search1: function (e) {
  56. this.setData({
  57. list: [],
  58. page: 1,
  59. list1: [],
  60. page1: 1
  61. })
  62. this.getData();
  63. this.getData1();
  64. },
  65. showmenu:function(){
  66. this.setData({
  67. show:!this.data.show
  68. })
  69. },
  70. check:function(e){
  71. this.setData({
  72. list:[],
  73. list1: [],
  74. show: 0,
  75. page:1,
  76. page1: 1,
  77. index:e.target.dataset.id
  78. })
  79. this.getData();
  80. this.getData1();
  81. },
  82. //下一页
  83. next:function(){
  84. if(this.data.list.length < this.data.total){
  85. const page = this.data.page+1
  86. this.setData({
  87. page: page
  88. })
  89. this.getData()
  90. }
  91. },
  92. next1: function () {
  93. if (this.data.list1.length < this.data.total1) {
  94. const page = this.data.page1 + 1
  95. this.setData({
  96. page1: page
  97. })
  98. this.getData1()
  99. }
  100. },
  101. //获取所有数据
  102. getData: function () {
  103. wx.showNavigationBarLoading()
  104. const _list=this.data.list;
  105. var index=this.data.index;
  106. wx.request({
  107. url: host + '/api/article/list',
  108. method: 'GET',
  109. data:{
  110. order_by:this.data.val[index],
  111. keyword: this.data.keyword ? this.data.keyword:'',
  112. page:this.data.page
  113. },
  114. success: res=> {
  115. wx.hideNavigationBarLoading()
  116. if(res.data.code == 0){
  117. const list=res.data.data.list;
  118. for(let i=0;i<list.length;i++){
  119. list[i].name = list[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  120. _list.push(list[i])
  121. }
  122. this.setData({
  123. list: _list,
  124. total:res.data.data.total
  125. })
  126. }
  127. }
  128. })
  129. },
  130. //刊群
  131. getData1: function () {
  132. wx.showNavigationBarLoading()
  133. const _list = this.data.list1;
  134. var index = this.data.index;
  135. wx.request({
  136. url: host + '/api/news/list',
  137. method: 'GET',
  138. data: {
  139. order_by: this.data.val[index],
  140. keyword: this.data.keyword ? this.data.keyword : '',
  141. page1: this.data.page1
  142. },
  143. success: res => {
  144. wx.hideNavigationBarLoading()
  145. if (res.data.code == 0) {
  146. const list = res.data.data.list;
  147. for (let i = 0; i < list.length; i++) {
  148. list[i].name = list[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  149. _list.push(list[i])
  150. }
  151. this.setData({
  152. list1: _list,
  153. total1: res.data.data.total
  154. })
  155. }
  156. }
  157. })
  158. },
  159. /**
  160. * 生命周期函数--监听页面初次渲染完成
  161. */
  162. onReady: function () {
  163. },
  164. /**
  165. * 生命周期函数--监听页面显示
  166. */
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })