knowledge.js 1.8 KB

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