2025-09-01 18:42:59 +09:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
import React, { useState, useCallback, useEffect, useMemo } from "react";
|
2025-09-01 18:42:59 +09:00
|
|
|
|
import { Input } from "@/components/ui/input";
|
|
|
|
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
|
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
|
|
|
|
|
import { Calendar } from "@/components/ui/calendar";
|
|
|
|
|
|
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
|
2025-12-05 10:46:10 +09:00
|
|
|
|
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
2025-12-10 13:53:44 +09:00
|
|
|
|
import { CalendarIcon, File, Upload, X, Loader2 } from "lucide-react";
|
2025-09-01 18:42:59 +09:00
|
|
|
|
import { format } from "date-fns";
|
|
|
|
|
|
import { ko } from "date-fns/locale";
|
2025-09-04 18:36:40 +09:00
|
|
|
|
import { useAuth } from "@/hooks/useAuth";
|
2025-09-05 12:04:13 +09:00
|
|
|
|
import { uploadFilesAndCreateData } from "@/lib/api/file";
|
|
|
|
|
|
import { toast } from "sonner";
|
2025-12-10 13:53:44 +09:00
|
|
|
|
import { useCascadingDropdown } from "@/hooks/useCascadingDropdown";
|
|
|
|
|
|
import { CascadingDropdownConfig } from "@/types/screen-management";
|
2025-09-03 11:50:42 +09:00
|
|
|
|
import {
|
|
|
|
|
|
ComponentData,
|
|
|
|
|
|
WidgetComponent,
|
2025-09-03 15:23:12 +09:00
|
|
|
|
DataTableComponent,
|
2025-09-05 21:52:19 +09:00
|
|
|
|
FileComponent,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
TextTypeConfig,
|
|
|
|
|
|
NumberTypeConfig,
|
|
|
|
|
|
DateTypeConfig,
|
|
|
|
|
|
SelectTypeConfig,
|
|
|
|
|
|
RadioTypeConfig,
|
|
|
|
|
|
CheckboxTypeConfig,
|
|
|
|
|
|
TextareaTypeConfig,
|
|
|
|
|
|
FileTypeConfig,
|
|
|
|
|
|
CodeTypeConfig,
|
|
|
|
|
|
EntityTypeConfig,
|
2025-09-04 11:33:52 +09:00
|
|
|
|
ButtonTypeConfig,
|
2025-09-19 18:43:55 +09:00
|
|
|
|
} from "@/types";
|
2025-09-03 15:23:12 +09:00
|
|
|
|
import { InteractiveDataTable } from "./InteractiveDataTable";
|
2025-09-05 21:52:19 +09:00
|
|
|
|
import { FileUpload } from "./widgets/FileUpload";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
import { dynamicFormApi, DynamicFormData } from "@/lib/api/dynamicForm";
|
|
|
|
|
|
import { useParams } from "next/navigation";
|
2025-11-04 14:33:39 +09:00
|
|
|
|
import { screenApi, tableTypeApi } from "@/lib/api/screen";
|
2025-09-19 02:15:21 +09:00
|
|
|
|
import { DynamicWebTypeRenderer } from "@/lib/registry/DynamicWebTypeRenderer";
|
2025-09-19 18:43:55 +09:00
|
|
|
|
import { enhancedFormService } from "@/lib/services/enhancedFormService";
|
|
|
|
|
|
import { FormValidationIndicator } from "@/components/common/FormValidationIndicator";
|
|
|
|
|
|
import { useFormValidation } from "@/hooks/useFormValidation";
|
|
|
|
|
|
import { UnifiedColumnInfo as ColumnInfo } from "@/types";
|
2025-09-29 13:29:03 +09:00
|
|
|
|
import { isFileComponent } from "@/lib/utils/componentTypeUtils";
|
2025-10-13 18:28:03 +09:00
|
|
|
|
import { buildGridClasses } from "@/lib/constants/columnSpans";
|
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2025-10-28 15:39:22 +09:00
|
|
|
|
import { useScreenPreview } from "@/contexts/ScreenPreviewContext";
|
2026-01-14 15:33:57 +09:00
|
|
|
|
import { useMultiLang } from "@/hooks/useMultiLang";
|
2025-11-12 10:48:24 +09:00
|
|
|
|
import { TableOptionsProvider } from "@/contexts/TableOptionsContext";
|
|
|
|
|
|
import { TableOptionsToolbar } from "./table-options/TableOptionsToolbar";
|
2025-12-11 18:40:39 +09:00
|
|
|
|
import { SplitPanelProvider } from "@/lib/registry/components/split-panel-layout/SplitPanelContext";
|
2025-12-17 15:00:15 +09:00
|
|
|
|
import { ActiveTabProvider } from "@/contexts/ActiveTabContext";
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
/**
|
|
|
|
|
|
* 🔗 연쇄 드롭다운 래퍼 컴포넌트
|
|
|
|
|
|
* InteractiveScreenViewer 내에서 사용
|
|
|
|
|
|
*/
|
|
|
|
|
|
interface CascadingDropdownWrapperProps {
|
|
|
|
|
|
/** 직접 설정 방식 */
|
|
|
|
|
|
config?: CascadingDropdownConfig;
|
|
|
|
|
|
/** 공통 관리 방식 (관계 코드) */
|
|
|
|
|
|
relationCode?: string;
|
|
|
|
|
|
/** 부모 필드명 (relationCode 사용 시 필요) */
|
|
|
|
|
|
parentFieldName?: string;
|
|
|
|
|
|
parentValue?: string | number | null;
|
|
|
|
|
|
value?: string;
|
|
|
|
|
|
onChange?: (value: string) => void;
|
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
|
disabled?: boolean;
|
|
|
|
|
|
required?: boolean;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const CascadingDropdownWrapper: React.FC<CascadingDropdownWrapperProps> = ({
|
|
|
|
|
|
config,
|
|
|
|
|
|
relationCode,
|
|
|
|
|
|
parentFieldName,
|
|
|
|
|
|
parentValue,
|
|
|
|
|
|
value,
|
|
|
|
|
|
onChange,
|
|
|
|
|
|
placeholder,
|
|
|
|
|
|
disabled,
|
|
|
|
|
|
required,
|
|
|
|
|
|
}) => {
|
|
|
|
|
|
const { options, loading, error, relationConfig } = useCascadingDropdown({
|
|
|
|
|
|
config,
|
|
|
|
|
|
relationCode,
|
|
|
|
|
|
parentValue,
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
// 실제 사용할 설정 (직접 설정 또는 API에서 가져온 설정)
|
|
|
|
|
|
const effectiveConfig = config || relationConfig;
|
|
|
|
|
|
|
|
|
|
|
|
// 부모 값이 없을 때 메시지
|
|
|
|
|
|
const getPlaceholder = () => {
|
|
|
|
|
|
if (!parentValue) {
|
|
|
|
|
|
return effectiveConfig?.emptyParentMessage || "상위 항목을 먼저 선택하세요";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (loading) {
|
|
|
|
|
|
return effectiveConfig?.loadingMessage || "로딩 중...";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (options.length === 0) {
|
|
|
|
|
|
return effectiveConfig?.noOptionsMessage || "선택 가능한 항목이 없습니다";
|
|
|
|
|
|
}
|
|
|
|
|
|
return placeholder || "선택하세요";
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const isDisabled = disabled || !parentValue || loading;
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<Select value={value || ""} onValueChange={(newValue) => onChange?.(newValue)} disabled={isDisabled}>
|
2025-12-10 13:53:44 +09:00
|
|
|
|
<SelectTrigger className="h-full w-full">
|
|
|
|
|
|
{loading ? (
|
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
|
<Loader2 className="h-4 w-4 animate-spin" />
|
|
|
|
|
|
<span className="text-muted-foreground text-sm">로딩 중...</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<SelectValue placeholder={getPlaceholder()} />
|
|
|
|
|
|
)}
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
{options.length === 0 ? (
|
|
|
|
|
|
<div className="text-muted-foreground px-2 py-4 text-center text-sm">
|
|
|
|
|
|
{!parentValue
|
|
|
|
|
|
? config.emptyParentMessage || "상위 항목을 먼저 선택하세요"
|
|
|
|
|
|
: config.noOptionsMessage || "선택 가능한 항목이 없습니다"}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
options.map((option) => (
|
|
|
|
|
|
<SelectItem key={option.value} value={option.value}>
|
|
|
|
|
|
{option.label}
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
))
|
|
|
|
|
|
)}
|
|
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
interface InteractiveScreenViewerProps {
|
|
|
|
|
|
component: ComponentData;
|
|
|
|
|
|
allComponents: ComponentData[];
|
|
|
|
|
|
formData?: Record<string, any>;
|
|
|
|
|
|
onFormDataChange?: (fieldName: string, value: any) => void;
|
2025-09-04 11:33:52 +09:00
|
|
|
|
hideLabel?: boolean;
|
2025-09-04 14:23:35 +09:00
|
|
|
|
screenInfo?: {
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
tableName?: string;
|
|
|
|
|
|
};
|
2025-11-11 15:25:07 +09:00
|
|
|
|
menuObjid?: number; // 🆕 메뉴 OBJID (코드 스코프용)
|
2025-09-19 18:43:55 +09:00
|
|
|
|
// 새로운 검증 관련 옵션들
|
|
|
|
|
|
enableEnhancedValidation?: boolean;
|
|
|
|
|
|
tableColumns?: ColumnInfo[];
|
|
|
|
|
|
showValidationPanel?: boolean;
|
|
|
|
|
|
validationOptions?: {
|
|
|
|
|
|
enableRealTimeValidation?: boolean;
|
|
|
|
|
|
validationDelay?: number;
|
|
|
|
|
|
enableAutoSave?: boolean;
|
|
|
|
|
|
showToastMessages?: boolean;
|
|
|
|
|
|
};
|
2025-09-01 18:42:59 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export const InteractiveScreenViewer: React.FC<InteractiveScreenViewerProps> = ({
|
|
|
|
|
|
component,
|
|
|
|
|
|
allComponents,
|
|
|
|
|
|
formData: externalFormData,
|
|
|
|
|
|
onFormDataChange,
|
2025-09-04 11:33:52 +09:00
|
|
|
|
hideLabel = false,
|
2025-09-04 14:23:35 +09:00
|
|
|
|
screenInfo,
|
2025-11-11 15:25:07 +09:00
|
|
|
|
menuObjid, // 🆕 메뉴 OBJID
|
2025-09-19 18:43:55 +09:00
|
|
|
|
enableEnhancedValidation = false,
|
|
|
|
|
|
tableColumns = [],
|
|
|
|
|
|
showValidationPanel = false,
|
|
|
|
|
|
validationOptions = {},
|
2025-09-01 18:42:59 +09:00
|
|
|
|
}) => {
|
2025-10-15 18:31:40 +09:00
|
|
|
|
// component가 없으면 빈 div 반환
|
|
|
|
|
|
if (!component) {
|
|
|
|
|
|
console.warn("⚠️ InteractiveScreenViewer: component가 undefined입니다.");
|
|
|
|
|
|
return <div className="h-full w-full" />;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-28 15:39:22 +09:00
|
|
|
|
const { isPreviewMode } = useScreenPreview(); // 프리뷰 모드 확인
|
2025-09-05 21:52:19 +09:00
|
|
|
|
const { userName, user } = useAuth(); // 현재 로그인한 사용자명과 사용자 정보 가져오기
|
2026-01-14 15:33:57 +09:00
|
|
|
|
const { userLang } = useMultiLang(); // 다국어 훅
|
2025-09-01 18:42:59 +09:00
|
|
|
|
const [localFormData, setLocalFormData] = useState<Record<string, any>>({});
|
|
|
|
|
|
const [dateValues, setDateValues] = useState<Record<string, Date | undefined>>({});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
// 다국어 번역 상태 (langKeyId가 있는 컴포넌트들의 번역 텍스트)
|
|
|
|
|
|
const [translations, setTranslations] = useState<Record<string, string>>({});
|
|
|
|
|
|
|
|
|
|
|
|
// 다국어 키 수집 및 번역 로드
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
const loadTranslations = async () => {
|
|
|
|
|
|
// 모든 컴포넌트에서 langKey 수집
|
|
|
|
|
|
const langKeysToFetch: string[] = [];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
const collectLangKeys = (comps: ComponentData[]) => {
|
|
|
|
|
|
comps.forEach((comp) => {
|
|
|
|
|
|
// 컴포넌트 라벨의 langKey
|
|
|
|
|
|
if ((comp as any).langKey) {
|
|
|
|
|
|
langKeysToFetch.push((comp as any).langKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
// componentConfig 내의 langKey (버튼 텍스트 등)
|
|
|
|
|
|
if ((comp as any).componentConfig?.langKey) {
|
|
|
|
|
|
langKeysToFetch.push((comp as any).componentConfig.langKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
// 자식 컴포넌트 재귀 처리
|
|
|
|
|
|
if ((comp as any).children) {
|
|
|
|
|
|
collectLangKeys((comp as any).children);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
collectLangKeys(allComponents);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
// langKey가 있으면 배치 조회
|
|
|
|
|
|
if (langKeysToFetch.length > 0 && userLang) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { apiClient } = await import("@/lib/api/client");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const response = await apiClient.post(
|
|
|
|
|
|
"/multilang/batch",
|
|
|
|
|
|
{
|
|
|
|
|
|
langKeys: [...new Set(langKeysToFetch)], // 중복 제거
|
2026-01-14 15:33:57 +09:00
|
|
|
|
},
|
2026-01-14 15:38:52 +09:00
|
|
|
|
{
|
|
|
|
|
|
params: {
|
|
|
|
|
|
userLang,
|
|
|
|
|
|
companyCode: user?.companyCode || "*",
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
if (response.data?.success && response.data?.data) {
|
|
|
|
|
|
setTranslations(response.data.data);
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("다국어 번역 로드 실패:", error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
loadTranslations();
|
|
|
|
|
|
}, [allComponents, userLang, user?.companyCode]);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 15:20:26 +09:00
|
|
|
|
// 팝업 화면 상태
|
|
|
|
|
|
const [popupScreen, setPopupScreen] = useState<{
|
|
|
|
|
|
screenId: number;
|
|
|
|
|
|
title: string;
|
|
|
|
|
|
size: string;
|
|
|
|
|
|
} | null>(null);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 15:20:26 +09:00
|
|
|
|
// 팝업 화면 레이아웃 상태
|
|
|
|
|
|
const [popupLayout, setPopupLayout] = useState<ComponentData[]>([]);
|
|
|
|
|
|
const [popupLoading, setPopupLoading] = useState(false);
|
2025-09-04 17:01:07 +09:00
|
|
|
|
const [popupScreenResolution, setPopupScreenResolution] = useState<{ width: number; height: number } | null>(null);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const [popupScreenInfo, setPopupScreenInfo] = useState<{ id: number; tableName?: string } | null>(null);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 팝업 전용 formData 상태
|
|
|
|
|
|
const [popupFormData, setPopupFormData] = useState<Record<string, any>>({});
|
|
|
|
|
|
|
2025-09-19 18:43:55 +09:00
|
|
|
|
// 통합된 폼 데이터
|
|
|
|
|
|
const finalFormData = { ...localFormData, ...externalFormData };
|
|
|
|
|
|
|
|
|
|
|
|
// 개선된 검증 시스템 (선택적 활성화)
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const enhancedValidation =
|
|
|
|
|
|
enableEnhancedValidation && screenInfo && tableColumns.length > 0
|
|
|
|
|
|
? useFormValidation(
|
|
|
|
|
|
finalFormData,
|
|
|
|
|
|
allComponents.filter((c) => c.type === "widget") as WidgetComponent[],
|
|
|
|
|
|
tableColumns,
|
|
|
|
|
|
{
|
|
|
|
|
|
id: screenInfo.id,
|
|
|
|
|
|
screenName: screenInfo.tableName || "unknown",
|
|
|
|
|
|
tableName: screenInfo.tableName,
|
|
|
|
|
|
screenResolution: { width: 800, height: 600 },
|
|
|
|
|
|
gridSettings: { size: 20, color: "#e0e0e0", opacity: 0.5 },
|
|
|
|
|
|
description: "동적 화면",
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
enableRealTimeValidation: true,
|
|
|
|
|
|
validationDelay: 300,
|
|
|
|
|
|
enableAutoSave: false,
|
|
|
|
|
|
showToastMessages: true,
|
|
|
|
|
|
...validationOptions,
|
|
|
|
|
|
},
|
|
|
|
|
|
)
|
|
|
|
|
|
: null;
|
2025-09-19 18:43:55 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 자동값 생성 함수
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const generateAutoValue = useCallback(
|
|
|
|
|
|
async (autoValueType: string, ruleId?: string): Promise<string> => {
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
|
switch (autoValueType) {
|
|
|
|
|
|
case "current_datetime":
|
|
|
|
|
|
return now.toISOString().slice(0, 19).replace("T", " "); // YYYY-MM-DD HH:mm:ss
|
|
|
|
|
|
case "current_date":
|
|
|
|
|
|
return now.toISOString().slice(0, 10); // YYYY-MM-DD
|
|
|
|
|
|
case "current_time":
|
|
|
|
|
|
return now.toTimeString().slice(0, 8); // HH:mm:ss
|
|
|
|
|
|
case "current_user":
|
|
|
|
|
|
// 실제 접속중인 사용자명 사용
|
|
|
|
|
|
return userName || "사용자"; // 사용자명이 없으면 기본값
|
|
|
|
|
|
case "uuid":
|
|
|
|
|
|
return crypto.randomUUID();
|
|
|
|
|
|
case "sequence":
|
|
|
|
|
|
return `SEQ_${Date.now()}`;
|
|
|
|
|
|
case "numbering_rule":
|
|
|
|
|
|
// 채번 규칙 사용
|
|
|
|
|
|
if (ruleId) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const { generateNumberingCode } = await import("@/lib/api/numberingRule");
|
|
|
|
|
|
const response = await generateNumberingCode(ruleId);
|
|
|
|
|
|
if (response.success && response.data) {
|
|
|
|
|
|
return response.data.generatedCode;
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error("채번 규칙 코드 생성 실패:", error);
|
2025-11-04 17:35:02 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
return "";
|
|
|
|
|
|
default:
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
[userName],
|
|
|
|
|
|
); // userName 의존성 추가
|
2025-09-04 15:20:26 +09:00
|
|
|
|
|
|
|
|
|
|
// 팝업 화면 레이아웃 로드
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
|
if (popupScreen) {
|
|
|
|
|
|
const loadPopupLayout = async () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
setPopupLoading(true);
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔍 팝업 화면 로드 시작:", popupScreen);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 화면 레이아웃과 화면 정보를 병렬로 가져오기
|
|
|
|
|
|
const [layout, screen] = await Promise.all([
|
|
|
|
|
|
screenApi.getLayout(popupScreen.screenId),
|
2026-01-14 15:38:52 +09:00
|
|
|
|
screenApi.getScreen(popupScreen.screenId),
|
2025-09-04 18:36:40 +09:00
|
|
|
|
]);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log("📊 팝업 화면 로드 완료:", {
|
2025-09-04 17:01:07 +09:00
|
|
|
|
componentsCount: layout.components?.length || 0,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
screenInfo: {
|
|
|
|
|
|
screenId: screen.screenId,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
tableName: screen.tableName,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
},
|
2026-01-14 15:38:52 +09:00
|
|
|
|
popupFormData: {},
|
2025-09-04 17:01:07 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 15:20:26 +09:00
|
|
|
|
setPopupLayout(layout.components || []);
|
2025-09-04 17:01:07 +09:00
|
|
|
|
setPopupScreenResolution(layout.screenResolution || null);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
setPopupScreenInfo({
|
|
|
|
|
|
id: popupScreen.screenId,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
tableName: screen.tableName,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 팝업 formData 초기화
|
|
|
|
|
|
setPopupFormData({});
|
2025-09-04 15:20:26 +09:00
|
|
|
|
} catch (error) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error("❌ 팝업 화면 로드 실패:", error);
|
2025-09-04 15:20:26 +09:00
|
|
|
|
setPopupLayout([]);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
setPopupScreenInfo(null);
|
2025-09-04 15:20:26 +09:00
|
|
|
|
} finally {
|
|
|
|
|
|
setPopupLoading(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 15:20:26 +09:00
|
|
|
|
loadPopupLayout();
|
|
|
|
|
|
}
|
|
|
|
|
|
}, [popupScreen]);
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 실제 사용할 폼 데이터 (외부와 로컬 데이터 병합)
|
|
|
|
|
|
const formData = { ...localFormData, ...externalFormData };
|
|
|
|
|
|
console.log("🔄 formData 구성:", {
|
|
|
|
|
|
external: externalFormData,
|
|
|
|
|
|
local: localFormData,
|
|
|
|
|
|
merged: formData,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
hasExternalCallback: !!onFormDataChange,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
// 폼 데이터 업데이트
|
|
|
|
|
|
const updateFormData = (fieldName: string, value: any) => {
|
2025-10-28 15:39:22 +09:00
|
|
|
|
// 프리뷰 모드에서는 데이터 업데이트 하지 않음
|
|
|
|
|
|
if (isPreviewMode) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`🔄 updateFormData: ${fieldName} = "${value}" (외부콜백: ${!!onFormDataChange})`);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 항상 로컬 상태도 업데이트
|
|
|
|
|
|
setLocalFormData((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[fieldName]: value,
|
|
|
|
|
|
}));
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`💾 로컬 상태 업데이트: ${fieldName} = "${value}"`);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-18 10:05:50 +09:00
|
|
|
|
// 외부 콜백이 있는 경우에도 전달 (개별 필드 단위로)
|
2025-09-01 18:42:59 +09:00
|
|
|
|
if (onFormDataChange) {
|
2025-09-18 10:05:50 +09:00
|
|
|
|
onFormDataChange(fieldName, value);
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`📤 외부 콜백으로 전달: ${fieldName} = "${value}"`);
|
2025-09-01 18:42:59 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 자동입력 필드들의 값을 formData에 초기 설정
|
|
|
|
|
|
React.useEffect(() => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🚀 자동입력 초기화 useEffect 실행 - allComponents 개수:", allComponents.length);
|
2025-11-04 14:33:39 +09:00
|
|
|
|
const initAutoInputFields = async () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔧 initAutoInputFields 실행 시작");
|
2025-11-04 14:33:39 +09:00
|
|
|
|
for (const comp of allComponents) {
|
|
|
|
|
|
// 🆕 type: "component" 또는 type: "widget" 모두 처리
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (comp.type === "widget" || comp.type === "component") {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
// 🆕 autoFill 처리 (테이블 조회 기반 자동 입력)
|
|
|
|
|
|
if (widget.autoFill?.enabled || (comp as any).autoFill?.enabled) {
|
|
|
|
|
|
const autoFillConfig = widget.autoFill || (comp as any).autoFill;
|
|
|
|
|
|
const currentValue = formData[fieldName];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (currentValue === undefined || currentValue === "") {
|
2025-11-04 14:33:39 +09:00
|
|
|
|
const { sourceTable, filterColumn, userField, displayColumn } = autoFillConfig;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
// 사용자 정보에서 필터 값 가져오기
|
|
|
|
|
|
const userValue = user?.[userField];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
if (userValue && sourceTable && filterColumn && displayColumn) {
|
|
|
|
|
|
try {
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const result = await tableTypeApi.getTableRecord(sourceTable, filterColumn, userValue, displayColumn);
|
|
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
updateFormData(fieldName, result.value);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error(`autoFill 조회 실패: ${fieldName}`, error);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
continue; // autoFill이 활성화되면 일반 자동입력은 건너뜀
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
// 기존 widget 타입 전용 로직은 widget인 경우만
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (comp.type !== "widget") continue;
|
|
|
|
|
|
|
2025-11-04 14:33:39 +09:00
|
|
|
|
// 텍스트 타입 위젯의 자동입력 처리 (기존 로직)
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (
|
|
|
|
|
|
(widget.widgetType === "text" || widget.widgetType === "email" || widget.widgetType === "tel") &&
|
|
|
|
|
|
widget.webTypeConfig
|
|
|
|
|
|
) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const config = widget.webTypeConfig as TextTypeConfig;
|
|
|
|
|
|
const isAutoInput = config?.autoInput || false;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (isAutoInput && config?.autoValueType) {
|
|
|
|
|
|
// 이미 값이 있으면 덮어쓰지 않음
|
|
|
|
|
|
const currentValue = formData[fieldName];
|
|
|
|
|
|
console.log(`🔍 자동입력 필드 체크: ${fieldName}`, {
|
|
|
|
|
|
currentValue,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
isEmpty: currentValue === undefined || currentValue === "",
|
2025-09-04 18:36:40 +09:00
|
|
|
|
isAutoInput,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
autoValueType: config.autoValueType,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
|
|
|
|
|
if (currentValue === undefined || currentValue === "") {
|
|
|
|
|
|
const autoValue =
|
|
|
|
|
|
config.autoValueType === "custom"
|
|
|
|
|
|
? config.customValue || ""
|
|
|
|
|
|
: generateAutoValue(config.autoValueType);
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log("🔄 자동입력 필드 초기화:", {
|
|
|
|
|
|
fieldName,
|
|
|
|
|
|
autoValueType: config.autoValueType,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
autoValue,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
updateFormData(fieldName, autoValue);
|
|
|
|
|
|
} else {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`⏭️ 자동입력 건너뜀 (값 있음): ${fieldName} = "${currentValue}"`);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-11-04 14:33:39 +09:00
|
|
|
|
}
|
2025-09-04 18:36:40 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 초기 로드 시 자동입력 필드들 설정
|
|
|
|
|
|
initAutoInputFields();
|
2025-11-04 14:33:39 +09:00
|
|
|
|
}, [allComponents, generateAutoValue, user]); // formData는 의존성에서 제외 (무한 루프 방지)
|
2025-09-04 18:36:40 +09:00
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
// 날짜 값 업데이트
|
|
|
|
|
|
const updateDateValue = (fieldName: string, date: Date | undefined) => {
|
|
|
|
|
|
setDateValues((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[fieldName]: date,
|
|
|
|
|
|
}));
|
|
|
|
|
|
updateFormData(fieldName, date ? format(date, "yyyy-MM-dd") : "");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 실제 사용 가능한 위젯 렌더링
|
|
|
|
|
|
const renderInteractiveWidget = (comp: ComponentData) => {
|
2025-11-25 10:06:56 +09:00
|
|
|
|
console.log("🎯 renderInteractiveWidget 호출:", {
|
|
|
|
|
|
type: comp.type,
|
|
|
|
|
|
id: comp.id,
|
|
|
|
|
|
componentId: (comp as any).componentId,
|
|
|
|
|
|
hasComponentConfig: !!(comp as any).componentConfig,
|
|
|
|
|
|
componentConfig: (comp as any).componentConfig,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-03 15:23:12 +09:00
|
|
|
|
// 데이터 테이블 컴포넌트 처리
|
|
|
|
|
|
if (comp.type === "datatable") {
|
|
|
|
|
|
return (
|
|
|
|
|
|
<InteractiveDataTable
|
|
|
|
|
|
component={comp as DataTableComponent}
|
|
|
|
|
|
className="h-full w-full"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
width: "100%",
|
|
|
|
|
|
height: "100%",
|
|
|
|
|
|
}}
|
2025-10-02 14:34:15 +09:00
|
|
|
|
onRefresh={() => {
|
|
|
|
|
|
// 테이블 내부에서 loadData 호출하므로 여기서는 빈 함수
|
|
|
|
|
|
console.log("🔄 InteractiveDataTable 새로고침 트리거됨");
|
|
|
|
|
|
}}
|
2025-09-03 15:23:12 +09:00
|
|
|
|
/>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-20 10:55:33 +09:00
|
|
|
|
// 플로우 위젯 컴포넌트 처리
|
|
|
|
|
|
if (comp.type === "flow" || (comp.type === "component" && (comp as any).componentConfig?.type === "flow-widget")) {
|
|
|
|
|
|
const FlowWidget = require("@/components/screen/widgets/FlowWidget").FlowWidget;
|
|
|
|
|
|
// componentConfig에서 flowId 추출
|
|
|
|
|
|
const flowConfig = (comp as any).componentConfig || {};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-20 10:55:33 +09:00
|
|
|
|
console.log("🔍 InteractiveScreenViewer 플로우 위젯 변환:", {
|
|
|
|
|
|
compType: comp.type,
|
|
|
|
|
|
hasComponentConfig: !!(comp as any).componentConfig,
|
|
|
|
|
|
flowConfig,
|
|
|
|
|
|
flowConfigFlowId: flowConfig.flowId,
|
|
|
|
|
|
finalFlowId: flowConfig.flowId,
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-20 10:55:33 +09:00
|
|
|
|
const flowComponent = {
|
|
|
|
|
|
...comp,
|
|
|
|
|
|
type: "flow" as const,
|
|
|
|
|
|
flowId: flowConfig.flowId,
|
|
|
|
|
|
flowName: flowConfig.flowName,
|
|
|
|
|
|
showStepCount: flowConfig.showStepCount !== false,
|
|
|
|
|
|
allowDataMove: flowConfig.allowDataMove || false,
|
|
|
|
|
|
displayMode: flowConfig.displayMode || "horizontal",
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-20 10:55:33 +09:00
|
|
|
|
console.log("🔍 InteractiveScreenViewer 최종 flowComponent:", flowComponent);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-20 10:55:33 +09:00
|
|
|
|
return (
|
2025-10-24 16:34:21 +09:00
|
|
|
|
<div className="w-full">
|
2025-10-20 10:55:33 +09:00
|
|
|
|
<FlowWidget component={flowComponent as any} />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-24 17:24:47 +09:00
|
|
|
|
// 탭 컴포넌트 처리
|
2025-11-25 10:06:56 +09:00
|
|
|
|
const componentType = (comp as any).componentType || (comp as any).componentId;
|
|
|
|
|
|
if (comp.type === "tabs" || (comp.type === "component" && componentType === "tabs-widget")) {
|
2025-11-24 17:24:47 +09:00
|
|
|
|
const TabsWidget = require("@/components/screen/widgets/TabsWidget").TabsWidget;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-24 17:24:47 +09:00
|
|
|
|
// componentConfig에서 탭 정보 추출
|
|
|
|
|
|
const tabsConfig = comp.componentConfig || {};
|
|
|
|
|
|
const tabsComponent = {
|
|
|
|
|
|
...comp,
|
|
|
|
|
|
type: "tabs" as const,
|
|
|
|
|
|
tabs: tabsConfig.tabs || [],
|
|
|
|
|
|
defaultTab: tabsConfig.defaultTab,
|
|
|
|
|
|
orientation: tabsConfig.orientation || "horizontal",
|
|
|
|
|
|
variant: tabsConfig.variant || "default",
|
|
|
|
|
|
allowCloseable: tabsConfig.allowCloseable || false,
|
|
|
|
|
|
persistSelection: tabsConfig.persistSelection || false,
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-24 17:24:47 +09:00
|
|
|
|
console.log("🔍 탭 컴포넌트 렌더링:", {
|
|
|
|
|
|
originalType: comp.type,
|
2025-11-25 10:06:56 +09:00
|
|
|
|
componentType,
|
2025-11-24 17:24:47 +09:00
|
|
|
|
componentId: (comp as any).componentId,
|
|
|
|
|
|
tabs: tabsComponent.tabs,
|
|
|
|
|
|
tabsConfig,
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-24 17:24:47 +09:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="h-full w-full">
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<TabsWidget
|
|
|
|
|
|
component={tabsComponent as any}
|
2025-11-25 15:55:05 +09:00
|
|
|
|
menuObjid={menuObjid} // 🆕 부모의 menuObjid 전달
|
|
|
|
|
|
/>
|
2025-11-24 17:24:47 +09:00
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-08 17:13:14 +09:00
|
|
|
|
// 🆕 렉 구조 컴포넌트 처리
|
|
|
|
|
|
if (comp.type === "component" && componentType === "rack-structure") {
|
|
|
|
|
|
const { RackStructureComponent } = require("@/lib/registry/components/rack-structure/RackStructureComponent");
|
|
|
|
|
|
const componentConfig = (comp as any).componentConfig || {};
|
|
|
|
|
|
// config가 중첩되어 있을 수 있음: componentConfig.config 또는 componentConfig 직접
|
|
|
|
|
|
const rackConfig = componentConfig.config || componentConfig;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-08 17:13:14 +09:00
|
|
|
|
console.log("🏗️ 렉 구조 컴포넌트 렌더링:", {
|
|
|
|
|
|
componentType,
|
|
|
|
|
|
componentConfig,
|
|
|
|
|
|
rackConfig,
|
|
|
|
|
|
fieldMapping: rackConfig.fieldMapping,
|
|
|
|
|
|
formData,
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-08 17:13:14 +09:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="h-full w-full overflow-auto">
|
|
|
|
|
|
<RackStructureComponent
|
|
|
|
|
|
config={rackConfig}
|
|
|
|
|
|
formData={formData}
|
|
|
|
|
|
tableName={tableName}
|
|
|
|
|
|
onChange={(locations: any[]) => {
|
|
|
|
|
|
console.log("📦 렉 구조 위치 데이터 변경:", locations.length, "개");
|
|
|
|
|
|
// 컴포넌트의 columnName을 키로 사용
|
|
|
|
|
|
const fieldKey = (comp as any).columnName || "_rackStructureLocations";
|
|
|
|
|
|
updateFormData(fieldKey, locations);
|
|
|
|
|
|
}}
|
|
|
|
|
|
isPreview={false}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
const { widgetType, label: originalLabel, placeholder, required, readonly, columnName } = comp;
|
2025-09-01 18:42:59 +09:00
|
|
|
|
const fieldName = columnName || comp.id;
|
|
|
|
|
|
const currentValue = formData[fieldName] || "";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2026-01-15 10:39:23 +09:00
|
|
|
|
// 🆕 엔티티 조인 컬럼은 읽기 전용으로 처리
|
|
|
|
|
|
const isEntityJoin = (comp as any).isEntityJoin === true;
|
|
|
|
|
|
const isReadonly = readonly || isEntityJoin;
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
// 다국어 라벨 적용 (langKey가 있으면 번역 텍스트 사용)
|
|
|
|
|
|
const compLangKey = (comp as any).langKey;
|
|
|
|
|
|
const label = compLangKey && translations[compLangKey] ? translations[compLangKey] : originalLabel;
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
// 스타일 적용
|
|
|
|
|
|
const applyStyles = (element: React.ReactElement) => {
|
|
|
|
|
|
if (!comp.style) return element;
|
|
|
|
|
|
|
2025-11-10 09:33:29 +09:00
|
|
|
|
// ✅ 격자 시스템 잔재 제거: style.width, style.height는 무시
|
|
|
|
|
|
// size.width, size.height가 부모 컨테이너에서 적용되므로
|
|
|
|
|
|
const { width, height, ...styleWithoutSize } = comp.style;
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return React.cloneElement(element, {
|
|
|
|
|
|
style: {
|
2025-09-04 11:33:52 +09:00
|
|
|
|
...element.props.style, // 기존 스타일 유지
|
2026-01-14 15:38:52 +09:00
|
|
|
|
...styleWithoutSize, // width/height 제외한 스타일만 적용
|
2025-09-04 11:33:52 +09:00
|
|
|
|
boxSizing: "border-box",
|
2025-09-01 18:42:59 +09:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
switch (widgetType) {
|
|
|
|
|
|
case "text":
|
|
|
|
|
|
case "email":
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "tel": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as TextTypeConfig | undefined;
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 자동입력 관련 처리
|
|
|
|
|
|
const isAutoInput = config?.autoInput || false;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const autoValue =
|
|
|
|
|
|
isAutoInput && config?.autoValueType
|
|
|
|
|
|
? config.autoValueType === "custom"
|
|
|
|
|
|
? config.customValue || ""
|
|
|
|
|
|
: generateAutoValue(config.autoValueType)
|
|
|
|
|
|
: "";
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 기본값 또는 자동값 설정
|
|
|
|
|
|
const displayValue = isAutoInput ? autoValue : currentValue || config?.defaultValue || "";
|
|
|
|
|
|
|
2025-09-03 11:50:42 +09:00
|
|
|
|
console.log("📝 InteractiveScreenViewer - Text 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
format: config?.format,
|
|
|
|
|
|
minLength: config?.minLength,
|
|
|
|
|
|
maxLength: config?.maxLength,
|
|
|
|
|
|
pattern: config?.pattern,
|
|
|
|
|
|
placeholder: config?.placeholder,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
defaultValue: config?.defaultValue,
|
|
|
|
|
|
autoInput: isAutoInput,
|
|
|
|
|
|
autoValueType: config?.autoValueType,
|
|
|
|
|
|
autoValue,
|
|
|
|
|
|
displayValue,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 형식별 패턴 생성
|
|
|
|
|
|
const getPatternByFormat = (format: string) => {
|
|
|
|
|
|
switch (format) {
|
|
|
|
|
|
case "korean":
|
|
|
|
|
|
return "[가-힣\\s]*";
|
|
|
|
|
|
case "english":
|
|
|
|
|
|
return "[a-zA-Z\\s]*";
|
|
|
|
|
|
case "alphanumeric":
|
|
|
|
|
|
return "[a-zA-Z0-9]*";
|
|
|
|
|
|
case "numeric":
|
|
|
|
|
|
return "[0-9]*";
|
|
|
|
|
|
case "email":
|
|
|
|
|
|
return "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}";
|
|
|
|
|
|
case "phone":
|
|
|
|
|
|
return "\\d{3}-\\d{4}-\\d{4}";
|
|
|
|
|
|
case "url":
|
|
|
|
|
|
return "https?://[\\w\\-]+(\\.[\\w\\-]+)+([\\w\\-\\.,@?^=%&:/~\\+#]*[\\w\\-\\@?^=%&/~\\+#])?";
|
|
|
|
|
|
default:
|
|
|
|
|
|
return config?.pattern || undefined;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 입력 검증 함수
|
|
|
|
|
|
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
|
const value = e.target.value;
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`📝 입력 변경: ${fieldName} = "${value}"`);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
|
|
|
|
|
|
// 형식별 실시간 검증
|
|
|
|
|
|
if (config?.format && config.format !== "none") {
|
|
|
|
|
|
const pattern = getPatternByFormat(config.format);
|
|
|
|
|
|
if (pattern) {
|
|
|
|
|
|
const regex = new RegExp(`^${pattern}$`);
|
|
|
|
|
|
if (value && !regex.test(value)) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`❌ 형식 검증 실패: ${fieldName} = "${value}"`);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
return; // 유효하지 않은 입력 차단
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 길이 제한 검증
|
|
|
|
|
|
if (config?.maxLength && value.length > config.maxLength) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`❌ 길이 제한 초과: ${fieldName} = "${value}" (최대: ${config.maxLength})`);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
return; // 최대 길이 초과 차단
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`✅ updateFormData 호출: ${fieldName} = "${value}"`);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
updateFormData(fieldName, value);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "입력하세요...";
|
|
|
|
|
|
const inputType = widgetType === "email" ? "email" : widgetType === "tel" ? "tel" : "text";
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Input
|
2025-09-03 11:50:42 +09:00
|
|
|
|
type={inputType}
|
2025-09-04 18:36:40 +09:00
|
|
|
|
placeholder={isAutoInput ? `자동입력: ${config?.autoValueType}` : finalPlaceholder}
|
|
|
|
|
|
value={displayValue}
|
|
|
|
|
|
onChange={isAutoInput ? undefined : handleInputChange}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly || isAutoInput}
|
2025-09-04 18:36:40 +09:00
|
|
|
|
readOnly={isAutoInput}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
minLength={config?.minLength}
|
|
|
|
|
|
maxLength={config?.maxLength}
|
|
|
|
|
|
pattern={getPatternByFormat(config?.format || "none")}
|
2025-10-30 15:39:39 +09:00
|
|
|
|
className={`w-full ${isAutoInput ? "bg-muted text-muted-foreground" : ""}`}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
case "number":
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "decimal": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as NumberTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("🔢 InteractiveScreenViewer - Number 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
format: config?.format,
|
|
|
|
|
|
min: config?.min,
|
|
|
|
|
|
max: config?.max,
|
|
|
|
|
|
step: config?.step,
|
|
|
|
|
|
decimalPlaces: config?.decimalPlaces,
|
|
|
|
|
|
thousandSeparator: config?.thousandSeparator,
|
|
|
|
|
|
prefix: config?.prefix,
|
|
|
|
|
|
suffix: config?.suffix,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const step = config?.step || (widgetType === "decimal" ? 0.01 : 1);
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "숫자를 입력하세요...";
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Input
|
|
|
|
|
|
type="number"
|
2025-09-03 11:50:42 +09:00
|
|
|
|
placeholder={finalPlaceholder}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
value={currentValue}
|
|
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.valueAsNumber || 0)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
min={config?.min}
|
|
|
|
|
|
max={config?.max}
|
|
|
|
|
|
step={step}
|
2025-09-04 11:33:52 +09:00
|
|
|
|
className="w-full"
|
|
|
|
|
|
style={{ height: "100%" }}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
case "textarea":
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "text_area": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as TextareaTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("📄 InteractiveScreenViewer - Textarea 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
rows: config?.rows,
|
|
|
|
|
|
maxLength: config?.maxLength,
|
|
|
|
|
|
minLength: config?.minLength,
|
|
|
|
|
|
placeholder: config?.placeholder,
|
|
|
|
|
|
defaultValue: config?.defaultValue,
|
|
|
|
|
|
resizable: config?.resizable,
|
|
|
|
|
|
wordWrap: config?.wordWrap,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "내용을 입력하세요...";
|
|
|
|
|
|
const rows = config?.rows || 3;
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Textarea
|
2025-09-03 11:50:42 +09:00
|
|
|
|
placeholder={finalPlaceholder}
|
|
|
|
|
|
value={currentValue || config?.defaultValue || ""}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
minLength={config?.minLength}
|
|
|
|
|
|
maxLength={config?.maxLength}
|
|
|
|
|
|
rows={rows}
|
|
|
|
|
|
className={`h-full w-full ${config?.resizable === false ? "resize-none" : ""}`}
|
|
|
|
|
|
style={{
|
|
|
|
|
|
whiteSpace: config?.wordWrap === false ? "nowrap" : "normal",
|
|
|
|
|
|
}}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
case "select":
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "dropdown": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as SelectTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("📋 InteractiveScreenViewer - Select 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
options: config?.options,
|
|
|
|
|
|
multiple: config?.multiple,
|
|
|
|
|
|
searchable: config?.searchable,
|
|
|
|
|
|
placeholder: config?.placeholder,
|
|
|
|
|
|
defaultValue: config?.defaultValue,
|
2025-12-10 13:53:44 +09:00
|
|
|
|
cascading: config?.cascading,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "선택하세요...";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
// 🆕 연쇄 드롭다운 처리 (방법 1: 관계 코드 방식 - 권장)
|
|
|
|
|
|
if (config?.cascadingRelationCode && config?.cascadingParentField) {
|
|
|
|
|
|
const parentFieldValue = formData[config.cascadingParentField];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
console.log("🔗 연쇄 드롭다운 (관계코드 방식):", {
|
|
|
|
|
|
relationCode: config.cascadingRelationCode,
|
|
|
|
|
|
parentField: config.cascadingParentField,
|
|
|
|
|
|
parentValue: parentFieldValue,
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<CascadingDropdownWrapper
|
|
|
|
|
|
relationCode={config.cascadingRelationCode}
|
|
|
|
|
|
parentFieldName={config.cascadingParentField}
|
|
|
|
|
|
parentValue={parentFieldValue}
|
|
|
|
|
|
value={currentValue}
|
|
|
|
|
|
onChange={(value) => updateFormData(fieldName, value)}
|
|
|
|
|
|
placeholder={finalPlaceholder}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-12-10 13:53:44 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
// 🔄 연쇄 드롭다운 처리 (방법 2: 직접 설정 방식 - 레거시)
|
|
|
|
|
|
if (config?.cascading?.enabled) {
|
|
|
|
|
|
const cascadingConfig = config.cascading;
|
|
|
|
|
|
const parentValue = formData[cascadingConfig.parentField];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<CascadingDropdownWrapper
|
|
|
|
|
|
config={cascadingConfig}
|
|
|
|
|
|
parentValue={parentValue}
|
|
|
|
|
|
value={currentValue}
|
|
|
|
|
|
onChange={(value) => updateFormData(fieldName, value)}
|
|
|
|
|
|
placeholder={finalPlaceholder}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-12-10 13:53:44 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-12-10 13:53:44 +09:00
|
|
|
|
// 일반 Select
|
2025-09-03 11:50:42 +09:00
|
|
|
|
const options = config?.options || [
|
|
|
|
|
|
{ label: "옵션 1", value: "option1" },
|
|
|
|
|
|
{ label: "옵션 2", value: "option2" },
|
|
|
|
|
|
{ label: "옵션 3", value: "option3" },
|
|
|
|
|
|
];
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Select
|
2025-09-03 11:50:42 +09:00
|
|
|
|
value={currentValue || config?.defaultValue || ""}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
onValueChange={(value) => updateFormData(fieldName, value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SelectTrigger className="h-full w-full">
|
2025-09-03 11:50:42 +09:00
|
|
|
|
<SelectValue placeholder={finalPlaceholder} />
|
2025-09-01 18:42:59 +09:00
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
2025-09-03 11:50:42 +09:00
|
|
|
|
{options.map((option, index) => (
|
|
|
|
|
|
<SelectItem key={index} value={option.value} disabled={option.disabled}>
|
|
|
|
|
|
{option.label}
|
|
|
|
|
|
</SelectItem>
|
|
|
|
|
|
))}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
</SelectContent>
|
|
|
|
|
|
</Select>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
case "checkbox":
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "boolean": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as CheckboxTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("☑️ InteractiveScreenViewer - Checkbox 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
defaultChecked: config?.defaultChecked,
|
|
|
|
|
|
labelPosition: config?.labelPosition,
|
|
|
|
|
|
checkboxText: config?.checkboxText,
|
|
|
|
|
|
trueValue: config?.trueValue,
|
|
|
|
|
|
falseValue: config?.falseValue,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const isChecked = currentValue === true || currentValue === "true" || config?.defaultChecked;
|
|
|
|
|
|
const checkboxText = config?.checkboxText || label || "확인";
|
|
|
|
|
|
const labelPosition = config?.labelPosition || "right";
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
2025-09-03 11:50:42 +09:00
|
|
|
|
<div
|
|
|
|
|
|
className={`flex h-full w-full items-center space-x-2 ${labelPosition === "left" ? "flex-row-reverse" : ""}`}
|
|
|
|
|
|
>
|
2025-09-01 18:42:59 +09:00
|
|
|
|
<Checkbox
|
|
|
|
|
|
id={fieldName}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
checked={isChecked}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
onCheckedChange={(checked) => updateFormData(fieldName, checked)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
/>
|
|
|
|
|
|
<label htmlFor={fieldName} className="text-sm">
|
2025-09-03 11:50:42 +09:00
|
|
|
|
{checkboxText}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
</label>
|
|
|
|
|
|
</div>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "radio": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as RadioTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("🔘 InteractiveScreenViewer - Radio 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
options: config?.options,
|
|
|
|
|
|
defaultValue: config?.defaultValue,
|
|
|
|
|
|
layout: config?.layout,
|
|
|
|
|
|
allowNone: config?.allowNone,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const options = config?.options || [
|
|
|
|
|
|
{ label: "옵션 1", value: "option1" },
|
|
|
|
|
|
{ label: "옵션 2", value: "option2" },
|
|
|
|
|
|
{ label: "옵션 3", value: "option3" },
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
const layout = config?.layout || "vertical";
|
|
|
|
|
|
const selectedValue = currentValue || config?.defaultValue || "";
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
return applyStyles(
|
2025-09-03 11:50:42 +09:00
|
|
|
|
<div className={`h-full w-full ${layout === "horizontal" ? "flex flex-wrap gap-4" : "space-y-2"}`}>
|
|
|
|
|
|
{config?.allowNone && (
|
|
|
|
|
|
<div className="flex items-center space-x-2">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="radio"
|
|
|
|
|
|
id={`${fieldName}_none`}
|
|
|
|
|
|
name={fieldName}
|
|
|
|
|
|
value=""
|
|
|
|
|
|
checked={selectedValue === ""}
|
|
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
className="h-4 w-4"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<label htmlFor={`${fieldName}_none`} className="text-sm">
|
|
|
|
|
|
선택 안함
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
{options.map((option, index) => (
|
2025-09-01 18:42:59 +09:00
|
|
|
|
<div key={index} className="flex items-center space-x-2">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="radio"
|
|
|
|
|
|
id={`${fieldName}_${index}`}
|
|
|
|
|
|
name={fieldName}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
value={option.value}
|
|
|
|
|
|
checked={selectedValue === option.value}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly || option.disabled}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
className="h-4 w-4"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<label htmlFor={`${fieldName}_${index}`} className="text-sm">
|
2025-09-03 11:50:42 +09:00
|
|
|
|
{option.label}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
2025-09-03 11:50:42 +09:00
|
|
|
|
case "date": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as DateTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("📅 InteractiveScreenViewer - Date 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
format: config?.format,
|
|
|
|
|
|
showTime: config?.showTime,
|
|
|
|
|
|
defaultValue: config?.defaultValue,
|
|
|
|
|
|
minDate: config?.minDate,
|
|
|
|
|
|
maxDate: config?.maxDate,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const shouldShowTime = config?.showTime || config?.format?.includes("HH:mm");
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "날짜를 선택하세요";
|
|
|
|
|
|
|
|
|
|
|
|
if (shouldShowTime) {
|
|
|
|
|
|
// 시간 포함 날짜 입력
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Input
|
|
|
|
|
|
type="datetime-local"
|
|
|
|
|
|
placeholder={finalPlaceholder}
|
|
|
|
|
|
value={currentValue || config?.defaultValue || ""}
|
|
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
min={config?.minDate}
|
|
|
|
|
|
max={config?.maxDate}
|
2025-09-04 11:33:52 +09:00
|
|
|
|
className="w-full"
|
2026-01-14 15:38:52 +09:00
|
|
|
|
style={{ height: "100%" }}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 날짜만 입력
|
|
|
|
|
|
const dateValue = dateValues[fieldName];
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Popover>
|
|
|
|
|
|
<PopoverTrigger asChild>
|
|
|
|
|
|
<Button
|
|
|
|
|
|
variant="outline"
|
|
|
|
|
|
className="h-full w-full justify-start text-left font-normal"
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
>
|
|
|
|
|
|
<CalendarIcon className="mr-2 h-4 w-4" />
|
|
|
|
|
|
{dateValue ? format(dateValue, "PPP", { locale: ko }) : config?.defaultValue || finalPlaceholder}
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
|
<PopoverContent className="w-auto p-0">
|
|
|
|
|
|
<Calendar
|
|
|
|
|
|
mode="single"
|
|
|
|
|
|
selected={dateValue}
|
|
|
|
|
|
onSelect={(date) => updateDateValue(fieldName, date)}
|
|
|
|
|
|
initialFocus
|
|
|
|
|
|
/>
|
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
|
</Popover>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "datetime": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as DateTypeConfig | undefined;
|
|
|
|
|
|
|
|
|
|
|
|
console.log("🕐 InteractiveScreenViewer - DateTime 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
|
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
format: config?.format,
|
|
|
|
|
|
defaultValue: config?.defaultValue,
|
|
|
|
|
|
minDate: config?.minDate,
|
|
|
|
|
|
maxDate: config?.maxDate,
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const finalPlaceholder = config?.placeholder || placeholder || "날짜와 시간을 입력하세요...";
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Input
|
|
|
|
|
|
type="datetime-local"
|
2025-09-03 11:50:42 +09:00
|
|
|
|
placeholder={finalPlaceholder}
|
|
|
|
|
|
value={currentValue || config?.defaultValue || ""}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
min={config?.minDate}
|
|
|
|
|
|
max={config?.maxDate}
|
2025-09-04 11:33:52 +09:00
|
|
|
|
className="w-full"
|
|
|
|
|
|
style={{ height: "100%" }}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "file": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as FileTypeConfig | undefined;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 현재 파일 값 가져오기
|
|
|
|
|
|
const getCurrentValue = () => {
|
|
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
|
|
|
|
|
return (externalFormData?.[fieldName] || localFormData[fieldName]) as any;
|
|
|
|
|
|
};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
const currentValue = getCurrentValue();
|
2025-09-03 11:50:42 +09:00
|
|
|
|
|
2025-09-29 13:29:03 +09:00
|
|
|
|
// 화면 ID 추출 (URL에서)
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const screenId =
|
|
|
|
|
|
typeof window !== "undefined" && window.location.pathname.includes("/screens/")
|
|
|
|
|
|
? parseInt(window.location.pathname.split("/screens/")[1])
|
|
|
|
|
|
: null;
|
2025-09-29 13:29:03 +09:00
|
|
|
|
|
2025-09-03 11:50:42 +09:00
|
|
|
|
console.log("📁 InteractiveScreenViewer - File 위젯:", {
|
|
|
|
|
|
componentId: widget.id,
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
config,
|
2025-09-05 12:04:13 +09:00
|
|
|
|
currentValue,
|
2025-09-29 13:29:03 +09:00
|
|
|
|
screenId,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
appliedSettings: {
|
|
|
|
|
|
accept: config?.accept,
|
|
|
|
|
|
multiple: config?.multiple,
|
|
|
|
|
|
maxSize: config?.maxSize,
|
2025-09-05 12:04:13 +09:00
|
|
|
|
preview: config?.preview,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
const handleFileChange = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
2025-10-28 15:39:22 +09:00
|
|
|
|
// 프리뷰 모드에서는 파일 업로드 차단
|
|
|
|
|
|
if (isPreviewMode) {
|
|
|
|
|
|
e.target.value = ""; // 파일 선택 취소
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-03 11:50:42 +09:00
|
|
|
|
const files = e.target.files;
|
2025-09-05 12:04:13 +09:00
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 파일 선택을 취소한 경우 (files가 null이거나 길이가 0)
|
|
|
|
|
|
if (!files || files.length === 0) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("📁 파일 선택 취소됨 - 기존 파일 유지");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 현재 저장된 파일이 있는지 확인
|
|
|
|
|
|
const currentStoredValue = externalFormData?.[fieldName] || localFormData[fieldName];
|
|
|
|
|
|
if (currentStoredValue) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("📁 기존 파일 있음 - 유지:", currentStoredValue);
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 기존 파일이 있으면 그대로 유지 (아무것도 하지 않음)
|
|
|
|
|
|
return;
|
|
|
|
|
|
} else {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("📁 기존 파일 없음 - 빈 상태 유지");
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 기존 파일이 없으면 빈 상태 유지
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
|
|
|
|
|
|
// 파일 크기 검증
|
|
|
|
|
|
if (config?.maxSize) {
|
|
|
|
|
|
for (let i = 0; i < files.length; i++) {
|
|
|
|
|
|
const file = files[i];
|
|
|
|
|
|
if (file.size > config.maxSize * 1024 * 1024) {
|
|
|
|
|
|
alert(`파일 크기가 ${config.maxSize}MB를 초과합니다: ${file.name}`);
|
|
|
|
|
|
e.target.value = "";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 실제 서버로 파일 업로드
|
|
|
|
|
|
try {
|
|
|
|
|
|
toast.loading(`${files.length}개 파일 업로드 중...`);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
const uploadResult = await uploadFilesAndCreateData(files);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
if (uploadResult.success) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("📁 업로드 완료된 파일 데이터:", uploadResult.data);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
|
|
|
|
|
setLocalFormData((prev) => ({ ...prev, [fieldName]: uploadResult.data }));
|
|
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 외부 폼 데이터 변경 콜백 호출
|
|
|
|
|
|
if (onFormDataChange) {
|
|
|
|
|
|
onFormDataChange(fieldName, uploadResult.data);
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
toast.success(uploadResult.message);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Error("파일 업로드에 실패했습니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error("파일 업로드 오류:", error);
|
2025-09-05 12:04:13 +09:00
|
|
|
|
toast.error("파일 업로드에 실패했습니다.");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 파일 입력 초기화
|
|
|
|
|
|
e.target.value = "";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const clearFile = () => {
|
|
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
setLocalFormData((prev) => ({ ...prev, [fieldName]: null }));
|
|
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 외부 폼 데이터 변경 콜백 호출
|
|
|
|
|
|
if (onFormDataChange) {
|
|
|
|
|
|
onFormDataChange(fieldName, null);
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
// 파일 input 초기화
|
|
|
|
|
|
const fileInput = document.querySelector(`input[type="file"][data-field="${fieldName}"]`) as HTMLInputElement;
|
|
|
|
|
|
if (fileInput) {
|
|
|
|
|
|
fileInput.value = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const renderFilePreview = () => {
|
|
|
|
|
|
if (!currentValue || !config?.preview) return null;
|
|
|
|
|
|
|
|
|
|
|
|
// 새로운 JSON 구조에서 파일 정보 추출
|
|
|
|
|
|
const fileData = currentValue.files || [];
|
|
|
|
|
|
if (fileData.length === 0) return null;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
return (
|
|
|
|
|
|
<div className="mt-2 space-y-2">
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div className="text-foreground text-sm font-medium">업로드된 파일 ({fileData.length}개)</div>
|
2025-09-05 12:04:13 +09:00
|
|
|
|
{fileData.map((fileInfo: any, index: number) => {
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const isImage = fileInfo.type?.startsWith("image/");
|
|
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
return (
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div key={index} className="bg-muted flex items-center gap-2 rounded border p-2">
|
|
|
|
|
|
<div className="bg-muted/50 flex h-16 w-16 items-center justify-center rounded">
|
2025-09-05 12:04:13 +09:00
|
|
|
|
{isImage ? (
|
2025-10-30 15:39:39 +09:00
|
|
|
|
<div className="text-success text-xs font-medium">IMG</div>
|
2025-09-05 12:04:13 +09:00
|
|
|
|
) : (
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<File className="text-muted-foreground h-8 w-8" />
|
2025-09-05 12:04:13 +09:00
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div className="min-w-0 flex-1">
|
|
|
|
|
|
<p className="text-foreground truncate text-sm font-medium">{fileInfo.name}</p>
|
|
|
|
|
|
<p className="text-muted-foreground text-xs">{(fileInfo.size / 1024 / 1024).toFixed(2)} MB</p>
|
|
|
|
|
|
<p className="text-muted-foreground text-xs">{fileInfo.type || "알 수 없는 형식"}</p>
|
|
|
|
|
|
<p className="text-muted-foreground/70 text-xs">
|
|
|
|
|
|
업로드: {new Date(fileInfo.uploadedAt).toLocaleString("ko-KR")}
|
2025-09-05 12:04:13 +09:00
|
|
|
|
</p>
|
|
|
|
|
|
</div>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<Button type="button" variant="ghost" size="sm" onClick={clearFile} className="h-8 w-8 p-0">
|
2025-09-05 12:04:13 +09:00
|
|
|
|
<X className="h-4 w-4" />
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
})}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
};
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return applyStyles(
|
2025-09-05 12:04:13 +09:00
|
|
|
|
<div className="w-full space-y-2">
|
|
|
|
|
|
{/* 파일 선택 영역 */}
|
|
|
|
|
|
<div className="relative">
|
|
|
|
|
|
<input
|
|
|
|
|
|
type="file"
|
|
|
|
|
|
data-field={fieldName}
|
|
|
|
|
|
onChange={handleFileChange}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-05 12:04:13 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
multiple={config?.multiple}
|
|
|
|
|
|
accept={config?.accept}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
className="absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed"
|
2025-09-05 12:04:13 +09:00
|
|
|
|
style={{ zIndex: 1 }}
|
|
|
|
|
|
/>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div
|
|
|
|
|
|
className={cn(
|
|
|
|
|
|
"flex items-center justify-center rounded-lg border-2 border-dashed p-4 text-center transition-colors",
|
|
|
|
|
|
currentValue && currentValue.files && currentValue.files.length > 0
|
|
|
|
|
|
? "border-success/30 bg-success/10"
|
|
|
|
|
|
: "border-input bg-muted hover:border-input/80 hover:bg-muted/80",
|
|
|
|
|
|
readonly && "cursor-not-allowed opacity-50",
|
|
|
|
|
|
!readonly && "cursor-pointer",
|
|
|
|
|
|
)}
|
|
|
|
|
|
>
|
2025-09-05 12:04:13 +09:00
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
|
{currentValue && currentValue.files && currentValue.files.length > 0 ? (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className="flex items-center justify-center">
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div className="bg-success/20 flex h-8 w-8 items-center justify-center rounded-full">
|
|
|
|
|
|
<svg className="text-success h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
2025-09-05 12:04:13 +09:00
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
|
|
|
|
|
|
</svg>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<p className="text-success text-sm font-medium">
|
|
|
|
|
|
{currentValue.totalCount === 1 ? "파일 선택됨" : `${currentValue.totalCount}개 파일 선택됨`}
|
2025-09-05 12:04:13 +09:00
|
|
|
|
</p>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<p className="text-success/80 text-xs">
|
2025-09-05 12:04:13 +09:00
|
|
|
|
총 {(currentValue.totalSize / 1024 / 1024).toFixed(2)}MB
|
|
|
|
|
|
</p>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<p className="text-success/80 text-xs">클릭하여 다른 파일 선택</p>
|
2025-09-05 12:04:13 +09:00
|
|
|
|
</>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<Upload className="text-muted-foreground mx-auto h-8 w-8" />
|
|
|
|
|
|
<p className="text-muted-foreground text-sm">
|
|
|
|
|
|
{config?.dragDrop ? "파일을 드래그하여 놓거나 클릭하여 선택" : "클릭하여 파일 선택"}
|
2025-09-05 12:04:13 +09:00
|
|
|
|
</p>
|
|
|
|
|
|
{(config?.accept || config?.maxSize) && (
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div className="text-muted-foreground space-y-1 text-xs">
|
2025-09-05 12:04:13 +09:00
|
|
|
|
{config.accept && <div>허용 형식: {config.accept}</div>}
|
|
|
|
|
|
{config.maxSize && <div>최대 크기: {config.maxSize}MB</div>}
|
|
|
|
|
|
{config.multiple && <div>다중 선택 가능</div>}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 12:04:13 +09:00
|
|
|
|
{/* 파일 미리보기 */}
|
|
|
|
|
|
{renderFilePreview()}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
</div>,
|
2025-09-01 18:42:59 +09:00
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "code": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as CodeTypeConfig | undefined;
|
|
|
|
|
|
|
2026-01-14 15:38:52 +09:00
|
|
|
|
console.log("🔍 [InteractiveScreenViewer] Code 위젯 렌더링:", {
|
2025-09-03 11:50:42 +09:00
|
|
|
|
componentId: widget.id,
|
2025-09-19 02:15:21 +09:00
|
|
|
|
columnName: widget.columnName,
|
|
|
|
|
|
codeCategory: config?.codeCategory,
|
2025-11-11 16:28:17 +09:00
|
|
|
|
menuObjid,
|
|
|
|
|
|
hasMenuObjid: !!menuObjid,
|
2025-09-03 11:50:42 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-19 02:15:21 +09:00
|
|
|
|
// code 타입은 공통코드 선택박스로 처리
|
|
|
|
|
|
// DynamicWebTypeRenderer를 사용하여 SelectBasicComponent 렌더링
|
|
|
|
|
|
try {
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<DynamicWebTypeRenderer
|
|
|
|
|
|
webType="select"
|
|
|
|
|
|
props={{
|
|
|
|
|
|
component: widget,
|
|
|
|
|
|
value: currentValue,
|
|
|
|
|
|
onChange: (value: any) => updateFormData(fieldName, value),
|
|
|
|
|
|
onFormDataChange: updateFormData,
|
|
|
|
|
|
isInteractive: true,
|
|
|
|
|
|
readonly: readonly,
|
|
|
|
|
|
required: required,
|
|
|
|
|
|
placeholder: config?.placeholder || "코드를 선택하세요...",
|
|
|
|
|
|
className: "w-full h-full",
|
2025-11-11 15:25:07 +09:00
|
|
|
|
menuObjid: menuObjid, // 🆕 메뉴 OBJID 전달
|
2025-09-19 02:15:21 +09:00
|
|
|
|
}}
|
|
|
|
|
|
config={{
|
|
|
|
|
|
...config,
|
|
|
|
|
|
codeCategory: config?.codeCategory,
|
|
|
|
|
|
isCodeType: true, // 코드 타입임을 명시
|
|
|
|
|
|
}}
|
|
|
|
|
|
onEvent={(event: string, data: any) => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`Code widget event: ${event}`, data);
|
2025-09-19 02:15:21 +09:00
|
|
|
|
}}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
/>,
|
2025-09-19 02:15:21 +09:00
|
|
|
|
);
|
|
|
|
|
|
} catch (error) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error("DynamicWebTypeRenderer 로딩 실패, 기본 Select 사용:", error);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-19 02:15:21 +09:00
|
|
|
|
// 폴백: 기본 Select 컴포넌트 사용
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Select
|
|
|
|
|
|
value={currentValue || ""}
|
|
|
|
|
|
onValueChange={(value) => updateFormData(fieldName, value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-19 02:15:21 +09:00
|
|
|
|
required={required}
|
|
|
|
|
|
>
|
|
|
|
|
|
<SelectTrigger className="h-full w-full">
|
|
|
|
|
|
<SelectValue placeholder={config?.placeholder || "코드를 선택하세요..."} />
|
|
|
|
|
|
</SelectTrigger>
|
|
|
|
|
|
<SelectContent>
|
|
|
|
|
|
<SelectItem value="loading">로딩 중...</SelectItem>
|
|
|
|
|
|
</SelectContent>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
</Select>,
|
2025-09-19 02:15:21 +09:00
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "entity": {
|
2026-01-08 14:49:24 +09:00
|
|
|
|
// DynamicWebTypeRenderer로 위임하여 EntitySearchInputWrapper 사용
|
2025-09-03 11:50:42 +09:00
|
|
|
|
const widget = comp as WidgetComponent;
|
2026-01-08 14:49:24 +09:00
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<DynamicWebTypeRenderer
|
|
|
|
|
|
webType="entity"
|
|
|
|
|
|
config={widget.webTypeConfig}
|
|
|
|
|
|
props={{
|
|
|
|
|
|
component: widget,
|
|
|
|
|
|
value: currentValue,
|
|
|
|
|
|
onChange: (value: any) => updateFormData(fieldName, value),
|
|
|
|
|
|
onFormDataChange: updateFormData,
|
|
|
|
|
|
formData: formData,
|
|
|
|
|
|
readonly: readonly,
|
|
|
|
|
|
required: required,
|
|
|
|
|
|
placeholder: widget.placeholder || "엔티티를 선택하세요",
|
|
|
|
|
|
isInteractive: true,
|
|
|
|
|
|
className: "w-full h-full",
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>,
|
2025-09-01 18:42:59 +09:00
|
|
|
|
);
|
2025-09-03 11:50:42 +09:00
|
|
|
|
}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
|
2025-09-04 11:33:52 +09:00
|
|
|
|
case "button": {
|
|
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const config = widget.webTypeConfig as ButtonTypeConfig | undefined;
|
|
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
const handleButtonClick = async () => {
|
2025-10-28 15:39:22 +09:00
|
|
|
|
// 프리뷰 모드에서는 버튼 동작 차단
|
|
|
|
|
|
if (isPreviewMode) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
const actionType = config?.actionType || "save";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
try {
|
|
|
|
|
|
switch (actionType) {
|
|
|
|
|
|
case "save":
|
|
|
|
|
|
await handleSaveAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "delete":
|
|
|
|
|
|
await handleDeleteAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "edit":
|
|
|
|
|
|
handleEditAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "add":
|
|
|
|
|
|
handleAddAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "search":
|
|
|
|
|
|
handleSearchAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "reset":
|
|
|
|
|
|
handleResetAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "submit":
|
|
|
|
|
|
await handleSubmitAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "close":
|
|
|
|
|
|
handleCloseAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "popup":
|
|
|
|
|
|
handlePopupAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "navigate":
|
|
|
|
|
|
handleNavigateAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
case "custom":
|
|
|
|
|
|
await handleCustomAction();
|
|
|
|
|
|
break;
|
|
|
|
|
|
default:
|
2026-01-14 15:38:52 +09:00
|
|
|
|
// console.log(`알 수 없는 액션 타입: ${actionType}`);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error(`버튼 액션 실행 오류 (${actionType}):`, error);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert(`작업 중 오류가 발생했습니다: ${error.message}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-19 18:43:55 +09:00
|
|
|
|
// 저장 액션 (개선된 버전)
|
2025-09-04 14:23:35 +09:00
|
|
|
|
const handleSaveAction = async () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("💾 저장 시작");
|
2025-09-19 18:43:55 +09:00
|
|
|
|
|
2025-11-03 16:26:32 +09:00
|
|
|
|
// ✅ 사용자 정보가 로드되지 않았으면 저장 불가
|
|
|
|
|
|
if (!user?.userId) {
|
|
|
|
|
|
alert("사용자 정보를 불러오는 중입니다. 잠시 후 다시 시도해주세요.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-19 18:43:55 +09:00
|
|
|
|
// 개선된 검증 시스템이 활성화된 경우
|
|
|
|
|
|
if (enhancedValidation) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔍 개선된 검증 시스템 사용");
|
2025-09-19 18:43:55 +09:00
|
|
|
|
const success = await enhancedValidation.saveForm();
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
toast.success("데이터가 성공적으로 저장되었습니다!");
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 기존 방식 (레거시 지원)
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const currentFormData = { ...localFormData, ...externalFormData };
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("💾 기존 방식으로 저장 - currentFormData:", currentFormData);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// formData 유효성 체크를 완화 (빈 객체라도 위젯이 있으면 저장 진행)
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const hasWidgets = allComponents.some((comp) => comp.type === "widget");
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (!hasWidgets) {
|
|
|
|
|
|
alert("저장할 입력 컴포넌트가 없습니다.");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 필수 항목 검증
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const requiredFields = allComponents.filter((c) => c.required && (c.columnName || c.id));
|
|
|
|
|
|
const missingFields = requiredFields.filter((field) => {
|
2025-09-04 14:23:35 +09:00
|
|
|
|
const fieldName = field.columnName || field.id;
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const value = currentFormData[fieldName];
|
2025-09-04 14:23:35 +09:00
|
|
|
|
return !value || value.toString().trim() === "";
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (missingFields.length > 0) {
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const fieldNames = missingFields.map((f) => f.label || f.columnName || f.id).join(", ");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert(`다음 필수 항목을 입력해주세요: ${fieldNames}`);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!screenInfo?.id) {
|
|
|
|
|
|
alert("화면 정보가 없어 저장할 수 없습니다.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 컬럼명 기반으로 데이터 매핑
|
|
|
|
|
|
const mappedData: Record<string, any> = {};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 입력 가능한 컴포넌트에서 데이터 수집
|
2026-01-14 15:38:52 +09:00
|
|
|
|
allComponents.forEach((comp) => {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 위젯 컴포넌트이고 입력 가능한 타입인 경우
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (comp.type === "widget") {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
|
|
|
|
|
let value = currentFormData[fieldName];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log(`🔍 컴포넌트 처리: ${fieldName}`, {
|
|
|
|
|
|
widgetType: widget.widgetType,
|
|
|
|
|
|
formDataValue: value,
|
|
|
|
|
|
hasWebTypeConfig: !!widget.webTypeConfig,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
config: widget.webTypeConfig,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 자동입력 필드인 경우에만 값이 없을 때 생성
|
2026-01-14 15:38:52 +09:00
|
|
|
|
if (
|
|
|
|
|
|
(widget.widgetType === "text" || widget.widgetType === "email" || widget.widgetType === "tel") &&
|
|
|
|
|
|
widget.webTypeConfig
|
|
|
|
|
|
) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const config = widget.webTypeConfig as TextTypeConfig;
|
|
|
|
|
|
const isAutoInput = config?.autoInput || false;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log(`📋 ${fieldName} 자동입력 체크:`, {
|
|
|
|
|
|
isAutoInput,
|
|
|
|
|
|
autoValueType: config?.autoValueType,
|
|
|
|
|
|
hasValue: !!value,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
value,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
|
|
|
|
|
if (isAutoInput && config?.autoValueType && (!value || value === "")) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 자동입력이고 값이 없을 때만 생성
|
2026-01-14 15:38:52 +09:00
|
|
|
|
value =
|
|
|
|
|
|
config.autoValueType === "custom"
|
|
|
|
|
|
? config.customValue || ""
|
|
|
|
|
|
: generateAutoValue(config.autoValueType);
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log("💾 자동입력 값 저장 (값이 없어서 생성):", {
|
|
|
|
|
|
fieldName,
|
|
|
|
|
|
autoValueType: config.autoValueType,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
generatedValue: value,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
|
|
|
|
|
} else if (isAutoInput && value) {
|
|
|
|
|
|
console.log("💾 자동입력 필드지만 기존 값 유지:", {
|
|
|
|
|
|
fieldName,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
existingValue: value,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
|
|
|
|
|
} else if (!isAutoInput) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`📝 일반 입력 필드: ${fieldName} = "${value}"`);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 값이 있는 경우만 매핑 (빈 문자열도 포함하되, undefined는 제외)
|
|
|
|
|
|
if (value !== undefined && value !== null && value !== "undefined") {
|
|
|
|
|
|
// columnName이 있으면 columnName을 키로, 없으면 컴포넌트 ID를 키로 사용
|
|
|
|
|
|
const saveKey = widget.columnName || `comp_${widget.id}`;
|
|
|
|
|
|
mappedData[saveKey] = value;
|
|
|
|
|
|
} else if (widget.columnName) {
|
|
|
|
|
|
// 값이 없지만 columnName이 있는 경우, 빈 문자열로 저장
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(`⚠️ ${widget.columnName} 필드에 값이 없어 빈 문자열로 저장`);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
mappedData[widget.columnName] = "";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
console.log("💾 저장할 데이터 매핑:", {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
원본데이터: currentFormData,
|
2025-09-04 14:23:35 +09:00
|
|
|
|
매핑된데이터: mappedData,
|
|
|
|
|
|
화면정보: screenInfo,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
전체컴포넌트수: allComponents.length,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
위젯컴포넌트수: allComponents.filter((c) => c.type === "widget").length,
|
2025-09-04 14:23:35 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 각 컴포넌트의 상세 정보 로그
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔍 컴포넌트별 데이터 수집 상세:");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
allComponents.forEach((comp) => {
|
|
|
|
|
|
if (comp.type === "widget") {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const widget = comp as WidgetComponent;
|
|
|
|
|
|
const fieldName = widget.columnName || widget.id;
|
|
|
|
|
|
const value = currentFormData[fieldName];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const hasValue = value !== undefined && value !== null && value !== "";
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log(` - ${fieldName} (${widget.widgetType}): "${value}" (값있음: ${hasValue}, 컬럼명: ${widget.columnName})`);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 매핑된 데이터가 비어있으면 경고
|
|
|
|
|
|
if (Object.keys(mappedData).length === 0) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.warn("⚠️ 매핑된 데이터가 없습니다. 빈 데이터로 저장됩니다.");
|
2025-09-04 18:36:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 테이블명 결정 (화면 정보에서 가져오거나 첫 번째 컴포넌트의 테이블명 사용)
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const tableName =
|
|
|
|
|
|
screenInfo.tableName || allComponents.find((c) => c.columnName)?.tableName || "dynamic_form_data"; // 기본값
|
2025-09-04 14:23:35 +09:00
|
|
|
|
|
2025-11-03 16:26:32 +09:00
|
|
|
|
// 🆕 자동으로 작성자 정보 추가 (user.userId가 확실히 있음)
|
|
|
|
|
|
const writerValue = user.userId;
|
|
|
|
|
|
const companyCodeValue = user.companyCode || "";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-29 11:26:00 +09:00
|
|
|
|
console.log("👤 현재 사용자 정보:", {
|
2025-11-03 16:26:32 +09:00
|
|
|
|
userId: user.userId,
|
2025-10-29 11:26:00 +09:00
|
|
|
|
userName: userName,
|
2025-11-03 16:26:32 +09:00
|
|
|
|
companyCode: user.companyCode, // ✅ 회사 코드
|
|
|
|
|
|
formDataWriter: mappedData.writer, // ✅ 폼에서 입력한 writer 값
|
|
|
|
|
|
formDataCompanyCode: mappedData.company_code, // ✅ 폼에서 입력한 company_code 값
|
|
|
|
|
|
defaultWriterValue: writerValue,
|
|
|
|
|
|
companyCodeValue, // ✅ 최종 회사 코드 값
|
2025-10-29 11:26:00 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
const dataWithUserInfo = {
|
|
|
|
|
|
...mappedData,
|
2025-11-03 16:26:32 +09:00
|
|
|
|
writer: mappedData.writer || writerValue, // ✅ 입력값 우선, 없으면 userId
|
|
|
|
|
|
created_by: writerValue, // created_by는 항상 로그인한 사람
|
|
|
|
|
|
updated_by: writerValue, // updated_by는 항상 로그인한 사람
|
|
|
|
|
|
company_code: mappedData.company_code || companyCodeValue, // ✅ 입력값 우선, 없으면 user.companyCode
|
2025-10-29 11:26:00 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
const saveData: DynamicFormData = {
|
|
|
|
|
|
screenId: screenInfo.id,
|
|
|
|
|
|
tableName: tableName,
|
2025-10-29 11:26:00 +09:00
|
|
|
|
data: dataWithUserInfo,
|
2025-09-04 14:23:35 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-29 11:26:00 +09:00
|
|
|
|
console.log("🚀 API 저장 요청:", saveData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
|
|
|
|
|
|
const result = await dynamicFormApi.saveFormData(saveData);
|
|
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
alert("저장되었습니다.");
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("✅ 저장 성공:", result.data);
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 저장 후 데이터 초기화 (선택사항)
|
|
|
|
|
|
if (onFormDataChange) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const resetData: Record<string, any> = {};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
Object.keys(formData).forEach((key) => {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
resetData[key] = "";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
});
|
2025-09-04 18:36:40 +09:00
|
|
|
|
onFormDataChange(resetData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Error(result.message || "저장에 실패했습니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error: any) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error("❌ 저장 실패:", error);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert(`저장 중 오류가 발생했습니다: ${error.message}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 삭제 액션
|
|
|
|
|
|
const handleDeleteAction = async () => {
|
|
|
|
|
|
const confirmMessage = config?.confirmMessage || "정말로 삭제하시겠습니까?";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
if (!confirm(confirmMessage)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 삭제할 레코드 ID가 필요 (폼 데이터에서 id 필드 찾기)
|
|
|
|
|
|
const recordId = formData["id"] || formData["ID"] || formData["objid"];
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
if (!recordId) {
|
|
|
|
|
|
alert("삭제할 데이터를 찾을 수 없습니다. (ID가 없음)");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 테이블명 결정
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const tableName =
|
|
|
|
|
|
screenInfo?.tableName || allComponents.find((c) => c.columnName)?.tableName || "unknown_table";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
|
|
|
|
|
|
if (!tableName || tableName === "unknown_table") {
|
|
|
|
|
|
alert("테이블 정보가 없어 삭제할 수 없습니다.");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🗑️ 삭제 실행:", { recordId, tableName, formData });
|
2025-09-04 14:23:35 +09:00
|
|
|
|
|
2026-01-09 13:43:14 +09:00
|
|
|
|
// screenId 전달하여 제어관리 실행 가능하도록 함
|
|
|
|
|
|
const result = await dynamicFormApi.deleteFormDataFromTable(recordId, tableName, screenInfo?.id);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
|
|
|
|
|
|
if (result.success) {
|
|
|
|
|
|
alert("삭제되었습니다.");
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("✅ 삭제 성공");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 삭제 후 폼 초기화
|
|
|
|
|
|
if (onFormDataChange) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const resetData: Record<string, any> = {};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
Object.keys(formData).forEach((key) => {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
resetData[key] = "";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
});
|
2025-09-04 18:36:40 +09:00
|
|
|
|
onFormDataChange(resetData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
throw new Error(result.message || "삭제에 실패했습니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (error: any) {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.error("❌ 삭제 실패:", error);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert(`삭제 중 오류가 발생했습니다: ${error.message}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 편집 액션
|
|
|
|
|
|
const handleEditAction = () => {
|
2025-10-01 17:45:29 +09:00
|
|
|
|
console.log("✏️ 수정 액션 실행");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-01 17:45:29 +09:00
|
|
|
|
// 버튼 컴포넌트의 수정 모달 설정 가져오기
|
|
|
|
|
|
const editModalTitle = config?.editModalTitle || "";
|
|
|
|
|
|
const editModalDescription = config?.editModalDescription || "";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-01 17:45:29 +09:00
|
|
|
|
console.log("📝 버튼 수정 모달 설정:", { editModalTitle, editModalDescription });
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-10-01 17:45:29 +09:00
|
|
|
|
// EditModal 열기 이벤트 발생
|
|
|
|
|
|
const event = new CustomEvent("openEditModal", {
|
|
|
|
|
|
detail: {
|
|
|
|
|
|
screenId: screenInfo?.id,
|
|
|
|
|
|
modalSize: "lg",
|
|
|
|
|
|
editData: formData,
|
|
|
|
|
|
modalTitle: editModalTitle,
|
|
|
|
|
|
modalDescription: editModalDescription,
|
|
|
|
|
|
onSave: () => {
|
|
|
|
|
|
console.log("✅ 수정 완료");
|
|
|
|
|
|
// 필요시 폼 새로고침 또는 콜백 실행
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
});
|
|
|
|
|
|
window.dispatchEvent(event);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 추가 액션
|
|
|
|
|
|
const handleAddAction = () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("➕ 새 항목 추가");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 새 항목 추가 로직
|
|
|
|
|
|
alert("새 항목을 추가할 수 있습니다.");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 검색 액션
|
|
|
|
|
|
const handleSearchAction = () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔍 검색 실행:", formData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 검색 로직
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const searchTerms = Object.values(formData).filter((v) => v && v.toString().trim());
|
2025-09-04 14:23:35 +09:00
|
|
|
|
if (searchTerms.length === 0) {
|
|
|
|
|
|
alert("검색할 내용을 입력해주세요.");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
alert(`검색 실행: ${searchTerms.join(", ")}`);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 초기화 액션
|
|
|
|
|
|
const handleResetAction = () => {
|
|
|
|
|
|
if (confirm("모든 입력을 초기화하시겠습니까?")) {
|
|
|
|
|
|
if (onFormDataChange) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const resetData: Record<string, any> = {};
|
2026-01-14 15:38:52 +09:00
|
|
|
|
Object.keys(formData).forEach((key) => {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
resetData[key] = "";
|
2025-09-04 14:23:35 +09:00
|
|
|
|
});
|
2025-09-04 18:36:40 +09:00
|
|
|
|
onFormDataChange(resetData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔄 폼 초기화 완료");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert("입력이 초기화되었습니다.");
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 제출 액션
|
|
|
|
|
|
const handleSubmitAction = async () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("📤 폼 제출:", formData);
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 제출 로직
|
|
|
|
|
|
alert("제출되었습니다.");
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 닫기 액션
|
|
|
|
|
|
const handleCloseAction = () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("❌ 닫기 액션 실행");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 모달 내부에서 실행되는지 확인
|
|
|
|
|
|
const isInModal = document.querySelector('[role="dialog"]') !== null;
|
|
|
|
|
|
const isInPopup = window.opener !== null;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (isInModal) {
|
|
|
|
|
|
// 모달 내부인 경우: 모달의 닫기 버튼 클릭하거나 모달 닫기 이벤트 발생
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔄 모달 내부에서 닫기 - 모달 닫기 시도");
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 모달의 닫기 버튼을 찾아서 클릭
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const modalCloseButton = document.querySelector(
|
|
|
|
|
|
'[role="dialog"] button[aria-label*="Close"], [role="dialog"] button[data-dismiss="modal"], [role="dialog"] .dialog-close',
|
|
|
|
|
|
);
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (modalCloseButton) {
|
|
|
|
|
|
(modalCloseButton as HTMLElement).click();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// ESC 키 이벤트 발생시키기
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const escEvent = new KeyboardEvent("keydown", { key: "Escape", keyCode: 27, which: 27 });
|
2025-09-04 18:36:40 +09:00
|
|
|
|
document.dispatchEvent(escEvent);
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (isInPopup) {
|
|
|
|
|
|
// 팝업 창인 경우
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔄 팝업 창 닫기");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
window.close();
|
|
|
|
|
|
} else {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 일반 페이지인 경우 - 이전 페이지로 이동하지 않고 아무것도 하지 않음
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🔄 일반 페이지에서 닫기 - 아무 동작 하지 않음");
|
2025-09-04 18:36:40 +09:00
|
|
|
|
alert("닫기 버튼이 클릭되었습니다.");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 팝업 액션
|
|
|
|
|
|
const handlePopupAction = () => {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("🎯 팝업 액션 실행:", { popupScreenId: config?.popupScreenId });
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 15:20:26 +09:00
|
|
|
|
if (config?.popupScreenId) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 화면 모달 열기
|
2025-09-04 15:20:26 +09:00
|
|
|
|
setPopupScreen({
|
|
|
|
|
|
screenId: config.popupScreenId,
|
|
|
|
|
|
title: config.popupTitle || "상세 정보",
|
2025-09-04 18:36:40 +09:00
|
|
|
|
size: "lg",
|
2025-09-04 15:20:26 +09:00
|
|
|
|
});
|
|
|
|
|
|
} else if (config?.popupTitle && config?.popupContent) {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
// 텍스트 모달 표시
|
2025-09-04 14:23:35 +09:00
|
|
|
|
alert(`${config.popupTitle}\n\n${config.popupContent}`);
|
|
|
|
|
|
} else {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
alert("모달을 표시합니다.");
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 네비게이션 액션
|
|
|
|
|
|
const handleNavigateAction = () => {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
const navigateType = config?.navigateType || "url";
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (navigateType === "screen" && config?.navigateScreenId) {
|
|
|
|
|
|
// 화면으로 이동
|
|
|
|
|
|
const screenPath = `/screens/${config.navigateScreenId}`;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log("🎯 화면으로 이동:", {
|
|
|
|
|
|
screenId: config.navigateScreenId,
|
|
|
|
|
|
target: config.navigateTarget || "_self",
|
2026-01-14 15:38:52 +09:00
|
|
|
|
path: screenPath,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 18:36:40 +09:00
|
|
|
|
if (config.navigateTarget === "_blank") {
|
|
|
|
|
|
window.open(screenPath, "_blank");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.location.href = screenPath;
|
|
|
|
|
|
}
|
|
|
|
|
|
} else if (navigateType === "url" && config?.navigateUrl) {
|
|
|
|
|
|
// URL로 이동
|
|
|
|
|
|
console.log("🔗 URL로 이동:", {
|
|
|
|
|
|
url: config.navigateUrl,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
target: config.navigateTarget || "_self",
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-04 11:33:52 +09:00
|
|
|
|
if (config.navigateTarget === "_blank") {
|
|
|
|
|
|
window.open(config.navigateUrl, "_blank");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.location.href = config.navigateUrl;
|
|
|
|
|
|
}
|
2025-09-04 14:23:35 +09:00
|
|
|
|
} else {
|
2025-09-04 18:36:40 +09:00
|
|
|
|
console.log("🔗 네비게이션 정보가 설정되지 않았습니다:", {
|
|
|
|
|
|
navigateType,
|
|
|
|
|
|
hasUrl: !!config?.navigateUrl,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
hasScreenId: !!config?.navigateScreenId,
|
2025-09-04 18:36:40 +09:00
|
|
|
|
});
|
2025-09-04 14:23:35 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 커스텀 액션
|
|
|
|
|
|
const handleCustomAction = async () => {
|
|
|
|
|
|
if (config?.customAction) {
|
2025-09-04 11:33:52 +09:00
|
|
|
|
try {
|
2025-09-04 14:23:35 +09:00
|
|
|
|
// 보안상 제한적인 eval 사용
|
|
|
|
|
|
const result = eval(config.customAction);
|
|
|
|
|
|
if (result instanceof Promise) {
|
|
|
|
|
|
await result;
|
|
|
|
|
|
}
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("⚡ 커스텀 액션 실행 완료");
|
2025-09-04 11:33:52 +09:00
|
|
|
|
} catch (error) {
|
2025-09-04 14:23:35 +09:00
|
|
|
|
throw new Error(`커스텀 액션 실행 실패: ${error.message}`);
|
2025-09-04 11:33:52 +09:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2025-10-01 18:17:30 +09:00
|
|
|
|
// console.log("⚡ 커스텀 액션이 설정되지 않았습니다.");
|
2025-09-04 11:33:52 +09:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
// 버튼 텍스트 다국어 적용 (componentConfig.langKey 확인)
|
|
|
|
|
|
const buttonLangKey = (widget as any).componentConfig?.langKey;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const buttonText =
|
|
|
|
|
|
buttonLangKey && translations[buttonLangKey]
|
|
|
|
|
|
? translations[buttonLangKey]
|
|
|
|
|
|
: (widget as any).componentConfig?.text || label || "버튼";
|
2026-01-14 15:33:57 +09:00
|
|
|
|
|
2026-01-14 14:35:27 +09:00
|
|
|
|
// 커스텀 색상이 있으면 Tailwind 클래스 대신 직접 스타일 적용
|
|
|
|
|
|
const hasCustomColors = config?.backgroundColor || config?.textColor;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-11-04 11:41:20 +09:00
|
|
|
|
return applyStyles(
|
2026-01-14 14:35:27 +09:00
|
|
|
|
<button
|
2025-09-04 11:33:52 +09:00
|
|
|
|
onClick={handleButtonClick}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
className={`focus:ring-ring w-full rounded-md px-3 py-2 text-sm font-medium transition-colors focus:ring-2 focus:ring-offset-2 focus:outline-none disabled:pointer-events-none disabled:opacity-50 ${
|
|
|
|
|
|
hasCustomColors
|
|
|
|
|
|
? ""
|
|
|
|
|
|
: "bg-background border-foreground text-foreground hover:bg-muted/50 border shadow-xs"
|
2026-01-14 14:35:27 +09:00
|
|
|
|
}`}
|
2025-09-04 11:33:52 +09:00
|
|
|
|
style={{
|
|
|
|
|
|
height: "100%",
|
2025-11-04 11:41:20 +09:00
|
|
|
|
backgroundColor: config?.backgroundColor,
|
|
|
|
|
|
color: config?.textColor,
|
|
|
|
|
|
borderColor: config?.borderColor,
|
2025-09-04 11:33:52 +09:00
|
|
|
|
}}
|
|
|
|
|
|
>
|
2026-01-14 15:33:57 +09:00
|
|
|
|
{buttonText}
|
2026-01-14 15:38:52 +09:00
|
|
|
|
</button>,
|
2025-09-04 11:33:52 +09:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
default:
|
|
|
|
|
|
return applyStyles(
|
|
|
|
|
|
<Input
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
placeholder={placeholder || "입력하세요..."}
|
|
|
|
|
|
value={currentValue}
|
|
|
|
|
|
onChange={(e) => updateFormData(fieldName, e.target.value)}
|
2026-01-15 10:39:23 +09:00
|
|
|
|
disabled={isReadonly}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
required={required}
|
2025-09-04 11:33:52 +09:00
|
|
|
|
className="w-full"
|
|
|
|
|
|
style={{ height: "100%" }}
|
2025-09-01 18:42:59 +09:00
|
|
|
|
/>,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-09-05 21:52:19 +09:00
|
|
|
|
// 파일 첨부 컴포넌트 처리
|
2025-09-29 13:29:03 +09:00
|
|
|
|
if (isFileComponent(component)) {
|
2025-09-05 21:52:19 +09:00
|
|
|
|
const fileComponent = component as FileComponent;
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
2025-09-05 21:52:19 +09:00
|
|
|
|
console.log("🎯 File 컴포넌트 렌더링:", {
|
|
|
|
|
|
componentId: fileComponent.id,
|
|
|
|
|
|
currentUploadedFiles: fileComponent.uploadedFiles?.length || 0,
|
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
userInfo: user ? { userId: user.userId, companyCode: user.companyCode } : "no user",
|
2025-09-05 21:52:19 +09:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-01-14 15:38:52 +09:00
|
|
|
|
const handleFileUpdate = useCallback(
|
|
|
|
|
|
async (updates: Partial<FileComponent>) => {
|
|
|
|
|
|
// 실제 화면에서는 파일 업데이트를 처리
|
|
|
|
|
|
console.log("📎 InteractiveScreenViewer - 파일 컴포넌트 업데이트:", {
|
|
|
|
|
|
updates,
|
2025-09-05 21:52:19 +09:00
|
|
|
|
hasUploadedFiles: !!updates.uploadedFiles,
|
2026-01-14 15:38:52 +09:00
|
|
|
|
uploadedFilesCount: updates.uploadedFiles?.length || 0,
|
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
2025-09-05 21:52:19 +09:00
|
|
|
|
});
|
2026-01-14 15:38:52 +09:00
|
|
|
|
|
|
|
|
|
|
if (updates.uploadedFiles && onFormDataChange) {
|
|
|
|
|
|
const fieldName = fileComponent.columnName || fileComponent.id;
|
|
|
|
|
|
|
|
|
|
|
|
// attach_file_info 테이블 구조에 맞는 데이터 생성
|
|
|
|
|
|
const fileInfoForDB = updates.uploadedFiles.map((file) => ({
|
|
|
|
|
|
objid: file.objid.replace("temp_", ""), // temp_ 제거
|
|
|
|
|
|
target_objid: "",
|
|
|
|
|
|
saved_file_name: file.savedFileName,
|
|
|
|
|
|
real_file_name: file.realFileName,
|
|
|
|
|
|
doc_type: file.docType,
|
|
|
|
|
|
doc_type_name: file.docTypeName,
|
|
|
|
|
|
file_size: file.fileSize,
|
|
|
|
|
|
file_ext: file.fileExt,
|
|
|
|
|
|
file_path: file.filePath,
|
|
|
|
|
|
writer: file.writer,
|
|
|
|
|
|
regdate: file.regdate,
|
|
|
|
|
|
status: file.status,
|
|
|
|
|
|
parent_target_objid: "",
|
|
|
|
|
|
company_code: file.companyCode,
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("💾 attach_file_info 형태로 변환된 데이터:", fileInfoForDB);
|
|
|
|
|
|
|
|
|
|
|
|
// FormData에는 파일 연결 정보만 저장 (간단한 형태)
|
|
|
|
|
|
const formDataValue = {
|
|
|
|
|
|
fileCount: updates.uploadedFiles.length,
|
|
|
|
|
|
docType: fileComponent.fileConfig.docType,
|
|
|
|
|
|
files: updates.uploadedFiles.map((file) => ({
|
|
|
|
|
|
objid: file.objid,
|
|
|
|
|
|
realFileName: file.realFileName,
|
|
|
|
|
|
fileSize: file.fileSize,
|
|
|
|
|
|
status: file.status,
|
|
|
|
|
|
})),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// console.log("📝 FormData 저장값:", { fieldName, formDataValue });
|
|
|
|
|
|
onFormDataChange(fieldName, formDataValue);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: 실제 API 연동 시 attach_file_info 테이블에 저장
|
|
|
|
|
|
// await saveFilesToDatabase(fileInfoForDB);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.warn("⚠️ 파일 업데이트 실패:", {
|
|
|
|
|
|
hasUploadedFiles: !!updates.uploadedFiles,
|
|
|
|
|
|
hasOnFormDataChange: !!onFormDataChange,
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
[fileComponent, onFormDataChange],
|
|
|
|
|
|
);
|
2025-09-05 21:52:19 +09:00
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="h-full w-full">
|
|
|
|
|
|
<FileUpload
|
|
|
|
|
|
component={fileComponent}
|
|
|
|
|
|
onUpdateComponent={handleFileUpdate}
|
|
|
|
|
|
userInfo={user} // 사용자 정보를 프롭으로 전달
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
// 그룹 컴포넌트 처리
|
|
|
|
|
|
if (component.type === "group") {
|
|
|
|
|
|
const children = allComponents.filter((comp) => comp.parentId === component.id);
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
|
<div className="relative h-full w-full">
|
|
|
|
|
|
{/* 그룹 내의 자식 컴포넌트들 렌더링 */}
|
|
|
|
|
|
{children.map((child) => (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={child.id}
|
|
|
|
|
|
style={{
|
|
|
|
|
|
position: "absolute",
|
|
|
|
|
|
left: `${child.position.x - component.position.x}px`,
|
|
|
|
|
|
top: `${child.position.y - component.position.y}px`,
|
2025-10-14 13:27:02 +09:00
|
|
|
|
width: child.style?.width || `${child.size.width}px`,
|
|
|
|
|
|
height: child.style?.height || `${child.size.height}px`,
|
2025-09-01 18:42:59 +09:00
|
|
|
|
zIndex: child.position.z || 1,
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<InteractiveScreenViewer
|
|
|
|
|
|
component={child}
|
|
|
|
|
|
allComponents={allComponents}
|
|
|
|
|
|
formData={externalFormData}
|
|
|
|
|
|
onFormDataChange={onFormDataChange}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 일반 위젯 컴포넌트
|
2025-09-03 15:23:12 +09:00
|
|
|
|
// 템플릿 컴포넌트 목록 (자체적으로 제목을 가지므로 라벨 불필요)
|
|
|
|
|
|
const templateTypes = ["datatable"];
|
|
|
|
|
|
|
|
|
|
|
|
// 라벨 표시 여부 계산
|
|
|
|
|
|
const shouldShowLabel =
|
2025-09-04 11:33:52 +09:00
|
|
|
|
!hideLabel && // hideLabel이 true면 라벨 숨김
|
2025-09-30 18:42:33 +09:00
|
|
|
|
(component.style?.labelDisplay ?? true) &&
|
2025-09-03 15:23:12 +09:00
|
|
|
|
(component.label || component.style?.labelText) &&
|
|
|
|
|
|
!templateTypes.includes(component.type); // 템플릿 컴포넌트는 라벨 표시 안함
|
|
|
|
|
|
|
2026-01-14 15:33:57 +09:00
|
|
|
|
// 다국어 라벨 텍스트 결정 (langKey가 있으면 번역 텍스트 사용)
|
|
|
|
|
|
const langKey = (component as any).langKey;
|
|
|
|
|
|
const originalLabelText = component.style?.labelText || component.label || "";
|
|
|
|
|
|
const labelText = langKey && translations[langKey] ? translations[langKey] : originalLabelText;
|
2025-09-03 15:23:12 +09:00
|
|
|
|
|
2025-09-19 02:15:21 +09:00
|
|
|
|
// 라벨 표시 여부 로그 (디버깅용)
|
|
|
|
|
|
if (component.type === "widget") {
|
|
|
|
|
|
console.log("🏷️ 라벨 표시 체크:", {
|
|
|
|
|
|
componentId: component.id,
|
|
|
|
|
|
hideLabel,
|
|
|
|
|
|
shouldShowLabel,
|
|
|
|
|
|
labelText,
|
2026-01-14 15:33:57 +09:00
|
|
|
|
langKey,
|
|
|
|
|
|
hasTranslation: !!translations[langKey],
|
2025-09-19 02:15:21 +09:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-03 15:23:12 +09:00
|
|
|
|
// 라벨 스타일 적용
|
|
|
|
|
|
const labelStyle = {
|
|
|
|
|
|
fontSize: component.style?.labelFontSize || "14px",
|
2025-10-02 14:34:15 +09:00
|
|
|
|
color: component.style?.labelColor || "#212121",
|
2025-09-03 15:23:12 +09:00
|
|
|
|
fontWeight: component.style?.labelFontWeight || "500",
|
|
|
|
|
|
backgroundColor: component.style?.labelBackgroundColor || "transparent",
|
|
|
|
|
|
padding: component.style?.labelPadding || "0",
|
|
|
|
|
|
borderRadius: component.style?.labelBorderRadius || "0",
|
|
|
|
|
|
marginBottom: component.style?.labelMarginBottom || "4px",
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-10-14 11:48:04 +09:00
|
|
|
|
// 상위에서 라벨을 표시한 경우, 컴포넌트 내부에서는 라벨을 숨김
|
|
|
|
|
|
const componentForRendering = shouldShowLabel
|
|
|
|
|
|
? {
|
|
|
|
|
|
...component,
|
|
|
|
|
|
style: {
|
|
|
|
|
|
...component.style,
|
|
|
|
|
|
labelDisplay: false, // 상위에서 라벨을 표시했으므로 컴포넌트 내부에서는 숨김
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
: component;
|
|
|
|
|
|
|
2025-09-01 18:42:59 +09:00
|
|
|
|
return (
|
2025-12-11 18:40:39 +09:00
|
|
|
|
<SplitPanelProvider>
|
2025-12-17 15:00:15 +09:00
|
|
|
|
<ActiveTabProvider>
|
|
|
|
|
|
<TableOptionsProvider>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
<div className="flex h-full flex-col">
|
|
|
|
|
|
{/* 테이블 옵션 툴바 */}
|
|
|
|
|
|
<TableOptionsToolbar />
|
|
|
|
|
|
|
|
|
|
|
|
{/* 메인 컨텐츠 */}
|
|
|
|
|
|
<div className="h-full flex-1" style={{ width: "100%" }}>
|
|
|
|
|
|
{/* 라벨이 있는 경우 표시 (데이터 테이블 제외) */}
|
|
|
|
|
|
{shouldShowLabel && (
|
|
|
|
|
|
<label className="mb-2 block text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70">
|
|
|
|
|
|
{labelText}
|
|
|
|
|
|
{(component.required || component.componentConfig?.required) && (
|
|
|
|
|
|
<span className="text-destructive ml-1">*</span>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</label>
|
|
|
|
|
|
)}
|
2025-09-04 15:20:26 +09:00
|
|
|
|
|
2026-01-14 15:38:52 +09:00
|
|
|
|
{/* 실제 위젯 - 상위에서 라벨을 렌더링했으므로 자식은 라벨 숨김 */}
|
|
|
|
|
|
<div className="h-full" style={{ width: "100%", height: "100%" }}>
|
|
|
|
|
|
{renderInteractiveWidget(componentForRendering)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-09-04 15:20:26 +09:00
|
|
|
|
</div>
|
2025-12-11 18:40:39 +09:00
|
|
|
|
|
2026-01-14 15:38:52 +09:00
|
|
|
|
{/* 개선된 검증 패널 (선택적 표시) */}
|
|
|
|
|
|
{showValidationPanel && enhancedValidation && (
|
|
|
|
|
|
<div className="absolute right-4 bottom-4 z-50">
|
|
|
|
|
|
<FormValidationIndicator
|
|
|
|
|
|
validationState={enhancedValidation.validationState}
|
|
|
|
|
|
saveState={enhancedValidation.saveState}
|
|
|
|
|
|
onSave={async () => {
|
|
|
|
|
|
const success = await enhancedValidation.saveForm();
|
|
|
|
|
|
if (success) {
|
|
|
|
|
|
toast.success("데이터가 성공적으로 저장되었습니다!");
|
|
|
|
|
|
}
|
|
|
|
|
|
}}
|
|
|
|
|
|
canSave={enhancedValidation.canSave}
|
|
|
|
|
|
compact={true}
|
|
|
|
|
|
showDetails={false}
|
|
|
|
|
|
/>
|
2025-12-11 18:40:39 +09:00
|
|
|
|
</div>
|
2026-01-14 15:38:52 +09:00
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
|
|
{/* 모달 화면 */}
|
|
|
|
|
|
<Dialog
|
|
|
|
|
|
open={!!popupScreen}
|
|
|
|
|
|
onOpenChange={() => {
|
|
|
|
|
|
setPopupScreen(null);
|
|
|
|
|
|
setPopupFormData({}); // 팝업 닫을 때 formData도 초기화
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
<DialogContent className="max-h-[90vh] max-w-4xl overflow-hidden p-0">
|
|
|
|
|
|
<DialogHeader className="px-6 pt-4 pb-2">
|
|
|
|
|
|
<DialogTitle>{popupScreen?.title || "상세 정보"}</DialogTitle>
|
|
|
|
|
|
</DialogHeader>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="overflow-y-auto px-6 pb-6" style={{ maxHeight: "calc(90vh - 80px)" }}>
|
|
|
|
|
|
{popupLoading ? (
|
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
|
<div className="text-muted-foreground">화면을 불러오는 중...</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : popupLayout.length > 0 ? (
|
|
|
|
|
|
<div
|
|
|
|
|
|
className="bg-background relative rounded border"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
width: popupScreenResolution ? `${popupScreenResolution.width}px` : "100%",
|
|
|
|
|
|
height: popupScreenResolution ? `${popupScreenResolution.height}px` : "400px",
|
|
|
|
|
|
minHeight: "400px",
|
|
|
|
|
|
position: "relative",
|
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{/* 팝업에서도 실제 위치와 크기로 렌더링 */}
|
|
|
|
|
|
{popupLayout.map((popupComponent) => (
|
|
|
|
|
|
<div
|
|
|
|
|
|
key={popupComponent.id}
|
|
|
|
|
|
className="absolute"
|
|
|
|
|
|
style={{
|
|
|
|
|
|
left: `${popupComponent.position.x}px`,
|
|
|
|
|
|
top: `${popupComponent.position.y}px`,
|
|
|
|
|
|
width: popupComponent.style?.width || `${popupComponent.size.width}px`,
|
|
|
|
|
|
height: popupComponent.style?.height || `${popupComponent.size.height}px`,
|
|
|
|
|
|
zIndex: Math.min(popupComponent.position.z || 1, 20), // 최대 z-index 20으로 제한
|
|
|
|
|
|
}}
|
|
|
|
|
|
>
|
|
|
|
|
|
{/* 🎯 핵심 수정: 팝업 전용 formData 사용 */}
|
|
|
|
|
|
<InteractiveScreenViewer
|
|
|
|
|
|
component={popupComponent}
|
|
|
|
|
|
allComponents={popupLayout}
|
|
|
|
|
|
hideLabel={false}
|
|
|
|
|
|
screenInfo={popupScreenInfo || undefined}
|
|
|
|
|
|
formData={popupFormData}
|
|
|
|
|
|
onFormDataChange={(fieldName, value) => {
|
|
|
|
|
|
console.log("💾 팝업 formData 업데이트:", {
|
|
|
|
|
|
fieldName,
|
|
|
|
|
|
value,
|
|
|
|
|
|
valueType: typeof value,
|
|
|
|
|
|
prevFormData: popupFormData,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
setPopupFormData((prev) => ({
|
|
|
|
|
|
...prev,
|
|
|
|
|
|
[fieldName]: value,
|
|
|
|
|
|
}));
|
|
|
|
|
|
}}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
))}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
) : (
|
|
|
|
|
|
<div className="flex items-center justify-center py-8">
|
|
|
|
|
|
<div className="text-muted-foreground">화면 데이터가 없습니다.</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
)}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</DialogContent>
|
|
|
|
|
|
</Dialog>
|
2025-12-17 15:00:15 +09:00
|
|
|
|
</TableOptionsProvider>
|
|
|
|
|
|
</ActiveTabProvider>
|
2025-12-11 18:40:39 +09:00
|
|
|
|
</SplitPanelProvider>
|
2025-09-01 18:42:59 +09:00
|
|
|
|
);
|
|
|
|
|
|
};
|