index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. Page({
  5. data: {
  6. url:'../../images/timg.jpg',
  7. motto: '',
  8. userInfo: {},
  9. hasUserInfo: false,
  10. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  11. aa:[
  12. {
  13. nickName:"wang",
  14. reward:"2"
  15. },
  16. {
  17. nickName: "wang",
  18. reward: "2"
  19. },
  20. {
  21. nickName: "wang",
  22. reward: "2"
  23. },
  24. {
  25. nickName: "wang",
  26. reward: "2"
  27. },
  28. {
  29. nickName: "wang",
  30. reward: "2"
  31. },
  32. {
  33. nickName: "wang",
  34. reward: "2"
  35. },
  36. {
  37. nickName: "wang",
  38. reward: "2"
  39. },
  40. {
  41. nickName: "wang",
  42. reward: "2"
  43. },
  44. {
  45. nickName: "wang",
  46. reward: "2"
  47. },
  48. {
  49. nickName: "wang",
  50. reward: "2"
  51. },
  52. ],
  53. },
  54. //事件处理函数
  55. bindViewTap: function() {
  56. wx.navigateTo({
  57. url: '../logs/logs'
  58. })
  59. },
  60. onReady: function (e) {
  61. this.computeScrollViewHeight();
  62. // var query = wx.createSelectorQuery()
  63. // query.select('#test').boundingClientRect(function (res) {
  64. // console.log(res.top);
  65. // }).exec();
  66. },
  67. onLoad: function () {
  68. // this.computeScrollViewHeight();
  69. // if (app.globalData.userInfo) {
  70. // this.setData({
  71. // userInfo: app.globalData.userInfo,
  72. // hasUserInfo: true
  73. // })
  74. // } else if (this.data.canIUse){
  75. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  76. // // 所以此处加入 callback 以防止这种情况
  77. // app.userInfoReadyCallback = res => {
  78. // this.setData({
  79. // userInfo: res.userInfo,
  80. // hasUserInfo: true
  81. // })
  82. // }
  83. // } else {
  84. // // 在没有 open-type=getUserInfo 版本的兼容处理
  85. // wx.getUserInfo({
  86. // success: res => {
  87. // app.globalData.userInfo = res.userInfo
  88. // this.setData({
  89. // userInfo: res.userInfo,
  90. // hasUserInfo: true
  91. // })
  92. // }
  93. // })
  94. // }
  95. },
  96. computeScrollViewHeight() {
  97. let that = this
  98. let query = wx.createSelectorQuery().in(this)
  99. query.select('.userinfo').boundingClientRect()
  100. query.select('.search').boundingClientRect()
  101. query.select('.news').boundingClientRect()
  102. query.exec(res => {
  103. let topHeight = res[0].height
  104. let searchHeight = res[1].height
  105. let titleHeight = res[2].height
  106. let windowHeight = wx.getSystemInfoSync().windowHeight
  107. let windowWidth = wx.getSystemInfoSync().windowWidth
  108. let height = windowHeight - topHeight - searchHeight - titleHeight
  109. let ratio = 750 / windowWidth
  110. let scrollHeight = height * ratio - 50
  111. this.setData({ scrollHeight: scrollHeight})
  112. })
  113. },
  114. getUserInfo: function(e) {
  115. console.log(e)
  116. app.globalData.userInfo = e.detail.userInfo
  117. this.setData({
  118. userInfo: e.detail.userInfo,
  119. hasUserInfo: true
  120. })
  121. }
  122. })