index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //index.js
  2. //获取应用实例
  3. var imageUtil = require('../../utils/window.js');
  4. const app = getApp()
  5. Page({
  6. data: {
  7. url:'../../images/timg.jpg',
  8. motto: '',
  9. userInfo: {},
  10. hasUserInfo: false,
  11. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  12. imagewidth: 0,//缩放后的宽
  13. imageheight: 0,//缩放后的高
  14. aa:[
  15. {
  16. from:"Investing.com 中文",
  17. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  18. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  19. time:"6天前"
  20. },
  21. {
  22. from:"chinese.aljazeera.net",
  23. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  24. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  25. time:"6天前"
  26. },
  27. {
  28. from:"Investing.com 中文",
  29. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  30. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  31. time:"5天前"
  32. },
  33. {
  34. from:"Investing.com 中文",
  35. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  36. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  37. time:"6天前"
  38. },
  39. {
  40. from:"chinese.aljazeera.net",
  41. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  42. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  43. time:"6天前"
  44. },
  45. {
  46. from:"Investing.com 中文",
  47. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  48. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  49. time:"5天前"
  50. },
  51. {
  52. from:"Investing.com 中文",
  53. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  54. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  55. time:"6天前"
  56. },
  57. {
  58. from:"chinese.aljazeera.net",
  59. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  60. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  61. time:"6天前"
  62. },
  63. {
  64. from:"Investing.com 中文",
  65. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  66. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  67. time:"5天前"
  68. },
  69. {
  70. from:"Investing.com 中文",
  71. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  72. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  73. time:"6天前"
  74. },
  75. {
  76. from:"chinese.aljazeera.net",
  77. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  78. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  79. time:"6天前"
  80. },
  81. {
  82. from:"Investing.com 中文",
  83. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  84. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  85. time:"5天前"
  86. },
  87. {
  88. from:"Investing.com 中文",
  89. nickName:"买入波音(BA.US)好时机?两个问题没解决之前劝你住手",
  90. reward:"今年迄今,美股航空板块受到公共卫生事件的冲击.....",
  91. time:"6天前"
  92. },
  93. {
  94. from:"chinese.aljazeera.net",
  95. nickName: "波音裁员超1.2万人与警惕最坏时刻尚未到来",
  96. reward: "波音公司当地时间27日宣布,将在美国裁减超1...",
  97. time:"6天前"
  98. },
  99. {
  100. from:"Investing.com 中文",
  101. nickName: "美股异动|波音737MAX客机恢复生产,盘前涨逾5%",
  102. reward: "Reuters.美股异动|波音(BA.US)737MAX客...",
  103. time:"5天前"
  104. },
  105. ],
  106. },
  107. //事件处理函数
  108. bindViewTap: function() {
  109. wx.navigateTo({
  110. url: '../logs/logs'
  111. })
  112. },
  113. onReady: function (e) {
  114. // this.computeScrollViewHeight();
  115. // var query = wx.createSelectorQuery()
  116. // query.select('#test').boundingClientRect(function (res) {
  117. // console.log(res.top);
  118. // }).exec();
  119. },
  120. onLoad: function () {
  121. this.computeScrollViewHeight();
  122. // if (app.globalData.userInfo) {
  123. // this.setData({
  124. // userInfo: app.globalData.userInfo,
  125. // hasUserInfo: true
  126. // })
  127. // } else if (this.data.canIUse){
  128. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  129. // // 所以此处加入 callback 以防止这种情况
  130. // app.userInfoReadyCallback = res => {
  131. // this.setData({
  132. // userInfo: res.userInfo,
  133. // hasUserInfo: true
  134. // })
  135. // }
  136. // } else {
  137. // // 在没有 open-type=getUserInfo 版本的兼容处理
  138. // wx.getUserInfo({
  139. // success: res => {
  140. // app.globalData.userInfo = res.userInfo
  141. // this.setData({
  142. // userInfo: res.userInfo,
  143. // hasUserInfo: true
  144. // })
  145. // }
  146. // })
  147. // }
  148. },
  149. computeScrollViewHeight() {
  150. var that = this
  151. let query = wx.createSelectorQuery().in(that)
  152. query.select('.userinfo').boundingClientRect()
  153. query.select('.search').boundingClientRect()
  154. query.select('.news').boundingClientRect()
  155. query.exec(res => {
  156. let topHeight = res[0].height
  157. let searchHeight = res[1].height
  158. let titleHeight = res[2].height
  159. let windowHeight = wx.getSystemInfoSync().windowHeight
  160. let windowWidth = wx.getSystemInfoSync().windowWidth
  161. let height = windowHeight - topHeight - searchHeight - titleHeight
  162. let ratio = 750 / windowWidth
  163. let scrollHeight = height * ratio - 50
  164. that.setData({ scrollHeight: scrollHeight})
  165. })
  166. },
  167. imageLoad: function (e) {
  168. var imageSize = imageUtil.imageUtil(e)
  169. this.setData({
  170. imagewidth: imageSize.imageWidth,
  171. imageheight: imageSize.imageHeight
  172. })
  173. },
  174. getUserInfo: function(e) {
  175. console.log(e)
  176. app.globalData.userInfo = e.detail.userInfo
  177. this.setData({
  178. userInfo: e.detail.userInfo,
  179. hasUserInfo: true
  180. })
  181. }
  182. })