Files
antd-admin/src/models/login.js
T
2017-05-09 15:25:08 +08:00

46 lines
943 B
JavaScript

import { login } from '../services/login'
import { routerRedux } from 'dva/router'
import { queryURL } from '../utils'
export default {
namespace: 'login',
state: {
loginLoading: false,
},
effects: {
*login ({
payload,
}, { put, call }) {
yield put({ type: 'showLoginLoading' })
const data = yield call(login, payload)
yield put({ type: 'hideLoginLoading' })
if (data.success) {
const from = queryURL('from')
yield put({ type: 'app/query' })
if (from) {
yield put(routerRedux.push(from))
} else {
yield put(routerRedux.push('/dashboard'))
}
} else {
throw data
}
},
},
reducers: {
showLoginLoading (state) {
return {
...state,
loginLoading: true,
}
},
hideLoginLoading (state) {
return {
...state,
loginLoading: false,
}
},
},
}