diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 047d90c..12269ef 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -41,6 +41,7 @@ export default { 'check.setPwd': '设置登录密码', 'check.confirmPwd': '确认登录密码', 'check.invite': '邀请码', + 'check.resetSuccess': '密码已成功重置,请使用新密码登录。', 'home.tabHome': 'Home', 'home.tabEstate': '矿场', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 592bea2..2c39b5c 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -41,6 +41,7 @@ export default { 'check.setPwd': '设置登录密码', 'check.confirmPwd': '确认登录密码', 'check.invite': '邀请码', + 'check.resetSuccess': '密码已成功重置,请使用新密码登录。', 'home.tabHome': '首页', 'home.tabEstate': '矿场', diff --git a/src/pages/check/index.tsx b/src/pages/check/index.tsx index 53afc9e..48cf775 100644 --- a/src/pages/check/index.tsx +++ b/src/pages/check/index.tsx @@ -14,6 +14,7 @@ import styles from './style.less'; import CheckPage from './check'; import LoginPage from './login'; import RegisterPage from './register'; +import ResetPage from './reset'; import { formatMessage } from 'umi-plugin-locale'; const Page: React.FC = ({ @@ -74,7 +75,7 @@ const Page: React.FC = ({ [PageStep.Check]: , [PageStep.Login]: , [PageStep.Register]: , - [PageStep.Reset]: null, + [PageStep.Reset]: , [PageStep.ResetSuccess]: null, }[pageStep]} diff --git a/src/pages/check/login.tsx b/src/pages/check/login.tsx index d2617d8..6ae242d 100644 --- a/src/pages/check/login.tsx +++ b/src/pages/check/login.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Button, Input } from 'antd'; import { connect, DispatchProp } from 'dva'; import { formatMessage } from 'umi-plugin-locale'; -import { CheckModelState } from './model'; +import { CheckModelState, PageStep } from './model'; const LoginPage: React.FC = ({ password, @@ -20,6 +20,14 @@ const LoginPage: React.FC = ({ type="password" /> +
dispatch({ type: 'check/onUpdateState', pageStep: PageStep.Reset })} + > + {formatMessage({ id: 'check.forget' })} +
+ diff --git a/src/pages/check/reset.tsx b/src/pages/check/reset.tsx new file mode 100644 index 0000000..7fd1f3a --- /dev/null +++ b/src/pages/check/reset.tsx @@ -0,0 +1,82 @@ +import React from 'react'; +import { Button, Input } from 'antd'; +import { connect, DispatchProp } from 'dva'; +import { formatMessage } from 'umi-plugin-locale'; +import { CheckModelState } from './model'; + +import styles from './style.less'; +import { SendCodeType } from '@/types/common'; + +const ResetPage: React.FC = ({ + password, + inviter, + pwdConfirm, + verifyCode, + submitting, + dispatch, + codeTimer, + sendingCode, +}) => { + let btnText; + if (codeTimer < 0) { + btnText = formatMessage({ id: 'check.getCode1' }); + } else if (codeTimer === 0) { + btnText = formatMessage({ id: 'check.getCode3' }); + } else { + btnText = formatMessage({ id: 'check.getCode2' }, { time: codeTimer }) + } + + return ( +
+ + dispatch({ type: 'check/onUpdateState', verifyCode: e.target.value })} + /> + + + + dispatch({ type: 'check/onUpdatePassword', payload: e.target.value })} + size="large" + type="password" + /> + + dispatch({ type: 'check/onUpdateState', pwdConfirm: e.target.value })} + size="large" + type="password" + /> + + +
+ ); +} + +export default connect( + ({ check } : any) => ({ ...check }) +)(ResetPage) as any; diff --git a/src/pages/check/service.ts b/src/pages/check/service.ts index 35a2f63..4190c73 100644 --- a/src/pages/check/service.ts +++ b/src/pages/check/service.ts @@ -1,5 +1,5 @@ import http from '@/utils/http'; -import { AreaCode } from '@/types/common'; +import { AreaCode, SendCodeType } from '@/types/common'; import { encodePhone } from '@/utils/transform'; export enum CheckResult { @@ -45,12 +45,26 @@ export async function signUp(areacode: AreaCode, phone: string, password: string return data.token; } -export async function sendCode(areacode: AreaCode, phone: string) { +export async function reset(areacode: AreaCode, phone: string, password: string, code: string): Promise { + const { ok, msg, data } = await http.post( + '/sign/forget', + { + phone: encodePhone(areacode, phone), + password, + code, + }, + ); + if (!ok) { + throw Error(msg); + } +} + +export async function sendCode(areacode: AreaCode, phone: string, type: SendCodeType) { const { ok, msg } = await http.post( '/sign/send', { phone: encodePhone(areacode, phone), - type: 'signUp', + type, }, ); if (ok) { diff --git a/src/pages/check/style.less b/src/pages/check/style.less index 45b94a4..f26c788 100644 --- a/src/pages/check/style.less +++ b/src/pages/check/style.less @@ -1,3 +1,4 @@ +@import '../../global.less'; .check { position: relative; @@ -57,7 +58,14 @@ .register { height: 100%; - padding-top: 160px; + padding-top: @header-height; + display: flex; + flex-direction: column; +} + +.reset { + height: 100%; + padding-top: @header-height; display: flex; flex-direction: column; } diff --git a/src/types/common.ts b/src/types/common.ts index a018c6f..3fe8e6a 100644 --- a/src/types/common.ts +++ b/src/types/common.ts @@ -14,6 +14,11 @@ export interface User { inviteCode: string; } +export enum SendCodeType { + SignUp = 'signUp', + ForgetPwd = 'forgetPasswd', +} + export interface AreaCode { id: string; areacode: string; diff --git a/src/utils/http.ts b/src/utils/http.ts index 03c2380..5e04aab 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -2,7 +2,7 @@ import axios, { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios'; import { formatMessage } from 'umi-plugin-locale'; import _ from 'lodash'; import { globalState } from '@/services/common'; -import { isDev } from './utils'; +import { isDev, dispatch } from './utils'; export interface AppResp { ok: boolean, @@ -55,6 +55,9 @@ async function filter( } const { status, data } = await (instance[method] as (...args: any[]) => Promise>)(...args); replaceId(data); + if (data && data.code === 401) { + dispatch({ type: 'user/logout' }); + } ret = { ok: status >= 200 && status < 300 && data && data.code === 0, code: data && data.code,