1
0

user.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. originInviteCode(inviteCode) {
  12. this.setState({
  13. inviteCode,
  14. });
  15. }
  16. /**
  17. * 验证token
  18. */
  19. token() {
  20. return this.apiPost('/auth/token');
  21. }
  22. /**
  23. * 登陆
  24. * @param {*} area 区域码
  25. * @param {*} mobile 手机号
  26. * @param {*} mobileVerifyCode 手机验证码
  27. * @param {*} inviteCode 邀请人手机/邀请码
  28. */
  29. login(area, mobile, mobileVerifyCode, inviteCode) {
  30. if (!inviteCode) {
  31. ({ inviteCode } = this.state);
  32. }
  33. return this.apiPost('/auth/login', { area, mobile, mobileVerifyCode, inviteCode });
  34. }
  35. loginWechat(code) {
  36. return this.apiGet('/auth/wechat', { code }).then((info) => {
  37. this.setState({ login: true, info });
  38. return info;
  39. });
  40. }
  41. /**
  42. * 登出
  43. */
  44. logout() {
  45. return this.apiPost('/auth/logout');
  46. }
  47. /**
  48. * 绑定手机
  49. * @param {*} area 区域码
  50. * @param {*} mobile 手机号
  51. * @param {*} mobileVerifyCode 手机验证码
  52. * @param {*} inviteCode 邀请人手机/邀请码
  53. */
  54. bind(area, mobile, mobileVerifyCode, inviteCode) {
  55. if (!inviteCode) {
  56. ({ inviteCode } = this.state);
  57. }
  58. return this.apiPost('/auth/bind', { area, mobile, mobileVerifyCode, inviteCode });
  59. }
  60. /**
  61. * 查询邀请码对应账号
  62. * @param {*} code 邀请码
  63. */
  64. validInviteCode(code) {
  65. return this.apiGet('/auth/valid/invite_code', { code });
  66. }
  67. /**
  68. * 查询手机对应账号
  69. */
  70. validMobile(area, mobile) {
  71. return this.apiGet('/auth/valid/mobile', { area, mobile });
  72. }
  73. /**
  74. * 查询手机是否绑定微信
  75. */
  76. validWechat(area, mobile) {
  77. return this.apiGet('/auth/valid/wechat', { area, mobile });
  78. }
  79. }
  80. export const User = new UserStore({ key: 'user', local: true });