index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // pages/home/index.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. height: app.globalData.height * 2 + 25,
  9. windowHeight: app.globalData.windowHeight,
  10. navbarData: {
  11. name: '新闻'
  12. },
  13. currentTab: 0,
  14. // 國内新聞
  15. oneList: [],
  16. twoList: []
  17. },
  18. // 禁止左右滑动
  19. stopTab: function (e) {
  20. return false
  21. },
  22. //点击切换
  23. clickTab: function (e) {
  24. var that = this;
  25. if (this.data.currentTab === e.target.dataset.current) {
  26. return false;
  27. } else {
  28. that.setData({
  29. currentTab: e.target.dataset.current
  30. })
  31. }
  32. },
  33. detail: function (data) {
  34. wx.navigateTo({
  35. url: `/pages/news/detail?id=${data.detail.id}`
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. wx.request({
  43. url: `${app.globalData.publicUrl}/api/st/system/news`,
  44. method: "get",
  45. header: { 'x-tenant': 'test' },
  46. data: { "type": '国内新闻' },
  47. success: res => {
  48. this.setData({ oneList: res.data.data })
  49. },
  50. error: err => {
  51. wx.showToast({
  52. title: err.msg,
  53. icon: 'error'
  54. })
  55. }
  56. })
  57. wx.request({
  58. url: `${app.globalData.publicUrl}/api/st/system/news`,
  59. method: "get",
  60. header: { 'x-tenant': 'test' },
  61. data: { "type": '健康资讯' },
  62. success: res => {
  63. this.setData({ twoList: res.data.data })
  64. },
  65. error: err => {
  66. wx.showToast({
  67. title: err.msg,
  68. icon: 'error'
  69. })
  70. }
  71. })
  72. },
  73. /**
  74. * 生命周期函数--监听页面初次渲染完成
  75. */
  76. onReady: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面显示
  80. */
  81. onShow: function () {
  82. if (typeof this.getTabBar === 'function' &&
  83. this.getTabBar()) {
  84. this.getTabBar().setData({
  85. selected: 2
  86. })
  87. }
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })