Commit ac97648b authored by 刘松's avatar 刘松

fix page

parent 50c5f4dd
...@@ -50,7 +50,9 @@ app.get('/manage/*', function (req, res){ ...@@ -50,7 +50,9 @@ app.get('/manage/*', function (req, res){
app.use(routes); app.use(routes);
app.listen(config.port); app.listen(config.port);
console.log('server started on port ' + config.port); console.log(process.env.NODE_ENV + 'server started on port ' + config.port);
if(process.env.NODE_ENV === 'production'){
cron.start();
cron_gather.start();
}
cron.start();
cron_gather.start();
This diff is collapsed.
...@@ -6,7 +6,8 @@ const api = require('../../js/api'); ...@@ -6,7 +6,8 @@ const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx'; import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button} from 'antd'; import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Select,Radio} from 'antd';
const Option = Select.Option;
const { RangePicker } = DatePicker; const { RangePicker } = DatePicker;
class DashBoard extends React.Component{ class DashBoard extends React.Component{
...@@ -14,7 +15,7 @@ class DashBoard extends React.Component{ ...@@ -14,7 +15,7 @@ class DashBoard extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')]; this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')];
this.state= { logs :[],status:'pending',pagination:{current:1,pageSize:100,total:1} }; this.state= { logs :[],status:'pending',pagination:{current:1,pageSize:100,total:1},sort:'updatedAt' };
} }
componentDidMount(){ componentDidMount(){
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){ if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
...@@ -22,23 +23,21 @@ class DashBoard extends React.Component{ ...@@ -22,23 +23,21 @@ class DashBoard extends React.Component{
} }
let pagination = this.state.pagination; let pagination = this.state.pagination;
let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')}; let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api('GET', 'logs?'+'skip=0&limit=' + pagination.pageSize).then((res) => { api('GET', 'logs?'+'skip=0&limit=' + pagination.pageSize+'&sort=updatedAt').then((res) => {
this.setState({logs:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}}) this.setState({logs:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
console.dir(res.result);
}); });
} }
getlogs(pagination){ getlogs(pagination,sort){
this.setState({status:'pending'}); this.setState({status:'pending'});
api('GET', 'logs?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => { api('GET', 'logs?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize + '&sort='+ sort).then((res) => {
this.setState({logs:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}}) this.setState({logs:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
console.dir(res.result);
}); });
} }
onChange(pagination) { onChange(pagination) {
//let data = { start:dateString[0],end:dateString[1]}; //let data = { start:dateString[0],end:dateString[1]};
this.getlogs(pagination); this.getlogs(pagination,this.state.sort);
//this.props.dispatch(actions.getMainData(data)); //this.props.dispatch(actions.getMainData(data));
} }
onChangeRange(date, dateString){ onChangeRange(date, dateString){
...@@ -49,8 +48,22 @@ class DashBoard extends React.Component{ ...@@ -49,8 +48,22 @@ class DashBoard extends React.Component{
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'}); //json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
} }
handleSort(e){
this.setState({sort:e.target.value});
this.getlogs({current:1,pageSize:this.state.pagination.pageSize},e.target.value);
}
handleChange(value){
var pagination = this.state.pagination;
console.dir(pagination);
pagination['current'] = 1;
pagination['pageSize'] = parseInt(value);
this.setState({pagination:pagination});
this.getlogs(pagination,this.state.sort);
}
render(){ render(){
console.dir(this.state.pagination);
const columns = [ const columns = [
{ {
title: '日期', title: '日期',
...@@ -84,6 +97,7 @@ class DashBoard extends React.Component{ ...@@ -84,6 +97,7 @@ class DashBoard extends React.Component{
dataIndex: 'qd', dataIndex: 'qd',
key: 'qd', key: 'qd',
width: 100, width: 100,
// sorter: (a, b) => { a.qd - b.qd},
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
...@@ -111,7 +125,6 @@ class DashBoard extends React.Component{ ...@@ -111,7 +125,6 @@ class DashBoard extends React.Component{
let count = 0; let count = 0;
let logs = this.state.logs; let logs = this.state.logs;
for(let i = 0;i<logs.length;i++){ for(let i = 0;i<logs.length;i++){
console.dir(logs[i]);
data.push({ data.push({
key:i, key:i,
date:logs[i].date, date:logs[i].date,
...@@ -130,6 +143,26 @@ class DashBoard extends React.Component{ ...@@ -130,6 +143,26 @@ class DashBoard extends React.Component{
<Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}> <Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}>
导出数据 导出数据
</Button> </Button>
<Radio.Group value = { this.state.sort } onChange={this.handleSort.bind(this)} style={{ float:'right', "margin":'10px' }}>
<Radio.Button value="updatedAt">按更新</Radio.Button>
<Radio.Button value="status">按状态</Radio.Button>
<Radio.Button value="schedule">按计划</Radio.Button>
<Radio.Button value="date">按日期</Radio.Button>
</Radio.Group>
<Select
size ="default"
defaultValue="100"
value = { this.state.pagination.pageSize }
onChange={this.handleChange.bind(this)}
style={{ width: 100,float:'right', "margin":'10px' }}
>
<Option key='10'>10</Option>
<Option key='20'>20</Option>
<Option key='50'>50</Option>
<Option key='100'>100</Option>
<Option key='200'>200</Option>
<Option key='500'>500</Option>
</Select>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/> <Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin> </Spin>
......
...@@ -14,15 +14,15 @@ class Gather extends React.Component{ ...@@ -14,15 +14,15 @@ class Gather extends React.Component{
constructor(props){ constructor(props){
super(props); super(props);
this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')]; this.range = [moment().subtract(6,'days').format('YYYYMMDD'), moment().format('YYYYMMDD')];
this.state= { qdgathers :[],status:'pending',pagination:{current:1,pageSize:10,total:100},username:'channel',tody:{ tkl_count:0,count:0,schedule_count:0} ,none_tkls:[],list:[]}; this.state= { qdgathers :[],status:'pending',pagination:{current:1,pageSize:20,total:100},username:'channel',tody:{ tkl_count:0,count:0,schedule_count:0} ,none_tkls:[],list:[]};
} }
componentDidMount(){ componentDidMount(){
let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')}; let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){ if(document.cookie.match('username=[a-zA-Z0-9]+')[0] && document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]){
this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]}); this.setState({username:document.cookie.match('username=[a-zA-Z0-9]+')[0].split('=')[1]});
} }
api('GET', 'gathers/qd').then((res) => { api('GET', 'gathers/qd?skip=0&limit=20').then((res) => {
this.setState({qdgathers:res.result,status:'ready',none_tkls:res.none_tkls,list:res.list}); this.setState({qdgathers:res.result,status:'ready',none_tkls:res.none_tkls,list:res.list,pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}});
this.handle(res.list,res.tkl_count) this.handle(res.list,res.tkl_count)
}); });
} }
...@@ -36,7 +36,7 @@ class Gather extends React.Component{ ...@@ -36,7 +36,7 @@ class Gather extends React.Component{
} }
getQdGatherss(pagination){ getQdGathers(pagination){
this.setState({status:'pending'}) this.setState({status:'pending'})
api('GET', 'gathers/qd?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => { api('GET', 'gathers/qd?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize).then((res) => {
this.setState({qdgathers:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},none_tkls:res.none_tkls,list:res.list}); this.setState({qdgathers:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},none_tkls:res.none_tkls,list:res.list});
...@@ -44,9 +44,14 @@ class Gather extends React.Component{ ...@@ -44,9 +44,14 @@ class Gather extends React.Component{
}); });
} }
onChange(date, dateString) { onChange(pagination) {
let data = { start:dateString[0],end:dateString[1]}; //let data = { start:dateString[0],end:dateString[1]};
//this.props.dispatch(actions.getMainData(data)); //this.props.dispatch(actions.getMainData(data));
this.getQdGathers(pagination);
}
onChangeDate(){
} }
exportData(){ exportData(){
...@@ -55,12 +60,13 @@ class Gather extends React.Component{ ...@@ -55,12 +60,13 @@ class Gather extends React.Component{
} }
render(){ render(){
console.dir(this.state.pagination);
const columns = [ const columns = [
{ {
title: '日期', title: '日期',
dataIndex: 'date', dataIndex: 'date',
key: 'date', key: 'date',
width: 100, width: 80,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
...@@ -74,21 +80,21 @@ class Gather extends React.Component{ ...@@ -74,21 +80,21 @@ class Gather extends React.Component{
title: '请求数', title: '请求数',
dataIndex: 'times', dataIndex: 'times',
key: 'times', key: 'times',
width: 100, width: 50,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '导出数', title: '导出数',
dataIndex: 'dc_times', dataIndex: 'dc_times',
key: 'dc_times', key: 'dc_times',
width: 100, width: 50,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
}, },
{ {
title: '导出率(%)', title: '导出率(%)',
dataIndex: 'rate', dataIndex: 'rate',
key: 'rate', key: 'rate',
width: 100, width: 50,
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
} }
]; ];
...@@ -184,12 +190,12 @@ class Gather extends React.Component{ ...@@ -184,12 +190,12 @@ class Gather extends React.Component{
</Col> </Col>
</Row> </Row>
</div> </div>
<RangePicker onChange={ this.onChange.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/> {<RangePicker onChange={ this.onChangeDate.bind(this) } value={ ranges } format={'YYYYMMDD'} style={{margin:'10px 0px'}}/>}
<Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}> <Button type="primary" icon="export" onClick={ this.exportData.bind(this) } style={{ float:'right',margin:'10px 0px'}}>
导出数据 导出数据
</Button> </Button>
<Spin spinning= { this.state.status == 'pending' }> <Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" bordered/> <Table columns={columns} dataSource = { data } pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} size="middle" bordered/>
</Spin> </Spin>
</div> </div>
) )
......
...@@ -63,12 +63,15 @@ exports.putTbkl = async (req, res, next) => { ...@@ -63,12 +63,15 @@ exports.putTbkl = async (req, res, next) => {
}; };
exports.logs = async (req, res, next) => { exports.logs = async (req, res, next) => {
let {start,end} = req.body;
//const condition = {'$and': [{'createdAt': {'$gte': moment(start, 'YYYYMMDD').startOf('day').toDate()}}, {'createdAt': {'$lt': moment(end, 'YYYYMMDD').endOf('day').toDate()}}]}; //const condition = {'$and': [{'createdAt': {'$gte': moment(start, 'YYYYMMDD').startOf('day').toDate()}}, {'createdAt': {'$lt': moment(end, 'YYYYMMDD').endOf('day').toDate()}}]};
let sess = req.cookies['sess']; let sess = req.cookies['sess'];
if(sess){ if(sess){
let {limit = 100,skip = 0,sort = {'updatedAt': -1}} = req.query; let {limit = 100,skip = 0,sort = 'updatedAt'} = req.query;
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort}; var sort_body = {};
if(sort) sort_body[ sort ] = -1;
sort_body['updatedAt'] = -1;
console.dir(sort_body);
let options = {limit:parseInt(limit),skip:parseInt(skip)*limit,sort:sort_body};
var session_body = await Session.findById(sess); var session_body = await Session.findById(sess);
var logs = []; var logs = [];
var total = 0; var total = 0;
...@@ -89,7 +92,7 @@ exports.logs = async (req, res, next) => { ...@@ -89,7 +92,7 @@ exports.logs = async (req, res, next) => {
total = await Log.count(qs,null); total = await Log.count(qs,null);
} }
logs = logs.map(x => { var d = x.toJSON();d['updatedAt'] = dateFormat(d['updatedAt']);return d;}); logs = logs.map(x => { var d = x.toJSON();d['updatedAt'] = dateFormat(d['updatedAt']);return d;});
res.send({ status:'ok',result:logs,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:logs,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
} }
else{ else{
res.status(400).send(not_login); res.status(400).send(not_login);
...@@ -156,11 +159,12 @@ exports.getQdGatherData = async (req, res, next) => { ...@@ -156,11 +159,12 @@ exports.getQdGatherData = async (req, res, next) => {
}); });
none_tkls = await Nonetkl.find({date:match_qs['date']}).populate('qd','user').limit(1000); none_tkls = await Nonetkl.find({date:match_qs['date']}).populate('qd','user').limit(1000);
} }
console.dir(options);
var gatherDatas = await GatherData.find(qs,null,options).populate('qd','user'); var gatherDatas = await GatherData.find(qs,null,options).populate('qd','user');
let total = await GatherData.count({},null); let total = await GatherData.count(qs,null);
let tkl_count = await Kouling.count(kl_qs,null); let tkl_count = await Kouling.count(kl_qs,null);
gatherDatas = gatherDatas.map(x => { var d = x.toJSON();d['date'] = dateFormat(d['date'],'YYYYMMDD'); return d;}); gatherDatas = gatherDatas.map(x => { var d = x.toJSON();d['date'] = dateFormat(d['date'],'YYYYMMDD'); return d;});
res.send({ status:'ok',result:gatherDatas,list:list,none_tkls:none_tkls,tkl_count:tkl_count,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:gatherDatas,list:list,none_tkls:none_tkls,tkl_count:tkl_count,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
} }
else{ else{
res.status(400).send(not_login); res.status(400).send(not_login);
...@@ -178,7 +182,7 @@ exports.getTbkls = async (req, res, next) => { ...@@ -178,7 +182,7 @@ exports.getTbkls = async (req, res, next) => {
let tbkls = await Kouling.find({},null,options).populate('link','title target'); let tbkls = await Kouling.find({},null,options).populate('link','title target');
tbkls = tbkls.map(x => { var d = x.toJSON();d['createdAt'] = dateFormat(d['createdAt']);return d;}); tbkls = tbkls.map(x => { var d = x.toJSON();d['createdAt'] = dateFormat(d['createdAt']);return d;});
let total = await Kouling.count({},null); let total = await Kouling.count({},null);
res.send({ status:'ok',result:tbkls,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:tbkls,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
} }
exports.getLinks = async (req, res, next) => { exports.getLinks = async (req, res, next) => {
...@@ -203,7 +207,7 @@ exports.getLinks = async (req, res, next) => { ...@@ -203,7 +207,7 @@ exports.getLinks = async (req, res, next) => {
}); });
} }
}); });
res.send({ status:'ok',result:links,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:links,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
} }
exports.createLink = async (req, res, next) => { exports.createLink = async (req, res, next) => {
...@@ -248,7 +252,7 @@ exports.getSchedules = async (req, res, next) => { ...@@ -248,7 +252,7 @@ exports.getSchedules = async (req, res, next) => {
Promise.all(tasks).then(async function(arr){ Promise.all(tasks).then(async function(arr){
let total = await Schedule.count({},null); let total = await Schedule.count({},null);
schedules = schedules.map( (x,i) => { var a = x.toJSON();a['createdAt'] = dateFormat(a['createdAt']); a['count'] = arr[i]; return a}); schedules = schedules.map( (x,i) => { var a = x.toJSON();a['createdAt'] = dateFormat(a['createdAt']); a['count'] = arr[i]; return a});
res.send({ status:'ok',result:schedules,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:schedules,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
}); });
} }
...@@ -272,7 +276,7 @@ exports.getQds = async (req, res, next) => { ...@@ -272,7 +276,7 @@ exports.getQds = async (req, res, next) => {
return x; return x;
}); });
//console.dir(_arrs); //console.dir(_arrs);
res.send({ status:'ok',result:qds,pagination:{total:total,skip:skip,limit:limit}}); res.send({ status:'ok',result:qds,pagination:{total:total,skip:parseInt(skip)+1,limit:limit}});
} }
exports.createQd = async (req, res, next) => { exports.createQd = async (req, res, next) => {
......
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