index.js 6.8 KB

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