login.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. Page({
  2. data: {},
  3. onLoad: function(e) {
  4. getApp().page.onLoad(this, e)
  5. },
  6. getUserInfo: function(o) {
  7. var n = this;
  8. "getUserInfo:ok" == o.detail.errMsg && getApp().core.login({
  9. success: function(e) {
  10. var t = e.code;
  11. n.unionLogin({
  12. code: t,
  13. user_info: o.detail.rawData,
  14. encrypted_data: o.detail.encryptedData,
  15. iv: o.detail.iv,
  16. signature: o.detail.signature
  17. })
  18. },
  19. fail: function(e) {}
  20. })
  21. },
  22. myLogin: function() {
  23. var t = this;
  24. "my" === getApp().platform && my.getAuthCode({
  25. scopes: "auth_user",
  26. success: function(e) {
  27. t.unionLogin({
  28. code: e.authCode
  29. })
  30. }
  31. })
  32. },
  33. unionLogin: function(e) {
  34. getApp().core.showLoading({
  35. title: "正在登录",
  36. mask: !0
  37. }), getApp().request({
  38. url: getApp().api.passport.login,
  39. method: "POST",
  40. data: e,
  41. success: function(e) {
  42. if (0 == e.code) {
  43. getApp().setUser(e.data), getApp().core.setStorageSync(getApp().const.ACCESS_TOKEN, e.data.access_token),
  44. getApp().trigger.run(getApp().trigger.events.login);
  45. var t = getApp().core.getStorageSync(getApp().const.LOGIN_PRE_PAGE);
  46. t && t.route ? getApp().core.redirectTo({
  47. url: "/" + t.route + "?" + getApp().helper.objectToUrlParams(t.options)
  48. }) : getApp().core.redirectTo({
  49. url: "/pages/index/index"
  50. })
  51. } else getApp().core.showModal({
  52. title: "提示",
  53. content: e.msg,
  54. showCancel: !1
  55. })
  56. },
  57. complete: function() {
  58. getApp().core.hideLoading()
  59. }
  60. })
  61. }
  62. });