优化总览导出为前端导出

master
chenzhi 5 years ago
parent 48fac5ab4d
commit 768c03c78d

@ -631,6 +631,8 @@
<script src="__JS__/zwmjs/highcharts.js"></script>
<script>
var datelist;
var ydata = {$foldline|json_encode};
console.log(ydata);
$(function() {
$('.data-box').each(function() {
var that = $(this);
@ -653,12 +655,46 @@
//end 点击确定关闭日历
$('.jsexport').on('click',function() {
var that=$(this),url = $.trim(that.attr('url')).replace(/((\.htm(l?))?)$/g,'');
var but = $('.tab_head a.current').attr('data-key');
var times = [];
if(ydata.hours ==1){
times = ["0:00","2:00","4:00","6:00","8:00","10:00","12:00","14:00","16:00","18:00","20:00","22:00"];
}else{
times = ydata["date"].split(",");
}
var value = ydata[but].split(",");
var but = $('.tab_head a.current');
url += '/name/'+$.trim(but.text())+'/key/'+but.attr('data-key');
window.location.href = url;
if(but == 'news'){
var str = `时间,新增用户\n`;
var title = "新增用户";
}
if(but == 'active'){
var str = `时间,活跃用户\n`;
var title = "活跃用户";
}
if(but == 'player'){
var str = `时间,付费用户\n`;
var title = "付费用户";
}
for (var i = 0, len = times.length; i < len; ++i) {
str += times[i]+"\t,"+value[i]+"\t\n";
}
var url = 'data:text/csv;charset=utf-8,\ufeff' + encodeURIComponent(str);
downloadCSV(url, title+'.csv');
});
//导出csv
function downloadCSV(url, name) {
// 利用a标签的download属性进行下载
var link = document.createElement("a");
// 设置a标签的属性
link.href = url;
link.download = name || 'work.csv';
// 加入dom树中模拟用户点击并下载
document.body.appendChild(link);
link.click();
// 移除该元素,防泄漏
document.body.removeChild(link);
}
if({$foldline.hours|default=1}==1) {
Highcharts.setOptions({

Loading…
Cancel
Save