260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -2,33 +2,61 @@
|
||||
|
||||
import {useLayoutFilter} from "@/components/layout/LayoutFilterContext";
|
||||
import {
|
||||
apiOwnershipPathByYear,
|
||||
apiOwnershipTriggerByYear,
|
||||
apiPurchaseChannelByYear,
|
||||
apiPurchaseChannelSummaryByYear
|
||||
} from "@/config/sample.data";
|
||||
import {useMemo} from "react";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PageData, ServerBannerRow} from "@/types/lg";
|
||||
import {CategoryByData} from "@/components/lge-dashboard";
|
||||
import {BANNER_GROUP, BANNER_KEY_MAP, LAST_YEAR, YEARS} from "@/const/lgConst";
|
||||
import {CategoryTypeValue} from "@/components/layout/CategoryFilter";
|
||||
import {buildHeader_Banner, exportDashboardExcel, Section} from "@/lib/lg-export-excel";
|
||||
|
||||
const PurchaseChannel = () => {
|
||||
const { filterValue } = useLayoutFilter();
|
||||
const { filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const tableDataArray = useMemo<PageData<ServerBannerRow>[]>(() => [
|
||||
{
|
||||
title: "구매 채널(온/오프라인)",
|
||||
chartMode: "reverseStack",
|
||||
data: apiPurchaseChannelSummaryByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
data: apiPurchaseChannelSummaryByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
|
||||
},
|
||||
{
|
||||
title: "구매 채널(상세)",
|
||||
chartMode: "horizontal",
|
||||
data: apiPurchaseChannelByYear.filter(r => !(r.year === 26 && r.rowLabel === "gap")),
|
||||
data: apiPurchaseChannelByYear.filter(r => !(r.year === LAST_YEAR && r.rowLabel === "gap")),
|
||||
chartHeight: 550,
|
||||
},
|
||||
], []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
|
||||
const sheetName = `${filterValue.product}_${(filterValue.type as CategoryTypeValue).label}_구매 채널`
|
||||
const h3 = buildHeader_Banner(BANNER_GROUP, BANNER_KEY_MAP);
|
||||
|
||||
type AnyRow = Record<string, any>;
|
||||
const sections: Section<AnyRow>[] = tableDataArray.flatMap((tableData) => {
|
||||
const years = [YEARS.at(-1), YEARS.at(-2)];
|
||||
|
||||
return years.map((year) => ({
|
||||
title: `${tableData.title}_${year}년`,
|
||||
header: h3,
|
||||
rows: tableData.data.filter((d) => d.year === year) as AnyRow[],
|
||||
rowGap: 1,
|
||||
}));
|
||||
});
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(${sheetName}).xlsx`,
|
||||
sheetName: sheetName,
|
||||
sections: sections,
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
{tableDataArray.map((tableData) => (
|
||||
|
||||
Reference in New Issue
Block a user