wenlele
10 months ago
13 changed files with 303 additions and 376 deletions
@ -1,62 +1,64 @@ |
|||
'use strict'; |
|||
|
|||
import { message } from 'antd'; |
|||
import { ApiTable } from '$utils' |
|||
import { Request } from '@peace/utils' |
|||
|
|||
export const INIT_AUTH = 'INIT_AUTH'; |
|||
export function initAuth () { |
|||
const user = JSON.parse(sessionStorage.getItem('user')) || {}; |
|||
return { |
|||
type: INIT_AUTH, |
|||
payload: { |
|||
user: user |
|||
} |
|||
}; |
|||
const user = JSON.parse(sessionStorage.getItem('user')) || {}; |
|||
return { |
|||
type: INIT_AUTH, |
|||
payload: { |
|||
user: user |
|||
} |
|||
}; |
|||
} |
|||
|
|||
export const REQUEST_LOGIN = 'REQUEST_LOGIN'; |
|||
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; |
|||
export const LOGIN_ERROR = 'LOGIN_ERROR'; |
|||
export function login ({ username, password, phone, code }) { |
|||
return dispatch => { |
|||
dispatch({ type: REQUEST_LOGIN }); |
|||
export function login ({ username, password, phone, code, p }) { |
|||
return dispatch => { |
|||
dispatch({ type: REQUEST_LOGIN }); |
|||
|
|||
return Request.post(ApiTable.login, { username, password, phone, code }) |
|||
.then(user => { |
|||
sessionStorage.setItem('user', JSON.stringify(user)); |
|||
dispatch({ |
|||
type: LOGIN_SUCCESS, |
|||
payload: { user: user }, |
|||
}); |
|||
}, error => { |
|||
let { body } = error.response; |
|||
dispatch({ |
|||
type: LOGIN_ERROR, |
|||
payload: { |
|||
error: body && body.message ? body.message : '登录失败' |
|||
} |
|||
}) |
|||
return Request.post(ApiTable.login, { username, password, phone, code, p }) |
|||
.then(user => { |
|||
sessionStorage.setItem('user', JSON.stringify(user)); |
|||
dispatch({ |
|||
type: LOGIN_SUCCESS, |
|||
payload: { user: user }, |
|||
}); |
|||
} |
|||
}, error => { |
|||
let { body } = error.response; |
|||
message.error(body && body.message ? body.message : '登录失败'); |
|||
|
|||
dispatch({ |
|||
type: LOGIN_ERROR, |
|||
payload: { |
|||
error: body && body.message ? body.message : '登录失败' |
|||
} |
|||
}) |
|||
}); |
|||
} |
|||
} |
|||
|
|||
export const LOGOUT = 'LOGOUT'; |
|||
export const SCREEN_LOGOUT = 'SCREEN_LOGOUT'; |
|||
export function logout (user) { |
|||
const token = user.token; |
|||
const url = ApiTable.logout; |
|||
sessionStorage.removeItem('user'); |
|||
localStorage.removeItem('zhongding_selected_sider') |
|||
localStorage.removeItem('zhongding_open_sider') |
|||
Request.put(url, { |
|||
token: token |
|||
}); |
|||
return { |
|||
type: LOGOUT |
|||
}; |
|||
const token = user.token; |
|||
const url = ApiTable.logout; |
|||
sessionStorage.removeItem('user'); |
|||
localStorage.removeItem('xunjian_selected_sider') |
|||
localStorage.removeItem('xunjian_open_sider') |
|||
Request.put(url, { |
|||
token: token |
|||
}); |
|||
return { |
|||
type: SCREEN_LOGOUT |
|||
}; |
|||
} |
|||
|
|||
export default { |
|||
initAuth, |
|||
login, |
|||
logout |
|||
initAuth, |
|||
login, |
|||
logout |
|||
} |
Loading…
Reference in new issue