working version

dev
timofejmalinin 4 years ago
parent 93832a7788
commit c82cecef34

@ -8,79 +8,79 @@ import { GridSizeSelect } from "./GridSizeSelect";
import { ModelSelect } from "./ModelSelect"; import { ModelSelect } from "./ModelSelect";
import { Settings } from "./Settings"; import { Settings } from "./Settings";
const activeTablesMapper = { // const activeTablesMapper = {
net_3: ["point3", "net_3"], // net_3: ["point3", "net_3"],
net_4: ["point4", "net_4"], // net_4: ["point4", "net_4"],
net_5: ["point5", "net_5"], // net_5: ["point5", "net_5"],
}; // };
function download(filename, data) { // function download(filename, data) {
const link = document.createElement("a"); // const link = document.createElement("a");
link.href = // link.href =
"data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," + // "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64," +
encodeURIComponent(data); // encodeURIComponent(data);
link.setAttribute("download", filename); // link.setAttribute("download", filename);
//
link.style.display = "none"; // link.style.display = "none";
document.body.appendChild(link); // document.body.appendChild(link);
//
link.click(); // link.click();
//
document.body.removeChild(link); // document.body.removeChild(link);
} // }
const getRegionParam = (regionId) => { // const getRegionParam = (regionId) => {
if (!regionId) return null; // if (!regionId) return null;
//
const [type, id] = regionId.split("-"); // const [type, id] = regionId.split("-");
//
if (type === "ao") { // if (type === "ao") {
return { msk_ao: Number(id) }; // return { msk_ao: Number(id) };
} // }
//
return { msk_rayon: Number(id) }; // return { msk_rayon: Number(id) };
}; // };
export const Sidebar = () => { export const Sidebar = () => {
const { factors } = useFactors(); // const { factors } = useFactors();
const { activeTypes } = useActiveTypes(); // const { activeTypes } = useActiveTypes();
const { region } = useRegion(); // const { region } = useRegion();
const { gridSize } = useGridSize(); // const { gridSize } = useGridSize();
//
const handleExport = async () => { // const handleExport = async () => {
const params = { // const params = {
koefs: factors, // koefs: factors,
tables: activeTablesMapper[gridSize], // tables: activeTablesMapper[gridSize],
}; // };
//
if (region) { // if (region) {
params.filters = { // params.filters = {
...params.filters, // ...params.filters,
...getRegionParam(region), // ...getRegionParam(region),
}; // };
} // }
//
if (activeTypes.length) { // if (activeTypes.length) {
params.filters = { // params.filters = {
...params.filters, // ...params.filters,
category: activeTypes, // category: activeTypes,
}; // };
} // }
//
const resp = await api.post("/api/raschet/", params); // const resp = await api.post("/api/raschet/", params);
const blob = resp.data; // const blob = resp.data;
//
const downloadLink = window.document.createElement("a"); // const downloadLink = window.document.createElement("a");
downloadLink.href = window.URL.createObjectURL( // downloadLink.href = window.URL.createObjectURL(
new Blob([blob], { // new Blob([blob], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", // type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
}) // })
); // );
downloadLink.download = "postamates.xlsx"; // downloadLink.download = "postamates.xlsx";
document.body.appendChild(downloadLink); // document.body.appendChild(downloadLink);
downloadLink.click(); // downloadLink.click();
document.body.removeChild(downloadLink); // document.body.removeChild(downloadLink);
}; // };
return ( return (
<div className="absolute top-[20px] right-[20px] bg-white-background w-[300px] rounded-xl p-3 max-h-[calc(100vh-40px)] overflow-y-auto z-10"> <div className="absolute top-[20px] right-[20px] bg-white-background w-[300px] rounded-xl p-3 max-h-[calc(100vh-40px)] overflow-y-auto z-10">

Loading…
Cancel
Save