260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { PRODUCT_KEYS, PRODUCTS, YEARS } from "@/const/lgConst";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {LAST_YEAR, PRODUCT_KEY_MAP, PRODUCT_KEYS, PRODUCTS, YEARS} from "@/const/lgConst";
|
||||
import {
|
||||
GroupedOverlayBar,
|
||||
type GroupedOverlayBarData,
|
||||
@@ -12,9 +12,10 @@ import {
|
||||
import { apiOwnShareOfTotalPurchase, apiTrendBuy } from "@/config/sample.data";
|
||||
import { useLayoutFilter } from "@/components/layout/LayoutFilterContext";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
|
||||
const LGPurchasePage = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const { isTotal, filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -28,7 +29,7 @@ const LGPurchasePage = () => {
|
||||
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 = apiTrendBuy.filter(
|
||||
(r) => YEARS.includes(r.year as any) && r.rowLabel.endsWith("년")
|
||||
@@ -47,8 +48,8 @@ const LGPurchasePage = () => {
|
||||
const v = (r as any)[k];
|
||||
|
||||
// total은 t 기준으로 체크해야 안전
|
||||
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 +63,21 @@ const LGPurchasePage = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(LG제품 구매율).xlsx`,
|
||||
sheetName: "LG제품 구매율",
|
||||
sections: [
|
||||
{ title: "LG제품 구매율", header: excelHeader, rows: apiOwnShareOfTotalPurchase, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TopChartTable
|
||||
|
||||
Reference in New Issue
Block a user