let downloadFile = (data: any, type: any, fileName: string) => {
    let blob = new Blob([data], {type: `application/${type};`});
    let downloadElement = document.createElement('a');
    let href = window.URL.createObjectURL(blob);
    downloadElement.href = href;
    downloadElement.download = fileName;
    document.body.appendChild(downloadElement);
    downloadElement.click();
    document.body.removeChild(downloadElement);
    window.URL.revokeObjectURL(href);
}

/** 时间格式化 */
let formatDate = (cellValue: any) => {
    if (cellValue == null || cellValue == "") return "";
    var date = new Date(cellValue)
    var year = date.getFullYear()
    var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
    var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
    var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
    var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
    return year + '' + month + '' + day + '' + hours + '' + minutes + '' + seconds
}

let downloadFile1 = (data: any, type: any, fileName: string) => {
    // let blob = new Blob([data], { type: `application/${type};charset=utf-8` });
    let downloadElement = document.createElement('a');
    let href = window.URL.createObjectURL(data);
    downloadElement.href = href;
    downloadElement.download = fileName;
    document.body.appendChild(downloadElement);
    downloadElement.click();
    document.body.removeChild(downloadElement);
    window.URL.revokeObjectURL(href);
}

export {downloadFile, formatDate, downloadFile1}