碧桂园
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

185 satır
4.1 KiB

  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. let userInfo = getApp().globalData.userInfo
  5. let token = getApp().globalData.token
  6. console.log(userInfo)
  7. Page({
  8. data: {
  9. avatarModal: false,
  10. phoneModal: false,
  11. phoneModal1: false,
  12. showBg: false,
  13. step: 0,// 头像授权1, 手机授权2
  14. nickNamebind: false,
  15. phonebind: false,
  16. userInfo: null,
  17. userid:'',
  18. token: ''
  19. },
  20. onLoad() {
  21. if (userInfo) {
  22. this.setData({
  23. token: token,
  24. userid: userInfo.id,
  25. userInfo: userInfo
  26. })
  27. if(!!userInfo.userWxName&&!!userInfo.phone){
  28. this.leave()
  29. return;
  30. }
  31. if(!userInfo.userWxName||!userInfo.phone){
  32. this.setData({
  33. showBg: true
  34. })
  35. }else{
  36. this.setData({
  37. showBg: false
  38. })
  39. }
  40. this.setData({
  41. avatarModal: !!userInfo.userWxName?false:true,
  42. phoneModal1: !!userInfo.phone?false:true,
  43. step: 1
  44. })
  45. if(!this.data.avatarModal){
  46. this.setData({
  47. step: 2,
  48. phoneModal: this.data.phoneModal1
  49. })
  50. }
  51. }
  52. },
  53. backhome(){
  54. wx.navigateTo({
  55. url: '/pages/index/index'
  56. })
  57. },
  58. shouquan(){
  59. if(userInfo&&userInfo.phone){
  60. wx.showToast({
  61. icon: 'none',
  62. title: '您已完成授权',
  63. })
  64. }
  65. if(this.data.step==1){
  66. this.setData({
  67. avatarModal: true,
  68. showBg: true
  69. })
  70. }
  71. if(this.data.step==2){
  72. this.setData({
  73. phoneModal: true,
  74. showBg: true
  75. })
  76. }
  77. },
  78. closeModal(){
  79. this.setData({
  80. showBg: false
  81. })
  82. },
  83. leave(){
  84. wx.navigateTo({
  85. url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2&url=' + getApp().globalData.gameurl,
  86. })
  87. },
  88. // 绑定用户头像信息
  89. bindNickname(obj) {
  90. let that = this
  91. let params = {
  92. id: that.data.userid,
  93. userWxHeadImgUrl: obj.avatarUrl,
  94. userWxName: obj.nickName,
  95. userVxGender: obj.gender
  96. }
  97. wx.request({
  98. url: getApp().globalData.httpurl +'ar/user/bindNickname',
  99. method: "POST",
  100. data: params,
  101. header: {
  102. Authorization: 'bearer '+ that.data.token
  103. },
  104. success(res) {
  105. console.log(res)
  106. if (res.data.code==0) {
  107. that.setData({
  108. avatarModal: false,
  109. step: 2
  110. })
  111. if(that.data.phoneModal1){
  112. that.setData({
  113. phoneModal: true
  114. })
  115. }
  116. }else{
  117. wx.showToast({
  118. icon: 'none',
  119. title: res.data.msg
  120. })
  121. }
  122. }
  123. })
  124. },
  125. getUserInfo(){
  126. let that = this
  127. wx.getUserProfile({
  128. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  129. success: (res) => {
  130. // console.log(res)
  131. that.bindNickname(res.userInfo)
  132. getApp().globalData.userInfo.userWxName = res.userInfo.nickName
  133. console.log(getApp().globalData.userInfo)
  134. }
  135. })
  136. },
  137. // 授权手机号
  138. getPhoneNumber(e) {
  139. console.log(e);
  140. let that = this
  141. if (e.detail.errMsg == "getPhoneNumber:ok") {
  142. const {
  143. iv,
  144. encryptedData
  145. } = e.detail;
  146. wx.request({
  147. url: getApp().globalData.httpurl + 'ar/user/bindMini',
  148. method: "POST",
  149. data: {
  150. encrypted: encryptedData,
  151. iv
  152. },
  153. header: {
  154. Authorization: 'bearer '+ that.data.token
  155. },
  156. success(res) {
  157. console.log(res)
  158. if (res.data.code == 0) {
  159. console.log(res)
  160. that.setData({
  161. phoneModal: false,
  162. showBg: false,
  163. step: 0
  164. })
  165. getApp().globalData.userInfo.phone = res.data.data
  166. console.log(getApp().globalData.userInfo)
  167. that.leave()
  168. }else{
  169. wx.showToast({
  170. icon: 'none',
  171. title: res.data.msg
  172. })
  173. }
  174. }
  175. })
  176. } else {
  177. wx.showToast({
  178. icon: "none",
  179. title: "请授权手机号"
  180. })
  181. }
  182. }
  183. })