This commit is contained in:
saplf
2019-09-08 01:24:27 +08:00
parent 1c0e5ddb66
commit 8282bb81d4
11 changed files with 82 additions and 33 deletions

View File

@@ -32,23 +32,25 @@ export interface CheckModelState {
codeTimer: number;
}
const initState: CheckModelState = {
pageState: PageState.Pending,
pageStep: PageStep.Check,
areacodes: [],
areacode: undefined,
phone: '',
password: '',
pwdConfirm: '',
inviter: '',
verifyCode: '',
submitting: false,
sendingCode: false,
codeTimer: -1,
};
const model: Model = {
namespace: 'check',
state: {
pageState: PageState.Pending,
pageStep: PageStep.Check,
areacodes: [],
areacode: undefined,
phone: '',
password: '',
pwdConfirm: '',
inviter: '',
verifyCode: '',
submitting: false,
sendingCode: false,
codeTimer: -1,
} as CheckModelState,
state: initState,
effects: {
*back(_, { select, put }) {
@@ -123,7 +125,7 @@ const model: Model = {
}
},
*submitLogin(_, { put, call, select }) {
*submitLogin(_, { put, call, select, all }) {
const { areacode, phone, password } = yield select((state: any) => state.check);
if (!areacode) return message.warn(formatMessage({ id: 'check.msgArea' }));
if (!validPhone(phone)) return message.warn(formatMessage({ id: 'check.msgPhone' }));
@@ -135,16 +137,20 @@ const model: Model = {
yield put({ type: 'user/updateToken', payload: token });
yield delay(10);
const user = yield call(getUserInfo, true);
yield put({ type: 'user/updateUser', payload: user });
yield all([
put({ type: 'user/updateUser', payload: user }),
put({ type: 'onUpdateState', ...initState }),
]);
} catch(e) {
message.error(e.message);
yield put({ type: 'user/logout' });
} finally {
yield put({ type: 'onUpdateState', submitting: false });
yield all([
put({ type: 'user/logout' }),
put({ type: 'onUpdateState', submitting: false }),
]);
}
},
*submitRegister(_, { put, select, call }) {
*submitRegister(_, { put, select, call, all }) {
const { areacode, phone, password, verifyCode, inviter, pwdConfirm } = yield select((state: any) => state.check);
if (!areacode) return message.warn(formatMessage({ id: 'check.msgArea' }));
if (!validPhone(phone)) return message.warn(formatMessage({ id: 'check.msgPhone' }));
@@ -159,12 +165,16 @@ const model: Model = {
yield put({ type: 'user/updateToken', payload: token });
yield delay(10);
const user = yield call(getUserInfo, true);
yield put({ type: 'user/updateUser', payload: user });
yield all([
put({ type: 'user/updateUser', payload: user }),
put({ type: 'onUpdateState', ...initState }),
]);
} catch(e) {
message.error(e.message);
yield put({ type: 'user/logout' });
} finally {
yield put({ type: 'onUpdateState', submitting: false });
yield all([
put({ type: 'user/logout' }),
put({ type: 'onUpdateState', submitting: false }),
]);
}
},