knowledge.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. show:0,
  15. keyword:'',
  16. total:0,
  17. page:1
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. this.getData()
  24. },
  25. search:function(e){
  26. this.setData({
  27. keyword: e.detail.value
  28. })
  29. this.getData();
  30. },
  31. showmenu:function(){
  32. this.setData({
  33. show:!this.data.show
  34. })
  35. },
  36. check:function(e){
  37. this.setData({
  38. show: 0,
  39. index:e.target.dataset.id
  40. })
  41. this.getData();
  42. },
  43. //下一页
  44. next:function(){
  45. if(this.data.list.length < this.data.total){
  46. const page = this.data.page+1
  47. this.setData({
  48. page: page
  49. })
  50. this.getData()
  51. }
  52. },
  53. //获取所有数据
  54. getData: function () {
  55. wx.showNavigationBarLoading()
  56. const _list=this.data.list;
  57. var index=this.data.index;
  58. wx.request({
  59. url: host + '/api/article/list',
  60. method: 'GET',
  61. data:{
  62. order_by:this.data.val[index],
  63. keyword:this.data.keyword,
  64. page:this.data.page
  65. },
  66. success: res=> {
  67. wx.hideNavigationBarLoading()
  68. if(res.data.code == 0){
  69. const list=res.data.data.list;
  70. for(let i=0;i<list.length;i++){
  71. _list.push(list[i])
  72. }
  73. this.setData({
  74. list: _list,
  75. total:res.data.data.total
  76. })
  77. }
  78. }
  79. })
  80. },
  81. /**
  82. * 生命周期函数--监听页面初次渲染完成
  83. */
  84. onReady: function () {
  85. },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow: function () {
  90. },
  91. /**
  92. * 生命周期函数--监听页面隐藏
  93. */
  94. onHide: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面卸载
  98. */
  99. onUnload: function () {
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh: function () {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. onReachBottom: function () {
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. }
  116. })