index.js 6.6 KB

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