Commit 0b12a7e4 authored by 刘松's avatar 刘松

update detail popover

parent ac97648b
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -89,3 +89,36 @@ body{ ...@@ -89,3 +89,36 @@ body{
padding: 0 20px; padding: 0 20px;
text-align: center; text-align: center;
} }
.detail-body{
margin-bottom: 3px;
}
.detail-body-list{
width: 500px;
}
.detail-body span{
width: 50%;
display: inline-block;
}
.detail-body-list{
margin-bottom: 3px;
display: -webkit-flex; /* Safari */
display: flex;
flex-direction: row;
flex-wrap: nowrap;
justify-content:flex-start;
align-items:center;
}
.detail-body-list span{
display: block;
margin: 0px 5px;
}
.detail-body-list span:nth-of-type(1){
width: 40%;
}
.detail-body-list span:nth-of-type(2){
width: 50%;
}
.detail-body-list span:nth-of-type(3){
width: 10%;
}
const React = require('react');
const moment = require('moment');
const api = require('../../js/api');
import json2xlsx from '../../js/json2xlsx';
import { Table, Icon, DatePicker, Alert, Row, Col, Spin, Button,Badge} from 'antd';
const { RangePicker } = DatePicker;
class Details extends React.Component{
constructor(props){
super(props);
console.dir(this.props);
this.state= { details :[],status:'pending',pagination:{current:1,pageSize:10,total:100},modalVisible:false,username:'channel',qd:null,date:null};
}
getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
componentDidMount(){
let pagination = this.state.pagination;
//alert(this.getQueryString('date') + this.getQueryString('qd'));
let qd = this.getQueryString('qd');
let date = this.getQueryString('date');
this.setState({qd:qd,date:date});
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]});
}
//let data = { start:moment().add(-6,'days').format('YYYYMMDD'),end:moment().format('YYYYMMDD')};
api('GET', 'details?'+'skip=0&limit=' + pagination.pageSize+'&qd='+qd+'&date='+date).then((res) => {
this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total},info:{quan:'',good:''}})
console.dir(res.result);
});
}
getdetails(pagination){
console.dir(pagination);
this.setState({status:'pending'});
api('GET', 'details?'+'skip='+ (pagination.current-1) + '&limit=' + pagination.pageSize +'&qd=' + this.state.qd+'&date=' + this.state.date).then((res) => {
this.setState({details:res.result,status:'ready',pagination:{current:res.pagination.skip,pageSize:res.pagination.limit,total:res.pagination.total}})
console.dir(res.result);
});
}
onChange(pagination) {
this.getdetails(pagination);
}
exportData(){
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
}
render(){
const columns = [
{
title: '渠道',
dataIndex: 'qd',
key: 'qd',
width: 60,
render: text => <span href="#">{text}</span>,
},
{
title: '计划ID',
dataIndex: 'schedule',
key: 'schedule',
width: 100,
render: text => <span href="#">{text}</span>,
},
{
title: '商品页面',
dataIndex: 'link',
key: 'link',
width: 100,
render: text => <span href="#">{text}</span>,
},
{
title: '淘口令',
dataIndex: 'tkl',
key: 'tkl',
width: 100,
render: text => <span href="#">{text}</span>,
},
{
title: '请求数',
dataIndex: 'times',
key: 'times',
width: 40,
render: text => <span href="#">{text}</span>
}
];
let data = [];
let details = this.state.details;
for(let i = 0;i<details.length;i++){
data.push({
key:i,
qd:details[i].info ,
schedule:details[i].schedule,
link:(details[i].link && details[i].link['target']) || '--',
tkl:details[i].status,
times:details[i].createdAt
});
}
return (
<div>
<Alert
message="提示"
description="淘口令油后台任务自动生成"
type="info"
/>
<Spin spinning= { this.state.status == 'pending' }>
<Table columns={columns} dataSource = { data } size="middle" pagination={ this.state.pagination } onChange = { this.onChange.bind(this)} bordered/>
</Spin>
</div>
)
}
}
module.exports = Details;
...@@ -59,6 +59,13 @@ class Gather extends React.Component{ ...@@ -59,6 +59,13 @@ class Gather extends React.Component{
//json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'}); //json2xlsx(data,{sheetName:"基础数据", filename : '基础数据'+moment().format('YYYYMMDD')+'.xlsx'});
} }
detailData(data){
console.dir(data);
var date = data.date;
var qd = data.qd;
location.href = '/manage/detail?qd='+qd+'&date='+date
}
render(){ render(){
console.dir(this.state.pagination); console.dir(this.state.pagination);
const columns = [ const columns = [
...@@ -98,6 +105,18 @@ class Gather extends React.Component{ ...@@ -98,6 +105,18 @@ class Gather extends React.Component{
render: text => <span href="#">{text}</span>, render: text => <span href="#">{text}</span>,
} }
]; ];
if(this.state.username == 'admin')
columns.push({
title: '详情',
dataIndex: 'detail',
key: 'detail',
width: 10,
render: (text,data) => <Popover placement="left" content={ text } title="详情 (计划ID - 商品页 - 请求数)">
<Button type="primary">
详情
</Button>
</Popover>
});
let range = this.range; let range = this.range;
var start = range[0]; var start = range[0];
...@@ -108,15 +127,39 @@ class Gather extends React.Component{ ...@@ -108,15 +127,39 @@ class Gather extends React.Component{
let data = []; let data = [];
let count = 0; let count = 0;
let qdgathers = this.state.qdgathers; let qdgathers = this.state.qdgathers;
for(let i = 0;i<qdgathers.length;i++){ for(let i = 0;i<qdgathers.length;i++){
data.push({ var item = qdgathers[i];
var detail_list_show = [];
var data_item = {
key:i, key:i,
date:qdgathers[i].date, qd:(item.qd && item.qd._id),
user:(qdgathers[i].qd && qdgathers[i].qd.user) + ' / ' + (qdgathers[i].qd && qdgathers[i].qd._id), date:item.date,
times:qdgathers[i].times || 0, user:(item.qd && item.qd.user) + ' / ' + (item.qd && item.qd._id),
dc_times:qdgathers[i].dc_times || 0, times:item.times || 0,
rate:qdgathers[i].dc_times / qdgathers[i].times ? ((qdgathers[i].dc_times / qdgathers[i].times).toFixed(6) * 100).toFixed(3) : 0 dc_times:item.dc_times || 0,
}); rate:item.dc_times / item.times ? ((item.dc_times / item.times).toFixed(6) * 100).toFixed(3) : 0
}
if(this.state.username == 'admin'){
if(item.schedules && item.schedules.length)
item.schedules.sort((a,b) => { return b.times - a.times });
for(var j = 0;j < item.schedules.length; j++){
var _item = item.schedules[j];
var schedule_id = _item.schedule && _item.schedule._id;
var links = '';
if(_item.schedule && _item.schedule.links)
links = _item.schedule.links.map( x => x.name).join(',')
var times = _item.times;
detail_list_show.push(<div className="detail-body-list" key={ schedule_id }><span>{ schedule_id }</span><span>{ links }</span><span>{ times }</span></div>);
}
var detail_content = (
<div>
{ detail_list_show }
</div>
);
data_item['detail']=detail_content;
}
data.push(data_item);
} }
var none_tkls = this.state.none_tkls; var none_tkls = this.state.none_tkls;
var list = this.state.list; var list = this.state.list;
...@@ -126,7 +169,7 @@ class Gather extends React.Component{ ...@@ -126,7 +169,7 @@ class Gather extends React.Component{
for(var i in none_tkls){ for(var i in none_tkls){
sum += none_tkls[i]['times']; sum += none_tkls[i]['times'];
let qd = none_tkls[i]["qd"]; let qd = none_tkls[i]["qd"];
if(qd) list_show.push(<p key={ qd['user'] }>{qd['user'] + " " +none_tkls[i]['times']}</p>) if(qd) list_show.push(<div className="detail-body" key={ qd['user'] }><span>{qd['user']}</span><span>{ none_tkls[i]['times'] }</span></div>)
} }
var map2qd = {}; var map2qd = {};
for(var k in list){ for(var k in list){
...@@ -134,8 +177,9 @@ class Gather extends React.Component{ ...@@ -134,8 +177,9 @@ class Gather extends React.Component{
map2qd[list[k]['qd']['user']] = (map2qd[list[k]['qd']['user']] ? (map2qd[list[k]['qd']['user']]+list[k]['sum']) : list[k]['sum']); map2qd[list[k]['qd']['user']] = (map2qd[list[k]['qd']['user']] ? (map2qd[list[k]['qd']['user']]+list[k]['sum']) : list[k]['sum']);
} }
for(var j in map2qd){ for(var j in map2qd){
sum_list_show.push(<p key={ j }>{j + " " +map2qd[j]}</p>); sum_list_show.push(<div className="detail-body" key={ j }><span>{j}</span><span>{ map2qd[j] }</span></div>);
} }
const content = ( const content = (
<div> <div>
{ list_show } { list_show }
...@@ -145,7 +189,6 @@ class Gather extends React.Component{ ...@@ -145,7 +189,6 @@ class Gather extends React.Component{
<div> <div>
{ sum_list_show } { sum_list_show }
</div>); </div>);
return ( return (
<div> <div>
<div> <div>
...@@ -154,7 +197,7 @@ class Gather extends React.Component{ ...@@ -154,7 +197,7 @@ class Gather extends React.Component{
<div className = "box" style={{ marginLeft:'0px'}}> <div className = "box" style={{ marginLeft:'0px'}}>
<h3>请求数</h3>{ <h3>请求数</h3>{
this.state.username !== 'admin' ? <span>{ this.state.tody.count }</span> : this.state.username !== 'admin' ? <span>{ this.state.tody.count }</span> :
<Popover content={sum_content} title="详情"> <Popover placement="bottom" content={sum_content} title="详情">
<span>{ this.state.tody.count }</span> <span>{ this.state.tody.count }</span>
</Popover> </Popover>
} }
...@@ -176,7 +219,7 @@ class Gather extends React.Component{ ...@@ -176,7 +219,7 @@ class Gather extends React.Component{
</Col> : <Col span="6"> </Col> : <Col span="6">
<div className = "box" style={{ marginLeft:'0px'}}> <div className = "box" style={{ marginLeft:'0px'}}>
<h3>无效请求</h3> <h3>无效请求</h3>
<Popover content={content} title="详情"> <Popover placement="bottom" content={content} title="详情">
<span>{ sum }</span> <span>{ sum }</span>
</Popover> </Popover>
</div> </div>
......
...@@ -11,10 +11,15 @@ const schema = mongoose.Schema({ ...@@ -11,10 +11,15 @@ const schema = mongoose.Schema({
required: true, required: true,
ref:'tao-agent' ref:'tao-agent'
}, },
schedules:{ schedules:[{
type:Array, schedule:{
required:true type:ObjectId,
ref:'tao-schedule'
}, },
times:{
type:Number
}
}],
times:{ times:{
type:Number, type:Number,
required: true required: true
......
...@@ -14,6 +14,7 @@ const url = require('url'); ...@@ -14,6 +14,7 @@ const url = require('url');
const not_full = 'params not full error'; const not_full = 'params not full error';
const not_right = 'params not right error'; const not_right = 'params not right error';
const not_login = 'please login first'; const not_login = 'please login first';
const not_auth = 'auth error';
function dateFormat(target,format) { function dateFormat(target,format) {
return moment(new Date(target.getTime()),'x').format(format || 'YYYYMMDD HH:mm:ss'); return moment(new Date(target.getTime()),'x').format(format || 'YYYYMMDD HH:mm:ss');
...@@ -159,8 +160,7 @@ exports.getQdGatherData = async (req, res, next) => { ...@@ -159,8 +160,7 @@ 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').populate({path:'schedules.schedule',populate:{path:'links',select:'name'}});
var gatherDatas = await GatherData.find(qs,null,options).populate('qd','user');
let total = await GatherData.count(qs,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;});
...@@ -413,6 +413,66 @@ exports.newTbkl = async (req, res, next) => { ...@@ -413,6 +413,66 @@ exports.newTbkl = async (req, res, next) => {
res.send({result:'ok',new:result,remove_result:{nModified:0}}); res.send({result:'ok',new:result,remove_result:{nModified:0}});
} }
/*exports.getDetails = async (req,res,next) => {
var {date,qd} = req.query;
let now = moment().add(8,'hours').format('YYYYMMDD');
if(!date || !qd || parseInt(now) - parseInt(date) < 0){
res.status(400).send(not_right);
}
let sess = req.cookies['sess'];
if(sess){
var session_body = await Session.findById(sess);
if(session_body){
var user = session_body.toJSON().user;
if(user != '5a1e81f8c86fa7aa4b51b18b' && user != qd){
res.status(400).send(not_auth);
}
else{
var list = await Log.aggregate([
{
$match:{date:date}
},
{
$group:{
_id: "$schedule",
sum:{ $sum:"$times" }
}
}
]);
var tasks = [];
list.forEach(item => {
tasks.push(Schedule.findById(item._id).populate('qd','user').populate('links'));
});
var arrs = await Promise.all(tasks);
var _arrs = [];
var _list = [];
var schedules = [];
arrs.forEach( item => {
if(item.qd && item.qd._id == qd){
schedules.push(item._id + '');
_arrs.push(item);
}
});
list.forEach( item => {
console.dir(schedules.indexOf(item._id+''))
if(schedules.indexOf(item._id+'') >= 0) _list.push(item);
});
res.send({status:'ok',infos:_arrs,result:_list});
}
}
else{
res.status(400).send(not_login);
}
}else{
res.status(400).send(not_login);
}
}*/
var createTbkl = async (data) => { var createTbkl = async (data) => {
let {title,target,pic,qd} = data; let {title,target,pic,qd} = data;
return new Promise(async (r,d) => { return new Promise(async (r,d) => {
......
...@@ -20,6 +20,8 @@ router.post('/newtkl',controller.newTbkl); ...@@ -20,6 +20,8 @@ router.post('/newtkl',controller.newTbkl);
router.post('/link',controller.createLink); router.post('/link',controller.createLink);
//router.get('/details',controller.getDetails);
router.get('/schedules',controller.getSchedules); router.get('/schedules',controller.getSchedules);
router.post('/schedule',controller.createSchedule); router.post('/schedule',controller.createSchedule);
......
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