修改登录密码
This commit is contained in:
72
src/pages/lgpwd/model.ts
Normal file
72
src/pages/lgpwd/model.ts
Normal file
@@ -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;
|
||||
Reference in New Issue
Block a user