user.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import BaseStore from '@src/stores/base';
  2. // import * as querystring from 'querystring';
  3. export default class UserStore extends BaseStore {
  4. initState() {
  5. // const { code } = querystring.parse(window.location.search.replace('?', ''));
  6. // if (code) {
  7. // this.loginWechat(code);
  8. // }
  9. return { login: false };
  10. }
  11. /**
  12. * 验证token
  13. */
  14. token() {
  15. return this.apiPost('/auth/token');
  16. }
  17. /**
  18. * 登陆
  19. * @param {*} mobile 手机号
  20. * @param {*} mobileVerifyCode 手机验证码
  21. * @param {*} inviteCode 邀请人手机/邀请码
  22. */
  23. login(mobile, mobileVerifyCode, inviteCode) {
  24. return this.apiPost('/auth/login', { mobile, mobileVerifyCode, inviteCode });
  25. }
  26. loginWechat(code) {
  27. return this.apiGet('/auth/wechat', { code }).then(() => {
  28. this.setState({ login: true });
  29. });
  30. }
  31. /**
  32. * 登出
  33. */
  34. logout() {
  35. return this.apiPost('/auth/logout');
  36. }
  37. /**
  38. * 绑定手机
  39. * @param {*} mobile 手机号
  40. * @param {*} mobileVerifyCode 手机验证码
  41. * @param {*} inviteCode 邀请人手机/邀请码
  42. */
  43. bind(mobile, mobileVerifyCode, inviteCode) {
  44. return this.apiPost('/auth/bind', { mobile, mobileVerifyCode, inviteCode });
  45. }
  46. /**
  47. * 查询邀请码对应账号
  48. * @param {*} code 邀请码
  49. */
  50. validInviteCode(code) {
  51. return this.apiGet('/auth/valid/invite_code', { code });
  52. }
  53. /**
  54. * 查询手机对应账号
  55. */
  56. validMobile(mobile) {
  57. return this.apiGet('/auth/valid/mobile', { mobile });
  58. }
  59. }
  60. export const User = new UserStore({ key: 'user', local: true });