diff --git a/mock/app.js b/mock/app.js index acf63ea..84aa842 100644 --- a/mock/app.js +++ b/mock/app.js @@ -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}) }, } diff --git a/package.json b/package.json index 42d313f..851d2de 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/src/models/app.js b/src/models/app.js index c50050e..11f8e7c 100644 --- a/src/models/app.js +++ b/src/models/app.js @@ -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 + } } } } diff --git a/src/routes/app.js b/src/routes/app.js index 9994662..1b61118 100644 --- a/src/routes/app.js +++ b/src/routes/app.js @@ -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 (