前台导出csv
function(fileName,spliter,record){
var me = this.__portal.componentItemMap.tablepanel;
spliter = spliter || ',';
var headers = [];
headers.push('上报时间,设备串号,开始时间,结束时间,节目播放地址,失败类型');
for (var j = 0; j < me.tableColumns.length; j ++) {
var columnItem = me.tableColumns[j];
if (columnItem._columnType != 'checkbox' && columnItem._columnType != 'flex' && !columnItem.hidden) {
headers.push(columnItem.title);
}
}
var str = [],recordText = [],type = '';
switch (record.failPlayInfoList.type) {
case 1:
type = '视频播放出第一帧,但超过成功约束时间';
break;
case 2:
type = '视频播放未出第一帧,但超过成功约束时间';
break;
case 3:
type = '视频播放未出第一帧,其未超过成功约束时间,m3u8或者ts http请求';
break;
}
recordText = [
$nps$.utils.dateTimeRenderer(record.reportTime,'Y-m-d H:i:s'),
record.deviceId,
$nps$.utils.dateTimeRenderer(record.failPlayInfoList.startTime,'Y-m-d H:i:s'),
$nps$.utils.dateTimeRenderer(record.failPlayInfoList.endTime,'Y-m-d H:i:s'),
record.failPlayInfoList.programUrl,
type,
];
str.push(headers.join(spliter)+"\n");
for (var i = 0; i < me.sourceResults.length; i ++) {
var dataItem = me.sourceResults[i];
var temp = [];
for (var j = 0; j < me.tableColumns.length; j ++) {
var columnItem = me.tableColumns[j];
if (columnItem._columnType != 'checkbox' && columnItem._columnType != 'flex' && !columnItem.hidden) {
if (columnItem._columnType == 'rowNumber') {
value = i+1;
} else {
if (columnItem.type == 'html') {
value = dataItem[columnItem.dataIndex];
} else {
value = me._renderCell(columnItem, dataItem, i, j);
}
}
if (value === null || value === undefined) {
value = '';
} else {
value = (value+'').replace(/"/g, '""').replace(/ /g, '');
}
temp.push(recordText.join(','));
temp.push(value.indexOf(',') >= 0 ? ('"'+value+'"') : value);
}
}
str.push(temp.join(spliter)+"\n");
}
// 上面是 拼接 字段 下面 是重要内容
var uri = 'data:text/csv;charset=utf-8,%EF%BB%BF' + encodeURIComponent(str.join(""));
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = (fileName || me.header.title)+".csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}