import { useMsg } from "./useMsg";

export const useExport = (res: any) => {
    if (!res) {
        useMsg("error", "表格数据为空!");
        return;
    }
    const blob = new Blob([res], { type: "application/vnd.ms-excel" });
    const url: any = URL.createObjectURL(blob);
    const a: any = document.createElement("a");
    a.href = url;
    a.download = localStorage.getItem("filename"); //设置下载文件名;
    document.body.appendChild(a);
    a.click();
    document.body.removeChild(a);
    // 清理 URL 对象，避免内存泄漏
    URL.revokeObjectURL(url);
    // 设置好表格名称后,删除本地存储的表格名称
    localStorage.removeItem("filename");
};
