Merge branch 'kwshin-node' of http://39.117.244.52:3000/kjs/ERP-node into jskim-node

This commit is contained in:
kjs
2026-03-31 11:19:55 +09:00
140 changed files with 27511 additions and 9366 deletions
@@ -0,0 +1,133 @@
"use client";
import React, { useState, useEffect, useCallback } from "react";
import { ComponentRendererProps } from "@/types/component";
import { ReportParamMapping, ReportViewerConfig } from "./types";
import { useScreenContextOptional } from "@/contexts/ScreenContext";
import { reportApi } from "@/lib/api/reportApi";
import { ReportMaster } from "@/types/report";
import { ReportListPreviewModal } from "@/components/report/ReportListPreviewModal";
import { FileText, Loader2 } from "lucide-react";
import { Button } from "@/components/ui/button";
/**
* paramMappings가 있으면 명시적 매핑, 없으면 formData 그대로 전달 (휴리스틱 유지)
*/
function buildContextParams(
formData: Record<string, unknown>,
mappings: ReportParamMapping[],
): Record<string, unknown> {
if (mappings.length === 0) return formData;
const result: Record<string, unknown> = {};
for (const { param, formField } of mappings) {
if (param && formField) {
result[param] = formData[formField] ?? null;
}
}
return result;
}
interface ReportViewerComponentProps extends ComponentRendererProps {
config?: ReportViewerConfig;
formData?: Record<string, any>;
}
export const ReportViewerComponent: React.FC<ReportViewerComponentProps> = ({
component,
isDesignMode = false,
formData,
}) => {
const screenContext = useScreenContextOptional();
const menuObjid = screenContext?.menuObjid;
const contextFormData = screenContext?.formData ?? formData ?? {};
const config = (component?.componentConfig ?? component?.overrides ?? {}) as ReportViewerConfig;
const title = config.title || "리포트";
const paramMappings = config.paramMappings ?? [];
const resolvedContextParams = buildContextParams(contextFormData, paramMappings);
const [reports, setReports] = useState<ReportMaster[]>([]);
const [isLoading, setIsLoading] = useState(false);
const [selectedReport, setSelectedReport] = useState<ReportMaster | null>(null);
const fetchReports = useCallback(async () => {
if (!menuObjid) return;
setIsLoading(true);
try {
const res = await reportApi.getReportsByMenuObjid(menuObjid);
if (res.success) setReports(res.data.items);
} catch {
// 실패 시 빈 목록 유지
} finally {
setIsLoading(false);
}
}, [menuObjid]);
useEffect(() => {
if (isDesignMode) return;
fetchReports();
}, [isDesignMode, fetchReports]);
// 디자인 모드: 플레이스홀더
if (isDesignMode) {
return (
<div className="flex h-full w-full flex-col items-center justify-center gap-2 rounded border border-dashed border-blue-300 bg-blue-50 text-blue-600">
<FileText className="h-8 w-8 opacity-60" />
<span className="text-sm font-medium">{title} ( )</span>
<span className="text-xs opacity-60"> </span>
</div>
);
}
// menuObjid 없음
if (!menuObjid) {
return (
<div className="flex h-full w-full items-center justify-center text-sm text-gray-400">
</div>
);
}
if (isLoading) {
return (
<div className="flex h-full w-full items-center justify-center">
<Loader2 className="h-6 w-6 animate-spin text-gray-400" />
</div>
);
}
if (reports.length === 0) {
return (
<div className="flex h-full w-full flex-col items-center justify-center gap-2 text-sm text-gray-400">
<FileText className="h-8 w-8 opacity-30" />
<span> </span>
</div>
);
}
return (
<>
<div className="flex h-full w-full flex-col gap-1 overflow-auto p-2">
{reports.map((report) => (
<Button
key={report.report_id}
variant="outline"
className="w-full justify-start gap-2 text-left text-sm"
onClick={() => setSelectedReport(report)}
>
<FileText className="h-4 w-4 shrink-0 text-blue-500" />
<span className="truncate">{report.report_name_kor}</span>
</Button>
))}
</div>
<ReportListPreviewModal
report={selectedReport}
onClose={() => setSelectedReport(null)}
contextParams={resolvedContextParams}
/>
</>
);
};
@@ -0,0 +1,115 @@
"use client";
import React, { useCallback } from "react";
import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import { Plus, Trash2 } from "lucide-react";
import { ReportParamMapping, ReportViewerConfig } from "./types";
interface ReportViewerConfigPanelProps {
config: ReportViewerConfig;
onChange: (config: Partial<ReportViewerConfig>) => void;
}
export const ReportViewerConfigPanel: React.FC<ReportViewerConfigPanelProps> = ({ config, onChange }) => {
const mappings = config.paramMappings ?? [];
const handleAddMapping = useCallback(() => {
onChange({ paramMappings: [...mappings, { param: "", formField: "" }] });
}, [mappings, onChange]);
const handleRemoveMapping = useCallback(
(index: number) => {
onChange({ paramMappings: mappings.filter((_, i) => i !== index) });
},
[mappings, onChange],
);
const handleMappingChange = useCallback(
(index: number, field: keyof ReportParamMapping, value: string) => {
const updated = mappings.map((m, i) => (i === index ? { ...m, [field]: value } : m));
onChange({ paramMappings: updated });
},
[mappings, onChange],
);
return (
<div className="flex flex-col gap-4 p-4">
{/* 컴포넌트 제목 */}
<div className="flex flex-col gap-1.5">
<Label className="text-xs font-medium text-gray-600"> </Label>
<Input
value={config.title ?? "리포트"}
onChange={(e) => onChange({ title: e.target.value })}
placeholder="리포트"
className="h-8 text-sm"
/>
<p className="text-xs text-gray-400"> .</p>
</div>
{/* 파라미터 매핑 */}
<div className="flex flex-col gap-2">
<div className="flex items-center justify-between">
<Label className="text-xs font-medium text-gray-600"> </Label>
<Button
variant="ghost"
size="sm"
onClick={handleAddMapping}
className="h-6 gap-1 px-2 text-xs text-blue-600 hover:text-blue-700"
>
<Plus className="h-3 w-3" />
</Button>
</div>
{mappings.length === 0 ? (
<p className="text-xs text-gray-400"> .</p>
) : (
<div className="flex flex-col gap-1.5">
<div className="grid grid-cols-[1fr_1fr_auto] gap-1 text-xs text-gray-400">
<span> </span>
<span> </span>
<span />
</div>
{mappings.map((mapping, index) => (
<div key={index} className="grid grid-cols-[1fr_1fr_auto] items-center gap-1">
<Input
value={mapping.param}
onChange={(e) => handleMappingChange(index, "param", e.target.value)}
placeholder="예: $1"
className="h-7 text-xs"
/>
<Input
value={mapping.formField}
onChange={(e) => handleMappingChange(index, "formField", e.target.value)}
placeholder="예: orderId"
className="h-7 text-xs"
/>
<Button
variant="ghost"
size="sm"
onClick={() => handleRemoveMapping(index)}
className="h-7 w-7 p-0 text-gray-400 hover:text-red-500"
>
<Trash2 className="h-3.5 w-3.5" />
</Button>
</div>
))}
</div>
)}
<p className="text-xs text-gray-400">
($1, $2 ) .
</p>
</div>
{/* 안내 */}
<div className="rounded border border-blue-100 bg-blue-50 p-3 text-xs text-blue-600">
.
<br />
.
</div>
</div>
);
};
@@ -0,0 +1,11 @@
"use client";
import { ComponentRegistry } from "@/lib/registry/ComponentRegistry";
import { V2ReportViewerDefinition } from "./index";
// 컴포넌트 자동 등록
if (typeof window !== "undefined") {
ComponentRegistry.registerComponent(V2ReportViewerDefinition);
}
export {};
@@ -0,0 +1,28 @@
"use client";
import { createComponentDefinition } from "../../utils/createComponentDefinition";
import { ComponentCategory } from "@/types/component";
import { ReportViewerComponent } from "./ReportViewerComponent";
import { ReportViewerConfigPanel } from "./ReportViewerConfigPanel";
import type { ReportViewerConfig } from "./types";
export const V2ReportViewerDefinition = createComponentDefinition({
id: "v2-report-viewer",
name: "리포트 뷰어",
nameEng: "Report Viewer",
description: "메뉴에 연결된 리포트 목록을 표시하고 미리보기/PDF 다운로드를 제공하는 컴포넌트",
category: ComponentCategory.DISPLAY,
webType: "text",
component: ReportViewerComponent,
defaultConfig: {
title: "리포트",
} as Partial<ReportViewerConfig>,
defaultSize: { width: 300, height: 200 },
configPanel: ReportViewerConfigPanel as any,
icon: "FileText",
tags: ["리포트", "report", "PDF", "미리보기", "뷰어"],
version: "1.0.0",
author: "개발팀",
});
export type { ReportViewerConfig } from "./types";
@@ -0,0 +1,18 @@
"use client";
import { ComponentConfig } from "@/types/component";
/** 쿼리 파라미터 → formData 필드 명시적 매핑 항목 */
export interface ReportParamMapping {
/** 쿼리 파라미터명 (예: $1, orderNo) */
param: string;
/** formData에서 가져올 필드명 */
formField: string;
}
export interface ReportViewerConfig extends ComponentConfig {
/** 표시할 리포트 목록의 제목 */
title?: string;
/** 파라미터 명시적 매핑 (설정 없으면 휴리스틱 자동 매핑) */
paramMappings?: ReportParamMapping[];
}