diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 8bf61a8..a4d4936 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -132,6 +132,14 @@ export default { 'fundpwd.originPrompt': '请输入原始资金密码', 'fundpwd.success': '资金密码修改成功', + 'lgpwd.title': '修改登录密码', + 'lgpwd.origin': '验证原登录密码', + 'lgpwd.new': '设置新的登录密码', + 'lgpwd.confirm': '确认新的登录密码', + 'lgpwd.btn': '设置', + 'lgpwd.originPrompt': '请输入原始登录密码', + 'lgpwd.success': '登录密码修改成功', + 'profile.account': 'Account Settings', 'profile.system': 'System Settings', 'profile.identity': '实名认证', diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 876679f..4e14195 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -132,6 +132,14 @@ export default { 'fundpwd.originPrompt': '请输入原始资金密码', 'fundpwd.success': '资金密码修改成功', + 'lgpwd.title': '修改登录密码', + 'lgpwd.origin': '验证原登录密码', + 'lgpwd.new': '设置新的登录密码', + 'lgpwd.confirm': '确认新的登录密码', + 'lgpwd.btn': '设置', + 'lgpwd.originPrompt': '请输入原始登录密码', + 'lgpwd.success': '登录密码修改成功', + 'profile.account': '账户管理', 'profile.system': '系统设置', 'profile.identity': '实名认证', diff --git a/src/pages/account/index.tsx b/src/pages/account/index.tsx index 90e86c6..0e188ae 100644 --- a/src/pages/account/index.tsx +++ b/src/pages/account/index.tsx @@ -77,6 +77,7 @@ const AccountPage: React.FC = dispatch(routerRedux.push('/lgpwd'))} /> = ({ + dispatch, + origin, + newPwd, + confirm, + submitting, +}) => { + useEffect(() => { + dispatch({ type: 'lgpwd/load' }); + }, []); + let body = ( + <> + dispatch({ type: 'lgpwd/onUpdateState', origin: e.target.value })} + placeholder={formatMessage({ id: 'lgpwd.origin' })} + type="password" + size="large" + /> + dispatch({ type: 'lgpwd/onUpdateState', newPwd: e.target.value })} + placeholder={formatMessage({ id: 'lgpwd.new' })} + type="password" + size="large" + /> + dispatch({ type: 'lgpwd/onUpdateState', confirm: e.target.value })} + placeholder={formatMessage({ id: 'lgpwd.confirm' })} + type="password" + size="large" + /> + + + ); + + return ( +
+
+ +
+ {body} +
+
+ ); +}; + +export default connect( + ({ lgpwd }: any) => ({ ...lgpwd }), +)(LgpwdPage); diff --git a/src/pages/lgpwd/model.ts b/src/pages/lgpwd/model.ts new file mode 100644 index 0000000..0bbb4bb --- /dev/null +++ b/src/pages/lgpwd/model.ts @@ -0,0 +1,72 @@ +import { Model, routerRedux } from "dva"; +import _ from 'lodash'; +import { PageState } from '@/types/common'; +import { message } from 'antd'; +import { formatMessage } from 'umi-plugin-locale'; +import { validPwd } from '@/utils/validate'; +import { changeLgpwd } from './service'; + +export interface LgpwdModelState { + origin: string; + newPwd: string; + confirm: string; + submitting: boolean; +} + +const initState: LgpwdModelState = { + origin: '', + newPwd: '', + confirm: '', + submitting: false, +}; + +const model: Model = { + namespace: 'lgpwd', + + state: initState, + + effects: { + *load(_, { put, call }) { + yield put({ + type: 'onUpdateState', + origin: '', + newPwd: '', + confirm: '', + submitting: false, + }); + }, + + *submit(_, { put, call, select }) { + const { + origin, + newPwd, + confirm, + submitting, + } = (yield select((state: any) => state.lgpwd)) as LgpwdModelState; + if (submitting) return; + if (!validPwd(newPwd)) return message.warn(formatMessage({ id: 'check.msgPwd' })); + if (confirm !== newPwd) return message.warn(formatMessage({ id: 'check.msgConfirm' })); + yield put({ type: 'onUpdateState', submitting: true }); + try { + yield call(changeLgpwd, newPwd, origin); + yield put(routerRedux.goBack()); + message.success(formatMessage({ id: 'lgpwd.success' })); + } catch (e) { + message.error(e.message); + } finally { + yield put({ type: 'onUpdateState', submitting: false }) + } + }, + }, + + reducers: { + onUpdateState(state, payload) { + return { + ...state, + ...payload, + }; + }, + }, +}; + +export default model; diff --git a/src/pages/lgpwd/service.ts b/src/pages/lgpwd/service.ts new file mode 100644 index 0000000..b2f8a37 --- /dev/null +++ b/src/pages/lgpwd/service.ts @@ -0,0 +1,10 @@ +import http from '@/utils/http'; + +export async function changeLgpwd(newPassword: string, password?: string) { + const { ok, msg } = await http.post('/user/chpasswd', { + password, + newPassword, + }); + if (ok) return; + throw Error(msg); +} diff --git a/src/pages/lgpwd/style.less b/src/pages/lgpwd/style.less new file mode 100644 index 0000000..219bd25 --- /dev/null +++ b/src/pages/lgpwd/style.less @@ -0,0 +1,30 @@ + +@import '../../global.less'; + +.container { + height: 100%; + background: white; + position: relative; + display: flex; + flex-direction: column; +} + +.body { + flex-grow: 1; + overflow-x: hidden; + overflow-y: auto; + display: flex; + flex-direction: column; + align-items: stretch; +} + +.none { + text-align: center; + width: 100%; + padding-top: 40%; +} + +.input { + margin: 10px 20px; + width: auto; +}