• 前台导出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)+" ");
    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(/&nbsp;/g, '');
    }
    temp.push(recordText.join(','));
    temp.push(value.indexOf(',') >= 0 ? ('"'+value+'"') : value);
    }
    }
    str.push(temp.join(spliter)+" ");
    }

    //  上面是 拼接 字段  下面 是重要内容

    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);
    }

  • 相关阅读:
    堆表修改内幕
    HBase集群安装
    ZooKeeper群集安装
    CentOS 6+Hadoop 2.6.0分布式集群安装
    Hive中使用Python实现Transform时遇到Broken pipe错误排查
    SQL Server审计功能入门:SQL Server审核 (SQL Server Audit)
    SQL Server审计功能入门:CDC(Change Data Capture)
    SQL Server审计功能入门:更改跟踪(Change Tracking)
    Redis 学习笔记(一) 字符串 SDS
    asp.net mvc core 管道以及拦截器初了解
  • 原文地址:https://www.cnblogs.com/stevenzhangcy/p/12582035.html
Copyright © 2020-2023  润新知