index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. const util = require("../../../utils/util")
  2. const app = getApp()
  3. Page({
  4. data: {
  5. spinShow: false,
  6. userInfo:{},
  7. },
  8. onShow: function(){
  9. app.checkLogin( userInfo =>{
  10. this.setData({userInfo})
  11. })
  12. },
  13. wxLogin( ){
  14. let that = this
  15. wx.login({
  16. success(wxres) {
  17. if( !wxres.code){
  18. util.showMsg("登入失败")
  19. }else{
  20. that.doLoginByCode( wxres.code )
  21. }
  22. }
  23. })
  24. },
  25. getPhoneNumber (e) {
  26. if( e.detail.errMsg !="getPhoneNumber:ok"){
  27. util.showMsg("获取手机失败")
  28. return
  29. }
  30. let {iv, encryptedData} = e.detail;
  31. let that = this
  32. wx.login({
  33. success(wxres) {
  34. that.doGetPhoneNumber( wxres.code, iv, encryptedData )
  35. }
  36. })
  37. },
  38. doLoginByCode( code ){
  39. app.formPost( "Auth.WxLoginByCode", {code}).then( (res)=>{
  40. if( res.code == 200){
  41. this.setData( {userInfo: res.data})
  42. app.setUserInfo( res.data )
  43. }
  44. })
  45. },
  46. doGetPhoneNumber( code, iv, encryptedData ){
  47. let param = {code, iv, encryptedData }
  48. app.formPost( "Auth.WxLoginByPhone", param).then( (res)=>{
  49. if( res.code == 200){
  50. this.setData( {userInfo: res.data})
  51. app.setUserInfo( res.data )
  52. }
  53. })
  54. },
  55. logOut() {
  56. wx.setStorageSync('@openid', '')
  57. wx.setStorageSync('@user', '')
  58. let userInfo = {}
  59. this.setData({userInfo})
  60. app.setUserInfo( userInfo )
  61. },
  62. gotoIdentify(){
  63. wx.navigateTo({
  64. url: '/pages/user/identify/index',
  65. })
  66. }
  67. })