me.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. // pages/me/me.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. baseImgUrl: app.globalData.baseImgUrl,
  9. thumbnail: app.globalData.thumbnail,
  10. hiddenModel: false,
  11. level:3,
  12. ageGroup:2,
  13. statusBar: app.globalData.statusBar,
  14. meList:[
  15. {
  16. id:'',
  17. img:'../../image/pai_hang_bang.png',
  18. url:'ranking',
  19. },
  20. {
  21. id: '',
  22. img: '../../image/wo_de_ce_shi.png',
  23. url: 'result'
  24. },
  25. {
  26. id: '',
  27. img: '../../image/ce_yi_ce.png',
  28. url: 'set_info'
  29. },
  30. ]
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad: function (options) {
  36. app.getWxloginCode(code => {
  37. this.setData({ code })
  38. })
  39. const userInfo = wx.getStorageSync('userInfo')
  40. if (userInfo) {
  41. this.setData({ userInfo})
  42. }
  43. this.getPersonInfo();
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面隐藏
  57. */
  58. onHide: function () {
  59. },
  60. /**
  61. * 生命周期函数--监听页面卸载
  62. */
  63. onUnload: function () {
  64. },
  65. /**
  66. * 页面相关事件处理函数--监听用户下拉动作
  67. */
  68. onPullDownRefresh: function () {
  69. },
  70. /**
  71. * 页面上拉触底事件的处理函数
  72. */
  73. onReachBottom: function () {
  74. },
  75. /**
  76. * 用户点击右上角分享
  77. */
  78. onShareAppMessage: function () {
  79. if (app.sharePageDefaultCtl) {
  80. return app.sharePageDefaultCtl()
  81. }
  82. },
  83. /**
  84. * 底部导航跳转
  85. */
  86. redirectCtl: app.redirectCtl,
  87. /**
  88. * 路由跳转
  89. */
  90. navigateCtl: app.navigateCtl,
  91. /**
  92. * 点击排行榜
  93. */
  94. clickOther:function(e){
  95. const { bindex,url } = e.currentTarget.dataset;
  96. var that = this;
  97. const { level, ageGroup, userInfo } = that.data;
  98. if (userInfo) {
  99. console.log(bindex)
  100. // if(bindex==0){
  101. // that.navigateCtl({ url: url, method: {} }, true)
  102. // }else if(bindex==1){
  103. that.navigateCtl({ url: url, method: {} }, true)
  104. // }
  105. } else {
  106. wx.showToast({
  107. title: '请授权登录后再试',
  108. icon: 'none'
  109. })
  110. }
  111. },
  112. /**
  113. * 微信授权
  114. */
  115. bindGetUserInfo: function (e) {
  116. const { code } = this.data;
  117. if (e.detail.userInfo) {
  118. app.saveUserInfo(e.detail, code)
  119. } else {
  120. wx.showToast({
  121. title: '微信授权失败',
  122. icon: 'none'
  123. })
  124. }
  125. },
  126. /**
  127. * 获取个人信息
  128. */
  129. getPersonInfo:function(){
  130. const postData = { fn: this.getPersonInfo, param: { ...arguments } }
  131. var that = this;
  132. const { userInfo } = this.data;
  133. app.post('/api/game/v2/homepageInfo', {}, 0, postData).then(res => {
  134. const { photo, name, level, ageGroup}=res.data;
  135. if (userInfo){
  136. that.setData({ photo, name, level, ageGroup });
  137. }else{
  138. that.setData({ level, ageGroup });
  139. }
  140. })
  141. },
  142. /**
  143. * 点击测一测
  144. */
  145. clickTest:function(){
  146. const { level, ageGroup} = this.data;
  147. this.redirectCtl({ url: 'set_info', method: {} }, true)
  148. // if (ageGroup ==-1){
  149. // this.redirectCtl({ url: 'set_info', method: { level:0, ageGroup } }, true)
  150. // } else{
  151. // this.redirectCtl({ url: 'tu_xing_tui_li', method: { level:0, ageGroup } }, true)
  152. // }
  153. },
  154. /**
  155. * 重新开始
  156. */
  157. getReset: function () {
  158. const { level, ageGroup} = this.data;
  159. const postData = { fn: this.getPersonInfo, param: { ...arguments } }
  160. var that = this;
  161. app.post('/api/game/v2/reset', {}, 0, postData).then(res => {
  162. that.navigateCtl({ url: 'info', method: { level: 1, ageGroup } }, true)
  163. that.setData({ hiddenModel:false})
  164. // wx.showToast({
  165. // title: '重置成功',
  166. // icon: 'none'
  167. // })
  168. })
  169. },
  170. /**
  171. * 接着测试
  172. */
  173. geonTest: function () {
  174. const { level, ageGroup } = this.data;
  175. this.setData({ hiddenModel: false })
  176. if (level==1){
  177. this.navigateCtl({ url: 'tu_xing_tui_li', method: { level: 2, ageGroup } }, true)
  178. } else if (level == 2){
  179. this.navigateCtl({ url: 'tu_xing_tui_li', method: { level: 3, ageGroup } }, true)
  180. }
  181. },
  182. /**
  183. * 提示框隐藏
  184. */
  185. allShowModel: function () {
  186. this.setData({ hiddenModel: false })
  187. },
  188. })