1234567891011121314151617181920212223242526272829303132333435363738 |
- import { routerRedux } from 'dva/router';
- import { message } from 'antd';
- import { login, logout } from '../services/login';
- import { addLocalUser } from '../utils/helper';
- export default {
- namespace: 'login',
- state: {
- loading: false,
- },
- effects: {
- *login({ payload }, { put, call, select }) {
- yield put({ type: 'save', payload: { loading: true } });
- const { data, success } = yield call(login, payload);
- if (success) {
- addLocalUser(data);
- message.success('登录成功')
- yield put(routerRedux.push('/'));
- }
- yield put({ type: 'save', payload: { loading: false } });
- },
- *logout(_, { put, call }) {
- const { success } = yield call(logout);
- if (success) {
- message.success('注销成功,请重新登录!')
- yield put(routerRedux.push('/user/login'));
- }
- }
- },
- reducers: {
- save(state, action) {
- return {
- ...state,
- ...action.payload,
- }
- },
- },
- }
|