碧桂园
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

207 linhas
4.8 KiB

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