knowledge.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. if(this.data.keyword == ''){
  45. wx.showLoading({
  46. title: '加载中',
  47. })
  48. }
  49. var that = this;
  50. var index=this.data.index;
  51. wx.request({
  52. url: host + '/api/article/list',
  53. method: 'GET',
  54. data:{
  55. order_by:this.data.val[index],
  56. keyword:this.data.keyword
  57. },
  58. success: function (res) {
  59. wx.hideLoading();
  60. that.setData({
  61. list: res.data.data.list
  62. })
  63. }
  64. })
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload: function () {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function () {
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. }
  101. })