1. /**
    2. * @description[exportFile 导出文件]
    3. * @author zoumiao
    4. * @param {Object} data [blob数据]
    5. * @param {String} title [文件名称]
    6. * @returns {null} [没有返回]
    7. */
    8. export const exportFile = function (data, title) {
    9. let type = data.type
    10. const relType = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
    11. if (type.includes('application/json')) {
    12. let reader = new FileReader()
    13. reader.onload = function (event) {
    14. let content = reader.result
    15. let message = JSON.parse(content).message // 错误信息
    16. // TODO 错误处理
    17. }
    18. reader.readAsText(data)
    19. return true
    20. }
    21. if (relType.includes(type)) {
    22. let url = window.URL.createObjectURL(new Blob([data]))
    23. let link = document.createElement('a')
    24. link.style.display = 'none'
    25. link.href = url
    26. link.setAttribute('download', title)
    27. document.body.appendChild(link)
    28. link.click()
    29. return true
    30. }
    31. // TODO 其他数据异常处理
    32. }