index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. this.bindPhone(e)
  29. },
  30. bindPhone(e){
  31. if( e.detail.errMsg =="getPhoneNumber:ok"){
  32. let param = {
  33. "iv": e.detail.iv,
  34. "encryptedData":e.detail.encryptedData,
  35. }
  36. app.formPost( "User.bindphone", param).then( (res)=>{
  37. if( res.code == 200){
  38. this.setData( {userInfo: res.data})
  39. app.setUserInfo( res.data )
  40. }
  41. })
  42. }else{
  43. app.message("绑定失败", 'error')
  44. }
  45. },
  46. logOut() {
  47. wx.setStorageSync('userId', '')
  48. wx.setStorageSync('token', '')
  49. app.reLogin( this.loadUserInfo )
  50. }
  51. })