碧桂园
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

175 Zeilen
3.9 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.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',
  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: 'https://cktest.2weisou.com/meta/ar/user/bindNickname',
  99. method: "POST",
  100. data: params,
  101. header: {
  102. Authorization: 'bearer '+ that.data.token
  103. },
  104. success(res) {
  105. if (res.statusCode == 200) {
  106. that.setData({
  107. avatarModal: false,
  108. step: 2
  109. })
  110. if(that.data.phoneModal1){
  111. that.setData({
  112. phoneModal: true
  113. })
  114. }
  115. }
  116. }
  117. })
  118. },
  119. getUserInfo(){
  120. let that = this
  121. wx.getUserProfile({
  122. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  123. success: (res) => {
  124. // console.log(res)
  125. that.bindNickname(res.userInfo)
  126. getApp().globalData.userInfo.userWxName = res.userInfo.nickName
  127. console.log(2121212)
  128. console.log(getApp().globalData.userInfo)
  129. }
  130. })
  131. },
  132. // 授权手机号
  133. getPhoneNumber(e) {
  134. console.log(e);
  135. let that = this
  136. if (e.detail.errMsg == "getPhoneNumber:ok") {
  137. const {
  138. iv,
  139. encryptedData
  140. } = e.detail;
  141. wx.request({
  142. url: 'https://cktest.2weisou.com/meta/ar/user/bindMini',
  143. method: "POST",
  144. data: {
  145. encrypted: encryptedData,
  146. iv
  147. },
  148. header: {
  149. Authorization: 'bearer '+ that.data.token
  150. },
  151. success(res) {
  152. console.log(res)
  153. if (res.data.code == 0) {
  154. console.log(res)
  155. that.setData({
  156. phoneModal: false,
  157. showBg: false,
  158. step: 0
  159. })
  160. getApp().globalData.userInfo.phone = res.data.data
  161. console.log(getApp().globalData.userInfo)
  162. that.leave()
  163. }
  164. }
  165. })
  166. } else {
  167. wx.showToast({
  168. icon: "none",
  169. title: "请授权手机号"
  170. })
  171. }
  172. }
  173. })