user.js 1.5 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 { token } = querystring.parse(window.location.search.replace('?', ''));
  6. this.setToken(token);
  7. return { login: !!token };
  8. }
  9. /**
  10. * 验证token
  11. */
  12. token() {
  13. return this.apiPost('/auth/token');
  14. }
  15. /**
  16. * 登陆
  17. * @param {*} mobile 手机号
  18. * @param {*} mobileVerifyCode 手机验证码
  19. * @param {*} inviteCode 邀请人手机/邀请码
  20. */
  21. login(mobile, mobileVerifyCode, inviteCode) {
  22. return this.apiPost('/auth/login', { mobile, mobileVerifyCode, inviteCode });
  23. }
  24. loginWechat(code) {
  25. return this.apiGet('/auth/wechat', { code });
  26. }
  27. loginWechatPC(code) {
  28. return this.apiGet('/auth/wechat_pc', { code });
  29. }
  30. /**
  31. * 登出
  32. */
  33. logout() {
  34. return this.apiPost('/auth/logout');
  35. }
  36. /**
  37. * 绑定手机
  38. * @param {*} mobile 手机号
  39. * @param {*} mobileVerifyCode 手机验证码
  40. * @param {*} inviteCode 邀请人手机/邀请码
  41. */
  42. bind(mobile, mobileVerifyCode, inviteCode) {
  43. return this.apiPost('/auth/bind', { mobile, mobileVerifyCode, inviteCode });
  44. }
  45. /**
  46. * 查询邀请码对应账号
  47. * @param {*} code 邀请码
  48. */
  49. validInviteCode(code) {
  50. return this.apiGet('/auth/valid/invite_code', { code });
  51. }
  52. /**
  53. * 查询手机对应账号
  54. */
  55. validMobile(mobile) {
  56. return this.apiGet('/auth/valid/mobile', { mobile });
  57. }
  58. }
  59. export const User = new UserStore({ key: 'user', local: true });