260205_01_ENH: 페이지 별 엑셀 다운로드 적용

This commit is contained in:
2026-02-05 09:24:19 +09:00
parent 544f3010aa
commit 3e7c2a98df
25 changed files with 2500 additions and 336 deletions

View File

@@ -7,15 +7,31 @@ import {
TopChartTable,
type TopChartTableRow,
} from "@/components/lge-dashboard";
import { PRODUCT_KEYS, PRODUCTS, YEARS } from "@/const/lgConst";
import { useMemo } from "react";
import { apiOwnShareOfTotalPenetration, apiTrendCategories } from "@/config/sample.data";
import {
LAST_YEAR,
LIFE_STAGE_COLUMNS,
LIFE_STAGE_GROUPS,
PRODUCT_KEY_MAP,
PRODUCT_KEYS,
PRODUCTS,
YEARS
} from "@/const/lgConst";
import {useEffect, useMemo} from "react";
import {apiLifeStageByProduct, apiOwnShareOfTotalPenetration, apiTrendCategories} from "@/config/sample.data";
import LifeStageDiv from "@/components/lge-dashboard/combo/LifeStageDiv";
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
import { formatRowLabel } from "@/lib/lg-dashboard";
import {
buildHeader_LifeStageColumns,
buildHeader_ProductKeyMap,
exportDashboardExcel,
Section
} from "@/lib/lg-export-excel";
import {norm} from "@/lib/utils";
import {LifeStageGroup, LifeStageRow} from "@/types/lg";
const LGPenetrationPage = () => {
const { isTotal, filterValue } = useLayoutFilter();
const { isTotal, filterValue, registerExcelExporter } = useLayoutFilter();
console.log(filterValue);
const productTableRows = useMemo<TopChartTableRow[]>(() => {
@@ -29,7 +45,7 @@ const LGPenetrationPage = () => {
const total: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
const focus: Array<Array<number>> = YEARS.map(() => Array(PRODUCT_KEYS.length).fill(0));
const yearIndexMap = new Map<number, number>(YEARS.map((y, i) => [y, i]));
const yearIndexMap = new Map<string, number>(YEARS.map((y, i) => [y, i]));
const totalRows = apiTrendCategories.filter(
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
@@ -47,8 +63,8 @@ const LGPenetrationPage = () => {
const t = (totalRows[ri] as any)[k];
const v = (r as any)[k];
total[yi][ci] = typeof t === "number" ? t : 0;
focus[yi][ci] = typeof v === "number" ? v : 0;
total[yi][ci] = Number(t);
focus[yi][ci] = Number(v);
}
});
@@ -62,6 +78,61 @@ const LGPenetrationPage = () => {
};
}, []);
const lifeStageRowsByGroup:LifeStageGroup[] = useMemo(() => {
const pick = (label: string) => apiLifeStageByProduct.find((r) => norm(r.rowLabel) === norm(label));
return LIFE_STAGE_GROUPS.map((g) => {
const rows: LifeStageRow[] = g.items.map((label) => {
const r = pick(label);
return {
item: label,
total: r?.total ?? "",
single: r?.single ?? "",
noKids: r?.noKids ?? "",
preschoolKids: r?.preschoolKids ?? "",
schoolKids: r?.schoolKids ?? "",
adultKids: r?.adultKids ?? "",
independentSenior: r?.independentSenior ?? "",
};
});
return { title: g.title, rows };
});
}, []);
useEffect(() => {
registerExcelExporter(async (payload) => {
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
const lifeStageHeader = buildHeader_LifeStageColumns(LIFE_STAGE_COLUMNS);
type AnyRow = Record<string, any>;
const sections: Section<AnyRow>[] = [
{
title: "LG제품 보급률",
header: excelHeader,
rows: apiOwnShareOfTotalPenetration as AnyRow[],
rowGap: 1,
},
...lifeStageRowsByGroup.map((lifeStageRow) => ({
title: lifeStageRow.title,
header: lifeStageHeader,
rows: lifeStageRow.rows as AnyRow[],
rowGap: 1,
})),
];
await exportDashboardExcel({
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(LG제품 보급률).xlsx`,
sheetName: "LG제품 보급률",
sections: sections,
});
});
return () => registerExcelExporter(null);
}, [registerExcelExporter]);
return (
<div>
<TopChartTable
@@ -79,7 +150,7 @@ const LGPenetrationPage = () => {
signStyle={signStyleGapRow}
/>
<LifeStageDiv />
<LifeStageDiv lifeStageRowsByGroup={lifeStageRowsByGroup} />
</div>
);
};