mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-03 00:14:00 +00:00
getUserInfo
This commit is contained in:
+30
-21
@@ -26,30 +26,39 @@ Watch.watch(adminUsersData, function () {
|
||||
localStorage.setItem("antdAdminUsersData", JSON.stringify(adminUsersData))
|
||||
})
|
||||
|
||||
|
||||
module.exports = {
|
||||
'POST /api/login' (req, res) {
|
||||
'POST /api/login' (req, res) {
|
||||
const userItem = req.body
|
||||
const d = adminUsersData.filter(function (item) {
|
||||
return item.username==userItem.username
|
||||
})
|
||||
if(!!d.length){
|
||||
if(d[0].password==userItem.password){
|
||||
|
||||
}else {
|
||||
|
||||
}
|
||||
}else {
|
||||
|
||||
const response = {
|
||||
success: false,
|
||||
message: ""
|
||||
}
|
||||
const now = new Date()
|
||||
now.setDate(now.getDate()+1)
|
||||
Cookie.set('user_session', now.getTime())
|
||||
Cookie.set('user_name', userItem.username)
|
||||
res.json({success: true})
|
||||
const d = adminUsersData.filter(function (item) {
|
||||
return item.username == userItem.username
|
||||
})
|
||||
if (!!d.length) {
|
||||
if (d[0].password == userItem.password) {
|
||||
const now = new Date()
|
||||
now.setDate(now.getDate() + 1)
|
||||
Cookie.set('user_session', now.getTime())
|
||||
Cookie.set('user_name', userItem.username)
|
||||
response.message = "登录成功"
|
||||
response.success = true
|
||||
} else {
|
||||
response.message = "密码不正确"
|
||||
}
|
||||
} else {
|
||||
response.message = "用户不存在"
|
||||
}
|
||||
res.json(response)
|
||||
},
|
||||
|
||||
'GET /api/userInfo' (req, res) {
|
||||
res.json({success: true,username:"吴彦祖"})
|
||||
},
|
||||
'GET /api/userInfo' (req, res) {
|
||||
const response = {
|
||||
success: Cookie.get('user_session')&&Cookie.get('user_session') > new Date().getTime() ? true :false,
|
||||
username: Cookie.get('user_name')||'',
|
||||
message: ""
|
||||
}
|
||||
res.json(response)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,13 @@ import styles from './main.less'
|
||||
|
||||
const SubMenu = Menu.SubMenu
|
||||
|
||||
function Header({location}) {
|
||||
function Header({location,user}) {
|
||||
return (
|
||||
<div className={styles.header}>
|
||||
<Menu className="header-menu" mode="horizontal">
|
||||
<SubMenu style={{
|
||||
float: 'right'
|
||||
}} title={< span > <Icon type="user"/>吴彦祖 < /span>}>
|
||||
}} title={< span > <Icon type="user"/>{user.name}< /span>}>
|
||||
<Menu.Item key="signOut">
|
||||
<a>注销</a>
|
||||
</Menu.Item>
|
||||
|
||||
+40
-13
@@ -5,40 +5,67 @@ import Cookie from 'js-cookie'
|
||||
export default {
|
||||
namespace : 'app',
|
||||
state : {
|
||||
login: Cookie.get('user_session') > new Date().getTime()
|
||||
? true
|
||||
: false,
|
||||
login: false,
|
||||
loading: false,
|
||||
user:{
|
||||
name:"吴彦祖",
|
||||
user: {
|
||||
name: "吴彦祖"
|
||||
},
|
||||
loginButtonLoading: false
|
||||
},
|
||||
subscriptions: {
|
||||
setup({dispatch}) {
|
||||
dispatch({
|
||||
type: 'queryUser',
|
||||
payload: location.query,
|
||||
})
|
||||
}
|
||||
},
|
||||
effects : {
|
||||
*login({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({type: 'showLoginButtonLoading'})
|
||||
const data = yield call(login, parse(payload))
|
||||
if (data) {
|
||||
if (data.success) {
|
||||
yield put({type: 'loginSuccess', payload: {
|
||||
data
|
||||
}})
|
||||
} else {
|
||||
yield put({type: 'loginFail', payload: {
|
||||
data
|
||||
}})
|
||||
}
|
||||
},
|
||||
*userInfo({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
*queryUser({payload}, {call, put}) {
|
||||
yield put({type: 'showLoading'})
|
||||
const data = yield call(login, parse(payload))
|
||||
if (data) {
|
||||
const data = yield call(userInfo, parse(payload))
|
||||
if (data.success) {
|
||||
console.log(data);
|
||||
yield put({type: 'loginSuccess', payload: {
|
||||
user:{
|
||||
name:data.username
|
||||
}
|
||||
}})
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
reducers : {
|
||||
loginSuccess(state) {
|
||||
return {login: true, loading: false, loginButtonLoading: false}
|
||||
loginSuccess(state,action) {
|
||||
return {
|
||||
...state,
|
||||
...action.payload,
|
||||
login: true,
|
||||
loginButtonLoading: false
|
||||
}
|
||||
},
|
||||
loginFail(state) {
|
||||
return {
|
||||
...state,
|
||||
login: false,
|
||||
loginButtonLoading: false
|
||||
}
|
||||
},
|
||||
showLoginButtonLoading(state) {
|
||||
return {
|
||||
|
||||
+6
-5
@@ -10,7 +10,7 @@ import styles from '../components/layout/main.less'
|
||||
import '../components/layout/common.less'
|
||||
|
||||
function App({children, location, dispatch,app}) {
|
||||
const {login, loading,loginButtonLoading,userName} = app
|
||||
const {login, loading,loginButtonLoading,user} = app
|
||||
const loginProps = {
|
||||
loading,
|
||||
loginButtonLoading,
|
||||
@@ -22,8 +22,9 @@ function App({children, location, dispatch,app}) {
|
||||
},
|
||||
}
|
||||
|
||||
const breadProps = {
|
||||
userName,
|
||||
const headerProps = {
|
||||
user,
|
||||
location,
|
||||
loginOut() {
|
||||
dispatch({
|
||||
type: 'app/loginOut'
|
||||
@@ -38,7 +39,7 @@ function App({children, location, dispatch,app}) {
|
||||
<Sider/>
|
||||
</aside>
|
||||
<div className={styles.main}>
|
||||
<Header location={location}/>
|
||||
<Header {...headerProps}/>
|
||||
<Bread location={location}/>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
@@ -59,7 +60,7 @@ App.propTypes = {
|
||||
loading: PropTypes.object,
|
||||
loginButtonLoading:PropTypes.bool,
|
||||
login: PropTypes.bool,
|
||||
userName:PropTypes.object,
|
||||
user:PropTypes.object,
|
||||
}
|
||||
|
||||
function mapStateToProps({app}) {
|
||||
|
||||
Reference in New Issue
Block a user