index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. logo: '',
  14. currentTab: 0,
  15. // 國内新聞
  16. oneList: [],
  17. twoList: []
  18. },
  19. // 禁止左右滑动
  20. stopTab: function (e) {
  21. return false
  22. },
  23. //点击切换
  24. clickTab: function (e) {
  25. var that = this;
  26. if (this.data.currentTab === e.target.dataset.current) {
  27. return false;
  28. } else {
  29. that.setData({
  30. currentTab: e.target.dataset.current
  31. })
  32. }
  33. },
  34. detail: function (data) {
  35. wx.navigateTo({
  36. url: `/pages/news/detail?id=${data.detail.id}`
  37. })
  38. },
  39. /**
  40. * 生命周期函数--监听页面加载
  41. */
  42. onLoad: function (options) {
  43. this.searchST();
  44. wx.request({
  45. url: `${app.globalData.publicUrl}/api/st/system/news`,
  46. method: "get",
  47. header: { 'x-tenant': app.globalData.tenant },
  48. data: { "type": '国内新闻' },
  49. success: res => {
  50. let data = this.dealImg(res.data.data)
  51. this.setData({ oneList: data })
  52. },
  53. error: err => {
  54. wx.showToast({
  55. title: err.msg,
  56. icon: 'error'
  57. })
  58. }
  59. })
  60. wx.request({
  61. url: `${app.globalData.publicUrl}/api/st/system/news`,
  62. method: "get",
  63. header: { 'x-tenant': app.globalData.tenant },
  64. data: { "type": '健康资讯' },
  65. success: res => {
  66. let data = this.dealImg(res.data.data)
  67. this.setData({ twoList: data })
  68. },
  69. error: err => {
  70. wx.showToast({
  71. title: err.msg,
  72. icon: 'error'
  73. })
  74. }
  75. })
  76. },
  77. dealImg(list) {
  78. for (let i of list) {
  79. if (i.img && i.img.length > 0 && i.img[0]) i.url = `${app.globalData.fileUrl}${i.img[0].url}`;
  80. else i.url = this.data.logo;
  81. }
  82. return list;
  83. },
  84. searchST: function () {
  85. wx.request({
  86. url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  87. method: "get",
  88. header: { 'x-tenant': app.globalData.tenant },
  89. data: {},
  90. success: res => {
  91. const { data } = res.data;
  92. this.setData({ logo: `${app.globalData.fileUrl}` + data.img.logo })
  93. },
  94. error: err => {
  95. wx.showToast({
  96. title: err.msg,
  97. icon: 'error'
  98. })
  99. }
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady: function () {
  106. },
  107. /**
  108. * 生命周期函数--监听页面显示
  109. */
  110. onShow: function () {
  111. if (typeof this.getTabBar === 'function' &&
  112. this.getTabBar()) {
  113. this.getTabBar().setData({
  114. selected: 2
  115. })
  116. }
  117. },
  118. /**
  119. * 生命周期函数--监听页面隐藏
  120. */
  121. onHide: function () {
  122. },
  123. /**
  124. * 生命周期函数--监听页面卸载
  125. */
  126. onUnload: function () {
  127. },
  128. /**
  129. * 页面相关事件处理函数--监听用户下拉动作
  130. */
  131. onPullDownRefresh: function () {
  132. },
  133. /**
  134. * 页面上拉触底事件的处理函数
  135. */
  136. onReachBottom: function () {
  137. },
  138. /**
  139. * 用户点击右上角分享
  140. */
  141. onShareAppMessage: function () {
  142. }
  143. })