123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import BaseStore from '@src/stores/base';
- export default class UserStore extends BaseStore {
- initState() {
-
-
-
-
- return { login: false };
- }
- infoHandle(result) {
- this.setToken(result.token);
- this.setState({ login: true, needLogin: false, info: result, username: result.username });
- }
- originInviteCode(inviteCode) {
- this.setState({
- inviteCode,
- });
- }
-
- refreshToken() {
- return this.apiPost('/auth/token')
- .then(result => {
- this.infoHandle(result);
- })
- .catch(() => {
- this.logout(false);
- });
- }
-
- login(area, mobile, mobileVerifyCode, inviteCode, email) {
- if (!inviteCode) {
- ({ inviteCode } = this.state);
- }
- return this.apiPost('/auth/login', { area, mobile, mobileVerifyCode, inviteCode, email }).then(result => {
- this.infoHandle(result);
- return result;
- });
- }
- loginWechat(code) {
- return this.apiGet('/auth/wechat', { code }).then((result) => {
- this.infoHandle(result);
- return result;
- });
- }
-
- logout() {
- return this.apiPost('/auth/logout');
- }
-
- bind(area, mobile, mobileVerifyCode, inviteCode, email) {
- if (!inviteCode) {
- ({ inviteCode } = this.state);
- }
- return this.apiPost('/auth/bind', { area, mobile, mobileVerifyCode, inviteCode, email });
- }
-
- validInviteCode(code) {
- return this.apiGet('/auth/valid/invite_code', { code });
- }
-
- validMobile(area, mobile) {
- return this.apiGet('/auth/valid/mobile', { area, mobile });
- }
-
- validWechat(area, mobile) {
- return this.apiGet('/auth/valid/wechat', { area, mobile });
- }
- }
- export const User = new UserStore({ key: 'user', local: true });
|