// pages/knowledge/knowledge.js const app = getApp() var host = app.globalData.host; Page({ /** * 页面的初始数据 */ data: { array:['发布时间','阅读量','转发量'], val: ['publish_time','read_num', 'forward_num'], index:0, act:0, list:[], list1: [], show:0, keyword:'', total:0, page:1, total1: 0, page1: 1 }, /** * 生命周期函数--监听页面加载 */ onLoad: function () { this.setData({ list: [], total: 0, page: 1 }) this.getData() this.getData1() }, tab: function (e) { this.setData({ act: e.target.dataset.id }) // if (e.target.dataset.id == 0){ // this.getData() // }else{ // this.getData1() // } if (e.target.dataset.id == 2){ this.toknowledge() } }, search:function(e){ this.setData({ keyword: e.detail.value, list:[], page:1, list1: [], page1: 1, }) this.getData(); this.getData1(); }, search1: function (e) { this.setData({ list: [], page: 1, list1: [], page1: 1 }) this.getData(); this.getData1(); }, showmenu:function(){ this.setData({ show:!this.data.show }) }, check:function(e){ this.setData({ list:[], list1: [], show: 0, page:1, page1: 1, index:e.target.dataset.id }) this.getData(); this.getData1(); }, //下一页 next:function(){ if(this.data.list.length < this.data.total){ const page = this.data.page+1 this.setData({ page: page }) this.getData() } }, next1: function () { if (this.data.list1.length < this.data.total1) { const page = this.data.page1 + 1 this.setData({ page1: page }) this.getData1() } }, //获取所有数据 getData: function () { wx.showNavigationBarLoading() const _list=this.data.list; var index=this.data.index; wx.request({ url: host + '/api/article/list', method: 'GET', data:{ order_by:this.data.val[index], keyword: this.data.keyword ? this.data.keyword:'', page:this.data.page }, success: res=> { wx.hideNavigationBarLoading() if(res.data.code == 0){ const list=res.data.data.list; for(let i=0;i' + this.data.keyword + '') _list.push(list[i]) } this.setData({ list: _list, total:res.data.data.total }) } } }) }, //刊群 getData1: function () { wx.showNavigationBarLoading() const _list = this.data.list1; var index = this.data.index; wx.request({ url: host + '/api/news/list', method: 'GET', data: { order_by: this.data.val[index], keyword: this.data.keyword ? this.data.keyword : '', page1: this.data.page1 }, success: res => { wx.hideNavigationBarLoading() if (res.data.code == 0) { const list = res.data.data.list; for (let i = 0; i < list.length; i++) { list[i].name = list[i].name.replace(this.data.keyword, '' + this.data.keyword + '') _list.push(list[i]) } this.setData({ list1: _list, total1: res.data.data.total }) } } }) }, toknowledge(){ this.setData({ isJp: false }) wx.navigateToMiniProgram({ appId: 'wxb2b094cfad8a8e6f', path: 'pages/index/index', extarData: { open: 'auth' }, envVersion: 'release', success(res) { // 打开成功 console.log('打开成功'); } }); }, swchange:function(e){ this.setData({ act: e.detail.current }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })