index.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const app = getApp()
  2. Page({
  3. data: {
  4. spinShow: false,
  5. userInfo:{},
  6. info: {}
  7. },
  8. onLoad: function(options) {
  9. app.checkLogin( this.loadUserInfo )
  10. },
  11. loadUserInfo( userInfo ) {
  12. this.setData( {userInfo} )
  13. },
  14. userInfoHandler(e){
  15. console.log( e.detail.userInfo )
  16. let param = {
  17. "displayName": e.detail.userInfo.nickName,
  18. "avatarUrl":e.detail.userInfo.avatarUrl,
  19. }
  20. app.formPost('User.updateInfo', param ).then(res => {
  21. if( res.code == 200){
  22. this.setData( {userInfo: res.data})
  23. app.setUserInfo( res.data )
  24. }
  25. })
  26. },
  27. getPhoneNumber (e) {
  28. if( e.detail.errMsg =="getPhoneNumber:ok"){
  29. let param = {
  30. "iv": e.detail.iv,
  31. "encryptedData":e.detail.encryptedData,
  32. }
  33. app.formPost( "User.bindphone", param).then( (res)=>{
  34. if( res.code == 200){
  35. this.setData( {userInfo: res.data})
  36. app.setUserInfo( res.data )
  37. }
  38. })
  39. }else{
  40. app.message("绑定失败", 'error')
  41. }
  42. },
  43. logOut() {
  44. wx.setStorageSync('userId', '')
  45. wx.setStorageSync('token', '')
  46. app.reLogin( this.loadUserInfo )
  47. }
  48. })