碧桂园
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

229 wiersze
5.4 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. let userInfo = wx.getStorageSync('userInfo')
  60. if(userInfo.phone){
  61. wx.showToast({
  62. icon: 'none',
  63. title: '您已完成授权',
  64. })
  65. }
  66. if(this.data.step==1){
  67. this.setData({
  68. avatarModal: true,
  69. showBg: true
  70. })
  71. }
  72. if(this.data.step==2){
  73. this.setData({
  74. phoneModal: true,
  75. showBg: true
  76. })
  77. }
  78. },
  79. closeModal(){
  80. this.setData({
  81. showBg: false
  82. })
  83. },
  84. leave(){
  85. wx.navigateTo({
  86. url: '/pages/out/index?index=1&userid='+ this.data.userid+'&gameid=1'+'&type=2',
  87. })
  88. },
  89. //登录-获取token
  90. loginGettoken(){
  91. let that = this
  92. wx.login({
  93. success (res) {
  94. if (res.code) {
  95. //发起网络请求
  96. wx.request({
  97. url:'https://cktest.2weisou.com/meta/auth/mobile/token/social?grant_type=mobil&mobile=MINI_C@'+res.code+'@'+'',
  98. method: "POST",
  99. data: {
  100. },
  101. header: {
  102. Authorization: "Basic YXBwbGV0OmFwcGxldA==",
  103. },
  104. success(res1) {
  105. if (res1.statusCode == 200) {
  106. let userInfo = res1.data.user_info
  107. that.setData({
  108. token: res1.data.access_token,
  109. userid: userInfo.id,
  110. userInfo: userInfo
  111. })
  112. wx.setStorageSync('token', res1.data.access_token)
  113. wx.setStorageSync('userInfo', userInfo)
  114. if(!!userInfo.userWxName&&!!userInfo.phone){
  115. that.leave()
  116. return;
  117. }
  118. if(!userInfo.userWxName||!userInfo.phone){
  119. that.setData({
  120. showBg: true
  121. })
  122. }else{
  123. that.setData({
  124. showBg: false
  125. })
  126. }
  127. that.setData({
  128. avatarModal: !!userInfo.userWxName?false:true,
  129. phoneModal1: !!userInfo.phone?false:true,
  130. step: 1
  131. })
  132. if(!that.data.avatarModal){
  133. that.setData({
  134. step: 2,
  135. phoneModal: that.data.phoneModal1
  136. })
  137. }
  138. }
  139. }
  140. })
  141. } else {
  142. console.log('登录失败!' + res.errMsg)
  143. }
  144. }
  145. })
  146. },
  147. // 绑定用户头像信息
  148. bindNickname(obj) {
  149. let that = this
  150. let params = {
  151. id: that.data.userid,
  152. userWxHeadImgUrl: obj.avatarUrl,
  153. userWxName: obj.nickName,
  154. userVxGender: obj.gender
  155. }
  156. wx.request({
  157. url: 'https://cktest.2weisou.com/meta/ar/user/bindNickname',
  158. method: "POST",
  159. data: params,
  160. header: {
  161. Authorization: 'bearer '+ that.data.token
  162. },
  163. success(res) {
  164. if (res.statusCode == 200) {
  165. that.setData({
  166. avatarModal: false,
  167. step: 2
  168. })
  169. if(that.data.phoneModal1){
  170. that.setData({
  171. phoneModal: true
  172. })
  173. }
  174. }
  175. }
  176. })
  177. },
  178. getUserInfo(){
  179. let that = this
  180. wx.getUserProfile({
  181. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  182. success: (res) => {
  183. // console.log(res)
  184. that.bindNickname(res.userInfo)
  185. }
  186. })
  187. },
  188. // 授权手机号
  189. getPhoneNumber(e) {
  190. console.log(e);
  191. let that = this
  192. if (e.detail.errMsg == "getPhoneNumber:ok") {
  193. const {
  194. iv,
  195. encryptedData
  196. } = e.detail;
  197. wx.request({
  198. url: 'https://cktest.2weisou.com/meta/ar/user/bindMini',
  199. method: "POST",
  200. data: {
  201. encrypted: encryptedData,
  202. iv
  203. },
  204. header: {
  205. Authorization: 'bearer '+ that.data.token
  206. },
  207. success(res) {
  208. console.log(res)
  209. if (res.data.code == 0) {
  210. // console.log(res)
  211. that.setData({
  212. phoneModal: false,
  213. showBg: false,
  214. step: 0
  215. })
  216. that.leave()
  217. }
  218. }
  219. })
  220. } else {
  221. wx.showToast({
  222. icon: "none",
  223. title: "请授权手机号"
  224. })
  225. }
  226. }
  227. })