修改资金密码

This commit is contained in:
saplf
2019-09-06 14:57:20 +08:00
parent f8598d34f7
commit 0cbfc2bf54
9 changed files with 248 additions and 6 deletions

View File

@@ -4,7 +4,7 @@
* - ./src/pages/routes
*/
import React from 'react';
import { connect, DispatchProp } from 'dva';
import { connect, DispatchProp, routerRedux } from 'dva';
import { formatMessage } from 'umi-plugin-locale';
import { Button, Modal, Input } from 'antd';
import Header from '@/components/Header';
@@ -76,12 +76,12 @@ const AccountPage: React.FC<DispatchProp & UserModelState & AccountModelState> =
/>
<AccountItem
className="group"
title="account.email"
message={user.email}
title="account.loginPwd"
/>
<AccountItem
className="group"
title="account.loginPwd"
title="account.fundPwd"
onClick={() => dispatch(routerRedux.push('/fundpwd'))}
/>
<Button
className={styles.logout}

View File

@@ -0,0 +1,92 @@
/**
* Title: 邀请新人
* Routes:
* - ./src/pages/routes
*/
import React, { useEffect, useState } from 'react';
import { connect, DispatchProp } from 'dva';
import { Spin, Button, message, Input } from 'antd';
import { formatMessage } from 'umi-plugin-locale';
import { FundpwdModelState } from './model';
import Header from '@/components/Header';
import styles from './style.less';
import { UserModelState } from '@/models/user';
import { PageState } from '@/types/common';
const FundpwdPage: React.FC<DispatchProp & FundpwdModelState & UserModelState> = ({
dispatch,
pageState,
origin,
originVisible,
newPwd,
confirm,
submitting,
}) => {
useEffect(() => {
dispatch({ type: 'fundpwd/load' });
}, []);
let body;
if (pageState === PageState.Pending) {
body = (
<Spin className={styles.none} />
);
} else if (pageState === PageState.Failure) {
body = (
<div className={styles.none}>{formatMessage({ id: 'common.loadError' })}</div>
);
} else if (pageState === PageState.Success) {
body = (
<>
{originVisible && <Input
className={styles.input}
value={origin}
onChange={e => dispatch({ type: 'fundpwd/onUpdateState', origin: e.target.value })}
placeholder={formatMessage({ id: 'fundpwd.origin' })}
type="password"
size="large"
/>}
<Input
className={styles.input}
value={newPwd}
onChange={e => dispatch({ type: 'fundpwd/onUpdateState', newPwd: e.target.value })}
placeholder={formatMessage({ id: 'fundpwd.new' })}
type="password"
size="large"
/>
<Input
className={styles.input}
value={confirm}
onChange={e => dispatch({ type: 'fundpwd/onUpdateState', confirm: e.target.value })}
placeholder={formatMessage({ id: 'fundpwd.confirm' })}
type="password"
size="large"
/>
<Button
className={styles.input}
type="primary"
size="large"
loading={submitting}
onClick={() => dispatch({ type: 'fundpwd/submit' })}
>{formatMessage({ id: 'fundpwd.btn' })}</Button>
</>
);
}
return (
<div className={styles.container}>
<Header
className="header"
title={formatMessage({ id: 'fundpwd.title' })}
/>
<div className={styles.body}>
{body}
</div>
</div>
);
};
export default connect(
({ fundpwd }: any) => ({ ...fundpwd }),
)(FundpwdPage);

View File

@@ -0,0 +1,92 @@
import { Model, routerRedux } from "dva";
import _ from 'lodash';
import { PageState } from '@/types/common';
import { checkFundPwd } from '@/services/common';
import { message } from 'antd';
import { formatMessage } from 'umi-plugin-locale';
import { validPwd } from '@/utils/validate';
import { changeFundPwd } from './service';
export interface FundpwdModelState {
pageState: PageState;
originVisible: boolean;
origin: string;
newPwd: string;
confirm: string;
submitting: boolean;
}
const initState: FundpwdModelState = {
pageState: PageState.Pending,
originVisible: false,
origin: '',
newPwd: '',
confirm: '',
submitting: false,
};
const model: Model = {
namespace: 'fundpwd',
state: initState,
effects: {
*load(_, { put, call }) {
yield put({ type: 'onUpdateState', pageState: PageState.Pending });
try {
const settled = yield call(checkFundPwd);
yield put({
type: 'onUpdateState',
pageState: PageState.Success,
originVisible: settled,
origin: '',
newPwd: '',
confirm: '',
submitting: false,
});
} catch (e) {
yield put({
type: 'onUpdateState',
pageState: PageState.Failure,
});
}
},
*submit(_, { put, call, select }) {
const {
originVisible,
origin,
newPwd,
confirm,
submitting,
} = (yield select((state: any) => state.fundpwd)) as FundpwdModelState;
if (submitting) return;
if (originVisible && !origin) return message.warn(formatMessage({ id: 'fundpwd.originPrompt' }));
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(changeFundPwd, newPwd, origin);
yield put(routerRedux.goBack());
message.success(formatMessage({ id: 'fundpwd.success' }));
} catch (e) {
message.error(e.message);
} finally {
yield put({ type: 'onUpdateState', submitting: false })
}
},
},
reducers: {
onUpdateState(state, payload) {
return {
...state,
...payload,
};
},
},
};
export default model;

View File

@@ -0,0 +1,10 @@
import http from '@/utils/http';
export async function changeFundPwd(newPassword: string, password?: string) {
const { ok, msg } = await http.post('/user/chFundPwd', {
password,
newPassword,
});
if (ok) return;
throw Error(msg);
}

View File

@@ -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;
}

View File

@@ -4,6 +4,7 @@ import { Journal, FundBasic } from '@/types/common';
import { getFundList } from './service';
import { checkFundPwd, getFundBasic } from '@/services/common';
import { formatMessage } from 'umi-plugin-locale';
import { dispatch } from '@/utils/utils';
export interface HomeFundModelState {
refreshingList: boolean;
@@ -118,7 +119,7 @@ const FundModel: Model = {
cancelText: formatMessage({ id: 'common.cancel' }),
title: formatMessage({ id: 'common.prompt' }),
content: formatMessage({ id: 'home.fund.prompt' }),
onOk: () => { message.warn('暂未完成,请再次点击'); },
onOk: () => dispatch(routerRedux.push('/fundpwd')),
});
}
} catch (e) {

View File

@@ -18,7 +18,8 @@
.body {
flex-grow: 1;
overflow: auto;
overflow-x: hidden;
overflow-y: auto;
}
.none {