Commit b35b9488 authored by 刘松's avatar 刘松

优化

parent e3ac86cb
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,5 +3,6 @@ module.exports = { ...@@ -3,5 +3,6 @@ module.exports = {
CURRENTPAGE: 'CURRENTPAGE', CURRENTPAGE: 'CURRENTPAGE',
MAINDATA:'MAINDATA', MAINDATA:'MAINDATA',
COUNTDATA:'COUNTDATA', COUNTDATA:'COUNTDATA',
DETAILDATA:'DETAILDATA' DETAILDATA:'DETAILDATA',
STATUS:'STATUS'
}; };
...@@ -23,6 +23,7 @@ exports.getSession = (data) => { ...@@ -23,6 +23,7 @@ exports.getSession = (data) => {
exports.getMainData = (data) => { exports.getMainData = (data) => {
return (dispatch) => { return (dispatch) => {
api('POST', 'data', data).then((res) => { api('POST', 'data', data).then((res) => {
dispatch({status: 'pending', type: types.STATUS});
dispatch({ status:res.result, data:res.data, type: types.MAINDATA}); dispatch({ status:res.result, data:res.data, type: types.MAINDATA});
}); });
}; };
...@@ -39,6 +40,7 @@ exports.getCountData= () => { ...@@ -39,6 +40,7 @@ exports.getCountData= () => {
exports.getDetailData = (data) => { exports.getDetailData = (data) => {
return (dispatch) => { return (dispatch) => {
dispatch({status: 'pending', type: types.STATUS});
api('POST', 'detail', data).then((res) => { api('POST', 'detail', data).then((res) => {
dispatch({ status:res.result, data:res.data, type: types.DETAILDATA}); dispatch({ status:res.result, data:res.data, type: types.DETAILDATA});
}); });
......
...@@ -26,6 +26,8 @@ module.exports = function data (state = defaultData, action) { ...@@ -26,6 +26,8 @@ module.exports = function data (state = defaultData, action) {
return _.assign({}, state, {count:action.data}); return _.assign({}, state, {count:action.data});
case types.DETAILDATA: case types.DETAILDATA:
return _.assign({}, state, {status: action.status,detail:action.data}); return _.assign({}, state, {status: action.status,detail:action.data});
case types.STATUS:
return _.assign({}, state, {status: action.status});
default: default:
return state; return state;
} }
......
...@@ -7,6 +7,7 @@ const rootReducer = require('../reducers'); ...@@ -7,6 +7,7 @@ const rootReducer = require('../reducers');
const createDevTools = require('redux-devtools-ie8').createDevTools; const createDevTools = require('redux-devtools-ie8').createDevTools;
const LogMonitor = require('redux-devtools-log-monitor-ie8').default; const LogMonitor = require('redux-devtools-log-monitor-ie8').default;
const DockMonitor = require('redux-devtools-dock-monitor-ie8').default; const DockMonitor = require('redux-devtools-dock-monitor-ie8').default;
import sequenceAction from 'redux-sequence-action';
const thunk = require('redux-thunk').default; const thunk = require('redux-thunk').default;
...@@ -23,7 +24,7 @@ module.exports.configureStore = function configureStore () { ...@@ -23,7 +24,7 @@ module.exports.configureStore = function configureStore () {
return redux.createStore( return redux.createStore(
rootReducer, rootReducer,
redux.compose( redux.compose(
redux.applyMiddleware(thunk), redux.applyMiddleware(thunk,sequenceAction),
ReduxDevTools.instrument() ReduxDevTools.instrument()
) )
) )
......
...@@ -3,7 +3,7 @@ const connect = require('react-redux').connect; ...@@ -3,7 +3,7 @@ const connect = require('react-redux').connect;
const actions = require('../../js/actions'); const actions = require('../../js/actions');
const moment = require('moment'); const moment = require('moment');
import { Table, Icon, DatePicker, Alert, Row, Col} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin} from 'antd';
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
class DashBoard extends React.Component{ class DashBoard extends React.Component{
...@@ -157,7 +157,9 @@ class DashBoard extends React.Component{ ...@@ -157,7 +157,9 @@ class DashBoard extends React.Component{
</Col> </Col>
</Row> </Row>
<RangePicker onChange={ this.onChange.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/> <RangePicker onChange={ this.onChange.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/>
<Table columns={columns} dataSource = { data } size="middle" /> <Spin spinning= { this.props.data.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" />
</Spin>
</div> </div>
) )
} }
......
...@@ -15,17 +15,13 @@ class Detail extends React.Component{ ...@@ -15,17 +15,13 @@ class Detail extends React.Component{
componentDidMount (){ componentDidMount (){
let limit = 30; let limit = 30;
let skip = 0; let skip = 0;
// await this.props.dispatch({status:'pending',type:types.DETAILDATA}); //await this.props.dispatch({status:'pending',type:types.DETAILDATA});
this.props.dispatch(actions.getDetailData({limit,skip})); this.props.dispatch(actions.getDetailData({limit,skip}));
} }
handleTableChange (pagination, filters, sorter) { handleTableChange (pagination, filters, sorter) {
const pager = this.props.data.detail.pagination; const pager = this.props.data.detail.pagination;
pager.current = pagination.current; pager.current = pagination.current;
// this.props.dispatch({
// pagination: pager,
// type:types.DETAILDATA
// })
this.props.dispatch(actions.getDetailData({limit: 30,skip: parseInt(pager.current)-1 })); this.props.dispatch(actions.getDetailData({limit: 30,skip: parseInt(pager.current)-1 }));
} }
...@@ -76,12 +72,13 @@ class Detail extends React.Component{ ...@@ -76,12 +72,13 @@ class Detail extends React.Component{
name : item['username'] || '-', name : item['username'] || '-',
phone : item['phone'] || '-', phone : item['phone'] || '-',
ups : upMap[ item['_id'] ] || 0, ups : upMap[ item['_id'] ] || 0,
date : moment(item['createdAt']).format('YYYY/MM/DD hh:mm:ss') date : moment(item['createdAt']).format('YYYY/MM/DD HH:mm:ss')
}) })
} }
return ( return (
<Spin spinning= { this.props.data.status == 'pending' }>
<Table columns={columns} dataSource = { data } pagination={ this.props.data.detail.pagination } size="middle" onChange = { this.handleTableChange.bind(this) }/> <Table columns={columns} dataSource = { data } pagination={ this.props.data.detail.pagination } size="middle" onChange = { this.handleTableChange.bind(this) }/>
</Spin>
) )
} }
} }
......
...@@ -48,7 +48,7 @@ exports.data = async (req,res,next) => { ...@@ -48,7 +48,7 @@ exports.data = async (req,res,next) => {
exports.count = async(req,res,next) => { exports.count = async(req,res,next) => {
const userPromise = await user.count({}); const userPromise = await user.count({});
const upstreamPromise = await upstream.count({}); const upstreamPromise = await upstream.count({_id: {$exists: true}});
const adminPromise = await upstream.count({ creater:mongoose.Types.ObjectId('58afdd80aa96916a41598698') }); const adminPromise = await upstream.count({ creater:mongoose.Types.ObjectId('58afdd80aa96916a41598698') });
let userCount= 0; let userCount= 0;
let upstreamCount = 0; let upstreamCount = 0;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
"react-tap-event-plugin": "^0.2.2", "react-tap-event-plugin": "^0.2.2",
"redux": "^3.3.1", "redux": "^3.3.1",
"redux-devtools-ie8": "0.0.1", "redux-devtools-ie8": "0.0.1",
"redux-sequence-action": "^0.2.1",
"redux-thunk": "^2.2.0", "redux-thunk": "^2.2.0",
"request": "^2.81.0", "request": "^2.81.0",
"request-promise": "^4.2.1" "request-promise": "^4.2.1"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment