260205_01_ENH: 페이지 별 엑셀 다운로드 적용
This commit is contained in:
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,9 +19,10 @@ import {
|
||||
PRODUCTS,
|
||||
YEARS,
|
||||
AXIS_HIDE_STYLE,
|
||||
GRID_X_NOT_PADDING,
|
||||
GRID_X_NOT_PADDING, PRODUCT_KEY_MAP, LAST_YEAR,
|
||||
} from "@/const/lgConst";
|
||||
import { formatRowLabel } from "@/lib/lg-dashboard";
|
||||
import {buildHeader_ProductKeyMap, exportDashboardExcel} from "@/lib/lg-export-excel";
|
||||
|
||||
const PenetrationPage = () => {
|
||||
const { isTotal, filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
@@ -73,7 +74,15 @@ const PenetrationPage = () => {
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
// TODO: export
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(보급률).xlsx`,
|
||||
sheetName: "전체 보급률",
|
||||
sections: [
|
||||
{ title: "전체 보급률", header: excelHeader, rows: apiTrendCategories, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useMemo } from "react";
|
||||
import { PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING } from "@/const/lgConst";
|
||||
import {useEffect, useMemo} from "react";
|
||||
import {PRODUCT_KEYS, PRODUCTS, AXIS_HIDE_STYLE, GRID_X_NOT_PADDING, LAST_YEAR, PRODUCT_KEY_MAP} from "@/const/lgConst";
|
||||
import {
|
||||
type ChartData,
|
||||
signStyleGapRow,
|
||||
@@ -12,9 +12,10 @@ import {
|
||||
import { 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 PurchasePage = () => {
|
||||
const { isTotal, filterValue } = useLayoutFilter();
|
||||
const { isTotal, filterValue, registerExcelExporter } = useLayoutFilter();
|
||||
console.log(filterValue);
|
||||
|
||||
const purchaseTableRows = useMemo<TopChartTableRow[]>(() => {
|
||||
@@ -36,6 +37,21 @@ const PurchasePage = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
registerExcelExporter(async (payload) => {
|
||||
const excelHeader = buildHeader_ProductKeyMap(PRODUCT_KEY_MAP);
|
||||
|
||||
await exportDashboardExcel({
|
||||
fileName: `20${LAST_YEAR}년도 가전 보급률 Dashboard(구매율).xlsx`,
|
||||
sheetName: "구매율",
|
||||
sections: [
|
||||
{ title: "구매율", header: excelHeader, rows: apiTrendBuy, rowGap: 1 },
|
||||
],
|
||||
});
|
||||
});
|
||||
return () => registerExcelExporter(null);
|
||||
}, [registerExcelExporter]);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<TopChartTable
|
||||
|
||||
@@ -14,11 +14,15 @@ export async function POST(
|
||||
|
||||
const [userId] = slug;
|
||||
|
||||
/*
|
||||
서버 로그아웃 할 필요 없음
|
||||
const url = userId
|
||||
? `/auth/logout/${encodeURIComponent(userId)}`
|
||||
: "/auth/logout/";
|
||||
|
||||
//await backApi.post<boolean>(url);
|
||||
await backApi.post<boolean>(url);
|
||||
*/
|
||||
|
||||
const res = NextResponse.json({ ok: true });
|
||||
|
||||
res.cookies.set("access_token", "", {
|
||||
|
||||
Reference in New Issue
Block a user