knowledge.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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: ['publish_time','read_num', 'forward_num'],
  11. index:0,
  12. act:0,
  13. list:[],
  14. list1: [],
  15. show:0,
  16. keyword:'',
  17. total:0,
  18. page:1,
  19. total1: 0,
  20. page1: 1
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function () {
  26. this.setData({
  27. list: [],
  28. total: 0,
  29. page: 1
  30. })
  31. this.getData()
  32. this.getData1()
  33. },
  34. tab: function (e) {
  35. this.setData({
  36. act: e.target.dataset.id
  37. })
  38. // if (e.target.dataset.id == 0){
  39. // this.getData()
  40. // }else{
  41. // this.getData1()
  42. // }
  43. if (e.target.dataset.id == 2){
  44. this.toknowledge()
  45. }
  46. },
  47. search:function(e){
  48. this.setData({
  49. keyword: e.detail.value,
  50. list:[],
  51. page:1,
  52. list1: [],
  53. page1: 1,
  54. })
  55. this.getData();
  56. this.getData1();
  57. },
  58. search1: function (e) {
  59. this.setData({
  60. list: [],
  61. page: 1,
  62. list1: [],
  63. page1: 1
  64. })
  65. this.getData();
  66. this.getData1();
  67. },
  68. showmenu:function(){
  69. this.setData({
  70. show:!this.data.show
  71. })
  72. },
  73. check:function(e){
  74. this.setData({
  75. list:[],
  76. list1: [],
  77. show: 0,
  78. page:1,
  79. page1: 1,
  80. index:e.target.dataset.id
  81. })
  82. this.getData();
  83. this.getData1();
  84. },
  85. //下一页
  86. next:function(){
  87. if(this.data.list.length < this.data.total){
  88. const page = this.data.page+1
  89. this.setData({
  90. page: page
  91. })
  92. this.getData()
  93. }
  94. },
  95. next1: function () {
  96. if (this.data.list1.length < this.data.total1) {
  97. const page = this.data.page1 + 1
  98. this.setData({
  99. page1: page
  100. })
  101. this.getData1()
  102. }
  103. },
  104. //获取所有数据
  105. getData: function () {
  106. wx.showNavigationBarLoading()
  107. const _list=this.data.list;
  108. var index=this.data.index;
  109. wx.request({
  110. url: host + '/api/article/list',
  111. method: 'GET',
  112. data:{
  113. order_by:this.data.val[index],
  114. keyword: this.data.keyword ? this.data.keyword:'',
  115. page:this.data.page
  116. },
  117. success: res=> {
  118. wx.hideNavigationBarLoading()
  119. if(res.data.code == 0){
  120. const list=res.data.data.list;
  121. for(let i=0;i<list.length;i++){
  122. list[i].name = list[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  123. _list.push(list[i])
  124. }
  125. this.setData({
  126. list: _list,
  127. total:res.data.data.total
  128. })
  129. }
  130. }
  131. })
  132. },
  133. //刊群
  134. getData1: function () {
  135. wx.showNavigationBarLoading()
  136. const _list = this.data.list1;
  137. var index = this.data.index;
  138. wx.request({
  139. url: host + '/api/news/list',
  140. method: 'GET',
  141. data: {
  142. order_by: this.data.val[index],
  143. keyword: this.data.keyword ? this.data.keyword : '',
  144. page1: this.data.page1
  145. },
  146. success: res => {
  147. wx.hideNavigationBarLoading()
  148. if (res.data.code == 0) {
  149. const list = res.data.data.list;
  150. for (let i = 0; i < list.length; i++) {
  151. list[i].name = list[i].name.replace(this.data.keyword, '<span style="color:#3780CD;">' + this.data.keyword + '</span>')
  152. _list.push(list[i])
  153. }
  154. this.setData({
  155. list1: _list,
  156. total1: res.data.data.total
  157. })
  158. }
  159. }
  160. })
  161. },
  162. toknowledge(){
  163. this.setData({
  164. isJp: false
  165. })
  166. wx.navigateToMiniProgram({
  167. appId: 'wxb2b094cfad8a8e6f',
  168. path: 'pages/index/index',
  169. extarData: {
  170. open: 'auth'
  171. },
  172. envVersion: 'release',
  173. success(res) {
  174. // 打开成功
  175. console.log('打开成功');
  176. }
  177. });
  178. },
  179. swchange:function(e){
  180. this.setData({
  181. act: e.detail.current
  182. })
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady: function () {
  188. },
  189. /**
  190. * 生命周期函数--监听页面显示
  191. */
  192. /**
  193. * 生命周期函数--监听页面隐藏
  194. */
  195. onHide: function () {
  196. },
  197. /**
  198. * 生命周期函数--监听页面卸载
  199. */
  200. onUnload: function () {
  201. },
  202. /**
  203. * 页面相关事件处理函数--监听用户下拉动作
  204. */
  205. onPullDownRefresh: function () {
  206. },
  207. /**
  208. * 页面上拉触底事件的处理函数
  209. */
  210. onReachBottom: function () {
  211. },
  212. /**
  213. * 用户点击右上角分享
  214. */
  215. onShareAppMessage: function () {
  216. }
  217. })