mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-02 07:53:59 +00:00
login
This commit is contained in:
+8
-3
@@ -1,6 +1,7 @@
|
||||
const qs = require('qs')
|
||||
const Mock = require('mockjs')
|
||||
const Watch = require("watchjs")
|
||||
const Cookie = require("js-cookie")
|
||||
|
||||
let adminUsersData = {}
|
||||
if (!global.adminUsersData) {
|
||||
@@ -28,9 +29,13 @@ Watch.watch(adminUsersData, function () {
|
||||
|
||||
module.exports = {
|
||||
'POST /api/login' (req, res) {
|
||||
console.log(req);
|
||||
console.log(res);
|
||||
console.log("858484");
|
||||
const now = new Date()
|
||||
now.setDate(now.getDate()+1)
|
||||
Cookie.set('user_session', now.getTime())
|
||||
res.json({success: true})
|
||||
},
|
||||
|
||||
'GET /api/userInfo' (req, res) {
|
||||
res.json({success: true})
|
||||
},
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"antd": "^2.0.1",
|
||||
"classnames": "^2.2.5",
|
||||
"dva": "1.0.0",
|
||||
"js-cookie": "^2.1.3",
|
||||
"qs": "^6.2.0",
|
||||
"react": "^15.1.0",
|
||||
"react-dom": "^15.1.0"
|
||||
|
||||
+13
-9
@@ -1,10 +1,15 @@
|
||||
import {login} from '../services/app'
|
||||
import {login, userInfo} from '../services/app'
|
||||
import {parse} from 'qs'
|
||||
import Cookie from 'js-cookie'
|
||||
|
||||
console.log(Cookie.get('user_session'));
|
||||
|
||||
export default {
|
||||
namespace : 'app',
|
||||
state : {
|
||||
login: false,
|
||||
login: Cookie.get('user_session') > new Date().getTime()
|
||||
? true
|
||||
: false,
|
||||
loading: false,
|
||||
loginButtonLoading: false
|
||||
},
|
||||
@@ -12,7 +17,7 @@ export default {
|
||||
*login({
|
||||
payload
|
||||
}, {call, put}) {
|
||||
yield put({ type: 'showButtonLoading' })
|
||||
yield put({type: 'showButtonLoading'})
|
||||
const data = yield call(login, parse(payload))
|
||||
if (data) {
|
||||
yield put({type: 'loginSuccess', payload: {
|
||||
@@ -23,14 +28,13 @@ export default {
|
||||
},
|
||||
reducers : {
|
||||
loginSuccess(state) {
|
||||
return {
|
||||
login: true,
|
||||
loading: false,
|
||||
loginButtonLoading: false
|
||||
}
|
||||
return {login: true, loading: false, loginButtonLoading: false}
|
||||
},
|
||||
showLoading(state) {
|
||||
return { ...state, loginButtonLoading: true }
|
||||
return {
|
||||
...state,
|
||||
loginButtonLoading: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -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} = app
|
||||
const {login, loading,loginButtonLoading,userName} = app
|
||||
const loginProps = {
|
||||
loading,
|
||||
loginButtonLoading,
|
||||
@@ -22,6 +22,15 @@ function App({children, location, dispatch,app}) {
|
||||
},
|
||||
}
|
||||
|
||||
const breadProps = {
|
||||
userName,
|
||||
loginOut() {
|
||||
dispatch({
|
||||
type: 'app/loginOut'
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
return (
|
||||
<div>{login
|
||||
? <div className={styles.layout}>
|
||||
@@ -48,8 +57,9 @@ App.propTypes = {
|
||||
location: PropTypes.object,
|
||||
dispatch: PropTypes.func,
|
||||
loading: PropTypes.object,
|
||||
loginButtonLoading:PropTypes.object,
|
||||
login: PropTypes.object,
|
||||
loginButtonLoading:PropTypes.bool,
|
||||
login: PropTypes.bool,
|
||||
userName:PropTypes.object,
|
||||
}
|
||||
|
||||
function mapStateToProps({app}) {
|
||||
|
||||
+4
-4
@@ -45,17 +45,17 @@ const login = ({
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '姓名未填写'
|
||||
message: '请填写用户名'
|
||||
}
|
||||
]
|
||||
})(<Input size="large" placeholder="账户"/>)}
|
||||
})(<Input size="large" placeholder="用户名"/>)}
|
||||
</FormItem>
|
||||
<FormItem hasFeedback>
|
||||
{getFieldDecorator('password', {
|
||||
rules: [
|
||||
{
|
||||
required: true,
|
||||
message: '姓名未填写'
|
||||
message: '请填写密码'
|
||||
}
|
||||
]
|
||||
})(<Input size="large" placeholder="密码"/>)}
|
||||
@@ -76,7 +76,7 @@ const login = ({
|
||||
|
||||
login.propTypes = {
|
||||
form: PropTypes.object,
|
||||
loginButtonLoading:PropTypes.object,
|
||||
loginButtonLoading:PropTypes.bool,
|
||||
onOk: PropTypes.func
|
||||
}
|
||||
|
||||
|
||||
+14
-1
@@ -2,9 +2,22 @@ import { request } from '../utils'
|
||||
import qs from 'qs'
|
||||
|
||||
export async function login(params) {
|
||||
console.log("48646");
|
||||
return request('/api/login', {
|
||||
method: 'post',
|
||||
data:params,
|
||||
})
|
||||
}
|
||||
|
||||
export async function loginOut(params) {
|
||||
return request('/api/loginOut', {
|
||||
method: 'post',
|
||||
data:params,
|
||||
})
|
||||
}
|
||||
|
||||
export async function userInfo(params) {
|
||||
return request('/api/userInfo', {
|
||||
method: 'get',
|
||||
data:params,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user