This commit is contained in:
saplf
2019-09-06 16:37:43 +08:00
parent 61810d9db4
commit 3c2edc1967
4 changed files with 35 additions and 10 deletions

View File

@@ -22,6 +22,8 @@ export default {
'common.copied': '复制成功', 'common.copied': '复制成功',
'common.prompt': 'Prompt', 'common.prompt': 'Prompt',
'common.iknow': 'I know', 'common.iknow': 'I know',
'common.404': '资源不存在',
'common.403': '登录过期,请重新登录',
'check.login': 'Sign In', 'check.login': 'Sign In',
'check.register': 'Sign Up', 'check.register': 'Sign Up',

View File

@@ -22,6 +22,8 @@ export default {
'common.copied': '复制成功', 'common.copied': '复制成功',
'common.prompt': '提示', 'common.prompt': '提示',
'common.iknow': '我知道了', 'common.iknow': '我知道了',
'common.404': '资源不存在',
'common.403': '登录过期,请重新登录',
'check.login': '登录', 'check.login': '登录',
'check.register': '注册', 'check.register': '注册',

View File

@@ -64,11 +64,22 @@ const model: Model = {
pageStep = PageStep.Login; pageStep = PageStep.Login;
break; break;
} }
yield put({ type: 'onUpdateState', pageStep }); yield put({
type: 'onUpdateState',
pageStep,
password: '',
pwdConfirm: '',
verifyCode: '',
});
}, },
*load(_, { call, put, all }) { *load(_, { call, put, all, select }) {
yield put({ type: 'onUpdatePageState', payload: PageState.Pending }); const { location } = yield select((state: any) => state.router);
let inviter = '';
if (location.query && location.query.inviteCode) {
inviter = location.query.inviteCode;
}
yield put({ type: 'onUpdateState', pageState: PageState.Pending, inviter });
try { try {
const areacodes = yield call(getAreaCodes); const areacodes = yield call(getAreaCodes);

View File

@@ -14,9 +14,13 @@ export interface AppResp<T = any> {
const successLabel = 'color:white;background-color:green;padding: 1px 2px'; const successLabel = 'color:white;background-color:green;padding: 1px 2px';
const failureLabel = 'color:white;background-color:red;padding: 1px 2px'; const failureLabel = 'color:white;background-color:red;padding: 1px 2px';
const originLabel = 'color:unset;background-color:unset;padding:unset'; const originLabel = 'color:unset;background-color:unset;padding:unset';
const errorMap = {
404: 'common.404',
403: 'common.403',
};
// const baseURL = 'https://server.fiv.tacever.org/v1'; const baseURL = 'https://server.fiv.tacever.org/v1';
const baseURL = '//yapi.faronear.org/mock/20/v1'; // const baseURL = '//yapi.faronear.org/mock/20/v1';
const instance = axios.create({ const instance = axios.create({
baseURL, baseURL,
}); });
@@ -55,9 +59,6 @@ async function filter<T>(
} }
const { status, data } = await (instance[method] as (...args: any[]) => Promise<AxiosResponse<AppResp>>)(...args); const { status, data } = await (instance[method] as (...args: any[]) => Promise<AxiosResponse<AppResp>>)(...args);
replaceId(data); replaceId(data);
if (data && data.code === 401) {
dispatch({ type: 'user/logout' });
}
ret = { ret = {
ok: status >= 200 && status < 300 && data && data.code === 0, ok: status >= 200 && status < 300 && data && data.code === 0,
code: data && data.code, code: data && data.code,
@@ -65,10 +66,19 @@ async function filter<T>(
data: data && data.data, data: data && data.data,
}; };
} catch (e) { } catch (e) {
let code = 404;
let msg = 'network.error';
if (e.response) {
code = e.response.status;
msg = (errorMap as any)[code] || 'network.error';
if (code === 403 || code === 401) {
dispatch({ type: 'user/logout' });
}
}
ret = { ret = {
ok: false, ok: false,
msg: formatMessage({ id: 'network.error' }), msg: formatMessage({ id: msg }),
code: 404, code,
}; };
} }
if (isDev) { if (isDev) {