knowledge.js 1.8 KB

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