skycaiji/public/static/js/admin/collected.js

16 lines
4.8 KiB
JavaScript

/*
|--------------------------------------------------------------------------
| SkyCaiji (蓝天采集器)
|--------------------------------------------------------------------------
| Copyright (c) 2018 https://www.skycaiji.com All rights reserved.
|--------------------------------------------------------------------------
| 使用协议 https://www.skycaiji.com/licenses
|--------------------------------------------------------------------------
*/
'use strict';function CollectedClass(){}
CollectedClass.prototype={constructor:CollectedClass,init_list:function(){$('#list_table .delete').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){$.ajax({type:"GET",url:obj.attr('url'),dataType:"json",success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);if(data.code==1){obj.parents('tr').eq(0).remove()}}})})});$('#deleteall').bind('click',function(){var obj=$(this);confirmRight(window.tpl_lang.confirm_delete,function(){$.ajax({type:"POST",url:ulink('Collected/op?op=deleteall'),dataType:"json",data:$('#form_list').serialize(),success:function(data){data.code==1?toastr.success(data.msg):toastr.error(data.msg);setTimeout("window.location.reload();",2500)}})})});$('#btn_clear_error').bind('click',function(){windowModal('清理失败的数据',ulink('Collected/clearError'))})},chart_init:function(){$('#chart_date [data-chart-op]').bind('click',function(){if(!$('#chart_date').attr('data-chart-tpl')){$('#chart_date').attr('data-chart-tpl',$('#chart_date .chart-box').prop('outerHTML'))}
$('#chart_date .nav-tabs>li').removeClass('active');$(this).parents('li').eq(0).addClass('active');$('#chart_date .chart-loading').show();$('#chart_date .chart-canvas').remove();var chartOp=$(this).attr('data-chart-op');$.ajax({type:"GET",url:ulink('Collected/chartOp?op='+chartOp),dataType:"json",success:function(data){var chartData={labels:[],datasets:[{label:"发布成功",data:[],backgroundColor:'rgba(54, 162, 235, 0.2)',borderColor:'rgba(54, 162, 235, 1)',borderWidth:1,},{label:"发布失败",data:[],backgroundColor:'rgba(255, 99, 132, 0.2)',borderColor:'rgba(255, 99, 132, 1)',borderWidth:1,}]};if(data.code==1&&data.data){var nameData=data.data.name;var successData=data.data.success;var failedData=data.data.failed;if(nameData){for(var i in nameData){chartData.labels.push(nameData[i]);chartData.datasets[0].data.push(successData[i]?successData[i]:0);chartData.datasets[1].data.push(failedData[i]?failedData[i]:0)}}}
$('#chart_date .chart-box').html($('#chart_date').attr('data-chart-tpl'));$('#chart_date .chart-loading').hide();var chart=$("#chart_date .chart-canvas").get(0).getContext("2d");chart=new Chart(chart,{type:'line',data:chartData,options:{maintainAspectRatio:!1,tooltips:{mode:'index',intersect:!1,}}});chart.canvas.parentNode.style.height='300px'}})});$('#chart_date [data-chart-op="today"]').trigger('click');$.ajax({type:"GET",url:ulink('Collected/chartOp?op=release'),dataType:"json",success:function(data){var chartData={labels:[],datasets:[{label:"发布成功",data:[],backgroundColor:'rgba(54, 162, 235, 0.2)',borderColor:'rgba(54, 162, 235, 1)',pointBackgroundColor:'rgba(54, 162, 235, 0.2)',pointBorderColor:'rgba(54, 162, 235, 1)',borderWidth:1,},{label:"发布失败",data:[],backgroundColor:'rgba(255, 99, 132, 0.2)',borderColor:'rgba(255, 99, 132, 1)',pointBackgroundColor:'rgba(255, 99, 132, 0.2)',pointBorderColor:'rgba(255, 99, 132, 1)',borderWidth:1,}]};if(data.code==1&&data.data){var nameData=data.data.name;var successData=data.data.success;var failedData=data.data.failed;if(nameData){for(var i in nameData){chartData.labels.push(nameData[i]);chartData.datasets[0].data.push(successData[i]?successData[i]:0);chartData.datasets[1].data.push(failedData[i]?failedData[i]:0)}}
$('#chart_release .chart-loading').hide();$('#chart_release .chart-canvas').show();var chart=$("#chart_release .chart-canvas").get(0).getContext("2d");chart=new Chart(chart,{type:'radar',data:chartData,options:{maintainAspectRatio:!1,tooltips:{mode:'index',intersect:!1,}}});chart.canvas.parentNode.style.height='300px'}}});$.ajax({type:"GET",url:ulink('Collected/chartOp?op=task'),dataType:"json",success:function(data){var chartData={labels:[],datasets:[{label:"采集数量",data:[],backgroundColor:'rgba(54, 162, 235, 0.2)',}]};if(data.code==1&&data.data){var nameData=data.data.name;var totalData=data.data.total;if(nameData){for(var i in nameData){if(nameData[i]&&totalData[i]){chartData.labels.push(nameData[i]);chartData.datasets[0].data.push(totalData[i])}}}
$('#chart_task .chart-loading').hide();$('#chart_task .chart-canvas').show();var chart=$("#chart_task .chart-canvas").get(0).getContext("2d");chart=new Chart(chart,{type:'bar',data:chartData,options:{maintainAspectRatio:!1,}});chart.canvas.parentNode.style.height='300px'}}})},}
var collectedClass=new CollectedClass()