mirror of
https://github.com/zuiidea/antd-admin
synced 2026-10-28 03:04:48 +00:00
loginOut
This commit is contained in:
+10
@@ -28,6 +28,7 @@ Watch.watch(adminUsersData, function () {
|
||||
|
||||
module.exports = {
|
||||
'POST /api/login' (req, res) {
|
||||
console.log(req);
|
||||
const userItem = req.body
|
||||
const response = {
|
||||
success: false,
|
||||
@@ -60,5 +61,14 @@ module.exports = {
|
||||
message: ""
|
||||
}
|
||||
res.json(response)
|
||||
},
|
||||
|
||||
'POST /api/logout' (req, res) {
|
||||
Cookie.remove('user_session', { path: '' })
|
||||
Cookie.remove('user_name', { path: '' })
|
||||
res.json({
|
||||
success: true,
|
||||
message: "退出成功"
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,14 +5,19 @@ import styles from './main.less'
|
||||
|
||||
const SubMenu = Menu.SubMenu
|
||||
|
||||
function Header({location,user}) {
|
||||
function Header({location,user,logout}) {
|
||||
function handleClickMenu(item){
|
||||
if(item.key=='logout'){
|
||||
logout()
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
<Menu className="header-menu" mode="horizontal">
|
||||
<Menu className="header-menu" mode="horizontal" onClick={handleClickMenu}>
|
||||
<SubMenu style={{
|
||||
float: 'right'
|
||||
}} title={< span > <Icon type="user"/>{user.name}< /span>}>
|
||||
<Menu.Item key="signOut">
|
||||
<Menu.Item key="logout">
|
||||
<a>注销</a>
|
||||
</Menu.Item>
|
||||
</SubMenu>
|
||||
|
||||
+30
-15
@@ -1,4 +1,4 @@
|
||||
import {login, userInfo} from '../services/app'
|
||||
import {login, userInfo, logout} from '../services/app'
|
||||
import {parse} from 'qs'
|
||||
import Cookie from 'js-cookie'
|
||||
|
||||
@@ -12,12 +12,9 @@ export default {
|
||||
},
|
||||
loginButtonLoading: false
|
||||
},
|
||||
subscriptions: {
|
||||
subscriptions : {
|
||||
setup({dispatch}) {
|
||||
dispatch({
|
||||
type: 'queryUser',
|
||||
payload: location.query,
|
||||
})
|
||||
dispatch({type: 'queryUser'})
|
||||
}
|
||||
},
|
||||
effects : {
|
||||
@@ -36,23 +33,35 @@ export default {
|
||||
}})
|
||||
}
|
||||
},
|
||||
*queryUser({payload}, {call, put}) {
|
||||
*queryUser({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showLoading'})
|
||||
const data = yield call(userInfo, parse(payload))
|
||||
if (data.success) {
|
||||
console.log(data);
|
||||
yield put({type: 'loginSuccess', payload: {
|
||||
user:{
|
||||
name:data.username
|
||||
yield put({
|
||||
type: 'loginSuccess',
|
||||
payload: {
|
||||
user: {
|
||||
name: data.username
|
||||
}
|
||||
}})
|
||||
}else {
|
||||
|
||||
}
|
||||
})
|
||||
} else {}
|
||||
},
|
||||
*logout({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
const data = yield call(logout, parse(payload))
|
||||
if(data.success){
|
||||
yield put({
|
||||
type: 'logoutSuccess'
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
reducers : {
|
||||
loginSuccess(state,action) {
|
||||
loginSuccess(state, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
@@ -60,6 +69,12 @@ export default {
|
||||
loginButtonLoading: false
|
||||
}
|
||||
},
|
||||
logoutSuccess(state){
|
||||
return {
|
||||
...state,
|
||||
login: false
|
||||
}
|
||||
},
|
||||
loginFail(state) {
|
||||
return {
|
||||
...state,
|
||||
|
||||
+2
-2
@@ -25,9 +25,9 @@ function App({children, location, dispatch,app}) {
|
||||
const headerProps = {
|
||||
user,
|
||||
location,
|
||||
loginOut() {
|
||||
logout() {
|
||||
dispatch({
|
||||
type: 'app/loginOut'
|
||||
type: 'app/logout'
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ export async function login(params) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function loginOut(params) {
|
||||
return request('/api/loginOut', {
|
||||
export async function logout(params) {
|
||||
return request('/api/logout', {
|
||||
method: 'post',
|
||||
data:params,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user