shawn133-utils
Version:
27 lines (23 loc) • 765 B
text/typescript
export const downLoadFile = (response:any,fileName: string, type: string = 'docx') => {
try {
// 创建一个 URL 对象
const url = window.URL.createObjectURL(new Blob([response]));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', `${fileName}.${type}`); // 设置下载文件的名称
document.body.appendChild(link);
link.click();
// 释放 URL 对象
window.URL.revokeObjectURL(url);
} catch (error) {
console.error('下载文件失败:', error);
}
};
/**
*
* @param value 得到数据类型
*/
export function getType(value: any) {
const type = Object.prototype.toString.call(value)
return type.replace(/(\[)|(\])/g, '').split(' ')[1]
}