모달창 윈도우 팝업 전면 수정

This commit is contained in:
kiminchan
2026-04-27 13:30:59 +09:00
parent f507afdfe9
commit 0b7a264f06
48 changed files with 1708 additions and 477 deletions
+14
View File
@@ -0,0 +1,14 @@
export { openWindowPopup } from "./lib/openWindowPopup";
export {
isWindowPopupKey,
windowPopupDefinitions,
type WindowPopupKey,
} from "./model/popupDefinitions";
export { windowPopupRegistry } from "./registry";
export type {
OpenWindowPopupParams,
WindowPopupContentProps,
WindowPopupMessageType,
WindowPopupSearchParams,
} from "./model/types";
export { WINDOW_POPUP_MESSAGE_TYPE } from "./model/types";
@@ -0,0 +1,61 @@
import {
isWindowPopupKey,
windowPopupDefinitions,
type WindowPopupKey,
} from "../model/popupDefinitions";
import type { OpenWindowPopupParams } from "../model/types";
const buildQueryString = (params: OpenWindowPopupParams = {}) => {
const searchParams = new URLSearchParams();
Object.entries(params).forEach(([key, value]) => {
if (value === null || value === undefined || value === "") return;
searchParams.set(key, String(value));
});
const queryString = searchParams.toString();
return queryString ? `?${queryString}` : "";
};
const buildPopupFeatures = (width: number, height: number) => {
const screenLeft = window.screenX ?? window.screenLeft ?? 0;
const screenTop = window.screenY ?? window.screenTop ?? 0;
const outerWidth = window.outerWidth || window.screen.width;
const outerHeight = window.outerHeight || window.screen.height;
const left = Math.max(0, screenLeft + Math.round((outerWidth - width) / 2));
const top = Math.max(0, screenTop + Math.round((outerHeight - height) / 2));
return [
`width=${width}`,
`height=${height}`,
`left=${left}`,
`top=${top}`,
"resizable=yes",
"scrollbars=yes",
"status=no",
"location=no",
"menubar=no",
"toolbar=no",
].join(",");
};
export const openWindowPopup = (
popupKey: WindowPopupKey,
params?: OpenWindowPopupParams,
) => {
if (typeof window === "undefined") return null;
if (!isWindowPopupKey(popupKey)) return null;
const definition = windowPopupDefinitions[popupKey];
const popupUrl = `/popup/${popupKey}${buildQueryString(params)}`;
const popupFeatures = buildPopupFeatures(definition.width, definition.height);
const popupWindow = window.open(
popupUrl,
`sn-popup-${popupKey}`,
popupFeatures,
);
popupWindow?.focus();
return popupWindow;
};
@@ -0,0 +1,24 @@
import type { WindowPopupMessageType } from "../model/types";
export const postPopupMessage = (
type: WindowPopupMessageType,
payload?: Record<string, string>,
) => {
if (typeof window === "undefined" || !window.opener) return;
window.opener.postMessage(
{
type,
payload,
},
window.location.origin,
);
};
export const postPopupMessageAndClose = (
type: WindowPopupMessageType,
payload?: Record<string, string>,
) => {
postPopupMessage(type, payload);
window.close();
};
@@ -0,0 +1,76 @@
import type { WindowPopupDefinition } from "./types";
export const windowPopupDefinitions = {
oldPpUpload: {
key: "oldPpUpload",
title: "노후 하수관로 정비사업 등록",
width: 860,
height: 360,
},
oldPpTable: {
key: "oldPpTable",
title: "노후 하수관로 정비사업 상세",
width: 1400,
height: 900,
requiredParams: ["fileNm", "atflId"],
},
floodPreUpload: {
key: "floodPreUpload",
title: "도시침수 예방사업 등록",
width: 860,
height: 360,
},
floodPreTable: {
key: "floodPreTable",
title: "도시침수 예방사업 상세",
width: 1400,
height: 900,
requiredParams: ["fileNm", "atflId"],
},
reportTab: {
key: "reportTab",
title: "하수도정비 기본계획보고서",
width: 1280,
height: 920,
},
reportFiles: {
key: "reportFiles",
title: "보고서 파일 목록",
width: 860,
height: 720,
requiredParams: ["clsfSystmSn"],
},
mapSearch: {
key: "mapSearch",
title: "관망도 검색",
width: 1280,
height: 980,
},
infilChart: {
key: "infilChart",
title: "침입수 분석",
width: 1360,
height: 980,
requiredParams: ["pplMngNo"],
},
rdiiChart: {
key: "rdiiChart",
title: "RDII 분석",
width: 1360,
height: 980,
requiredParams: ["pplMngNo"],
},
sscDetail: {
key: "sscDetail",
title: "중점우수토실 운영정보",
width: 1180,
height: 980,
requiredParams: ["chmbrXcnts", "chmbrYdnts"],
},
} as const satisfies Record<string, WindowPopupDefinition>;
export type WindowPopupKey = keyof typeof windowPopupDefinitions;
export const isWindowPopupKey = (key: string): key is WindowPopupKey => {
return key in windowPopupDefinitions;
};
@@ -0,0 +1,37 @@
import type { ComponentType } from "react";
export type WindowPopupSearchParams = Record<
string,
string | string[] | undefined
>;
export type WindowPopupContentProps = {
searchParams: WindowPopupSearchParams;
};
export type WindowPopupDefinition = {
key: string;
title: string;
width: number;
height: number;
requiredParams?: string[];
};
export type WindowPopupRegistryItem = WindowPopupDefinition & {
component: ComponentType<WindowPopupContentProps>;
};
export type OpenWindowPopupParams = Record<
string,
string | number | boolean | null | undefined
>;
export const WINDOW_POPUP_MESSAGE_TYPE = {
OLD_PP_UPLOAD_COMPLETED: "sn:popup:oldPpUploadCompleted",
FLOOD_PRE_UPLOAD_COMPLETED: "sn:popup:floodPreUploadCompleted",
MAP_SEARCH_SELECT_FEATURE: "sn:popup:mapSearchSelectFeature",
MAP_SEARCH_SHOW_MULTIPLE: "sn:popup:mapSearchShowMultiple",
} as const;
export type WindowPopupMessageType =
(typeof WINDOW_POPUP_MESSAGE_TYPE)[keyof typeof WINDOW_POPUP_MESSAGE_TYPE];
@@ -0,0 +1,55 @@
import { windowPopupDefinitions, type WindowPopupKey } from "./model/popupDefinitions";
import type { WindowPopupRegistryItem } from "./model/types";
import FloodPreTablePopupContent from "./ui/FloodPreTablePopupContent";
import FloodPreUploadPopupContent from "./ui/FloodPreUploadPopupContent";
import InfilChartPopupContent from "./ui/InfilChartPopupContent";
import OldPpUploadPopupContent from "./ui/OldPpUploadPopupContent";
import OldPpTablePopupContent from "./ui/OldPpTablePopupContent";
import RdiiChartPopupContent from "./ui/RdiiChartPopupContent";
import ReportFilesPopupContent from "./ui/ReportFilesPopupContent";
import ReportTabPopupContent from "./ui/ReportTabPopupContent";
import SearchModalPopupContent from "./ui/SearchModalPopupContent";
import SscDetailPopupContent from "./ui/SscDetailPopupContent";
export const windowPopupRegistry = {
oldPpUpload: {
...windowPopupDefinitions.oldPpUpload,
component: OldPpUploadPopupContent,
},
oldPpTable: {
...windowPopupDefinitions.oldPpTable,
component: OldPpTablePopupContent,
},
floodPreUpload: {
...windowPopupDefinitions.floodPreUpload,
component: FloodPreUploadPopupContent,
},
floodPreTable: {
...windowPopupDefinitions.floodPreTable,
component: FloodPreTablePopupContent,
},
reportTab: {
...windowPopupDefinitions.reportTab,
component: ReportTabPopupContent,
},
reportFiles: {
...windowPopupDefinitions.reportFiles,
component: ReportFilesPopupContent,
},
mapSearch: {
...windowPopupDefinitions.mapSearch,
component: SearchModalPopupContent,
},
infilChart: {
...windowPopupDefinitions.infilChart,
component: InfilChartPopupContent,
},
rdiiChart: {
...windowPopupDefinitions.rdiiChart,
component: RdiiChartPopupContent,
},
sscDetail: {
...windowPopupDefinitions.sscDetail,
component: SscDetailPopupContent,
},
} as const satisfies Record<WindowPopupKey, WindowPopupRegistryItem>;
@@ -0,0 +1,36 @@
import TableModal from "@/app/(with-base-layout)/oper/floodPre/tableModal";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
export default function FloodPreTablePopupContent({
searchParams,
}: WindowPopupContentProps) {
const fileNm = getPopupParamValue(searchParams.fileNm);
const atflId = getPopupParamValue(searchParams.atflId);
const missingParams = [
!fileNm ? "fileNm" : "",
!atflId ? "atflId" : "",
].filter(Boolean);
if (missingParams.length > 0) {
return (
<PopupMissingParams
title={windowPopupDefinitions.floodPreTable.title}
missingParams={missingParams}
/>
);
}
return (
<div className="flex h-dvh flex-col overflow-hidden bg-white p-4">
<h1 className="mb-3 shrink-0 text-2xl font-semibold">
{windowPopupDefinitions.floodPreTable.title}
</h1>
<div className="min-h-0 flex-1 overflow-hidden">
<TableModal fileNm={fileNm} atflId={atflId} />
</div>
</div>
);
}
@@ -0,0 +1,42 @@
"use client";
import { postData } from "@/components/lib/api";
import OperFileUploadForm from "@/components/ui/operFileUploadForm";
import { tokenManager } from "@/entities/auth/lib/token-manager";
import { AUTH_USER_ID } from "@/shared/config";
import { postPopupMessageAndClose } from "../lib/popupMessage";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import { WINDOW_POPUP_MESSAGE_TYPE } from "../model/types";
export default function FloodPreUploadPopupContent() {
const handleSubmit = async (
fileNm: string,
year: string,
quater: string,
cd: string,
id: string,
) => {
const data = await postData("v1/sbmrgPrevnt", {
mngYr: year,
mngQu: quater,
atflId: id,
atflCd: cd,
rgtr: tokenManager.getToken(AUTH_USER_ID) || null,
sbmrgPrevntBizNm: fileNm,
});
if (data) {
alert("파일이 등록되었습니다.");
postPopupMessageAndClose(WINDOW_POPUP_MESSAGE_TYPE.FLOOD_PRE_UPLOAD_COMPLETED);
}
};
return (
<div className="min-h-dvh bg-white p-4">
<OperFileUploadForm
title={windowPopupDefinitions.floodPreUpload.title}
onSubmit={handleSubmit}
/>
</div>
);
}
@@ -0,0 +1,22 @@
import InfilChart from "@/app/(map-layout)/map/components/popupComponent/chart/infilChart";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
export default function InfilChartPopupContent({
searchParams,
}: WindowPopupContentProps) {
const pplMngNo = getPopupParamValue(searchParams.pplMngNo);
if (!pplMngNo) {
return (
<PopupMissingParams
title={windowPopupDefinitions.infilChart.title}
missingParams={["pplMngNo"]}
/>
);
}
return <InfilChart pplMngNo={pplMngNo} />;
}
@@ -0,0 +1,36 @@
import TableModal from "@/app/(with-base-layout)/oper/oldPp/tableModal";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
export default function OldPpTablePopupContent({
searchParams,
}: WindowPopupContentProps) {
const fileNm = getPopupParamValue(searchParams.fileNm);
const atflId = getPopupParamValue(searchParams.atflId);
const missingParams = [
!fileNm ? "fileNm" : "",
!atflId ? "atflId" : "",
].filter(Boolean);
if (missingParams.length > 0) {
return (
<PopupMissingParams
title={windowPopupDefinitions.oldPpTable.title}
missingParams={missingParams}
/>
);
}
return (
<div className="flex h-dvh flex-col overflow-hidden bg-white p-4">
<h1 className="mb-3 shrink-0 text-2xl font-semibold">
{windowPopupDefinitions.oldPpTable.title}
</h1>
<div className="min-h-0 flex-1 overflow-hidden">
<TableModal fileNm={fileNm} atflId={atflId} />
</div>
</div>
);
}
@@ -0,0 +1,42 @@
"use client";
import { postData } from "@/components/lib/api";
import OperFileUploadForm from "@/components/ui/operFileUploadForm";
import { tokenManager } from "@/entities/auth/lib/token-manager";
import { AUTH_USER_ID } from "@/shared/config";
import { postPopupMessageAndClose } from "../lib/popupMessage";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import { WINDOW_POPUP_MESSAGE_TYPE } from "../model/types";
export default function OldPpUploadPopupContent() {
const handleSubmit = async (
fileNm: string,
year: string,
quater: string,
cd: string,
id: string,
) => {
const data = await postData("v1/dcrpPpl", {
mngYr: year,
mngQu: quater,
atflCd: cd,
atflId: id,
rgtr: tokenManager.getToken(AUTH_USER_ID) || null,
dcrpPplMtncBizNm: fileNm,
});
if (data) {
alert("파일이 등록되었습니다.");
postPopupMessageAndClose(WINDOW_POPUP_MESSAGE_TYPE.OLD_PP_UPLOAD_COMPLETED);
}
};
return (
<div className="min-h-dvh bg-white p-4">
<OperFileUploadForm
title={windowPopupDefinitions.oldPpUpload.title}
onSubmit={handleSubmit}
/>
</div>
);
}
@@ -0,0 +1,19 @@
export default function PopupMissingParams({
title,
missingParams,
}: {
title: string;
missingParams: string[];
}) {
return (
<section className="flex min-h-dvh flex-col items-center justify-center gap-4 p-8 text-center">
<h1 className="text-2xl font-semibold">{title}</h1>
<p className="text-base text-gray-600">
팝업을 여는 데 필요한 값이 누락되었습니다.
</p>
<p className="text-sm text-gray-500">
누락된 값: {missingParams.join(", ")}
</p>
</section>
);
}
@@ -0,0 +1,22 @@
import RdiiChart from "@/app/(map-layout)/map/components/popupComponent/chart/rdiiChart";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
export default function RdiiChartPopupContent({
searchParams,
}: WindowPopupContentProps) {
const pplMngNo = getPopupParamValue(searchParams.pplMngNo);
if (!pplMngNo) {
return (
<PopupMissingParams
title={windowPopupDefinitions.rdiiChart.title}
missingParams={["pplMngNo"]}
/>
);
}
return <RdiiChart pplMngNo={pplMngNo} />;
}
@@ -0,0 +1,121 @@
"use client";
import { useEffect, useState } from "react";
import LoadingOverlay from "@/components/ui/LoadingBar";
import { getDcData } from "@/components/lib/api";
import { UiTable } from "@common/business_components/ui";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
type ReportDataFile = {
no?: number;
fileTitle: string;
regDt: string;
fileSn: string;
filePath: string;
};
const REPORT_FILES_HEADLIST = [
{ id: "no", title: "NO" },
{ id: "fileTitle", title: "파일명" },
{ id: "regDt", title: "등록일자" },
];
export default function ReportFilesPopupContent({
searchParams,
}: WindowPopupContentProps) {
const clsfSystmSn = getPopupParamValue(searchParams.clsfSystmSn);
const [files, setFiles] = useState<ReportDataFile[]>([]);
const [allFiles, setAllFiles] = useState<ReportDataFile[]>([]);
const [curPage, setCurPage] = useState(1);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (!clsfSystmSn) return;
const fetchFiles = async () => {
setIsLoading(true);
try {
const result = await getDcData(`/api/v1/file?clsfSystmSn=${clsfSystmSn}`);
const normalized = (result ?? []).map((item: ReportDataFile, index: number) => ({
...item,
no: index + 1,
}));
setAllFiles(normalized);
} catch (error) {
console.error("보고서 파일 목록 조회 실패:", error);
setAllFiles([]);
} finally {
setIsLoading(false);
}
};
fetchFiles();
}, [clsfSystmSn]);
useEffect(() => {
const paged = allFiles.slice((curPage - 1) * 10, curPage * 10);
setFiles(paged);
}, [allFiles, curPage]);
const handleDownload = async (fileSn: string, fileTitle: string, filePath: string) => {
if (!filePath) {
alert("filePath 정보가 없으므로 다운로드가 불가합니다.");
return;
}
try {
const responseBlob = await getDcData(
`/api/v1/fileDownload?filePath=${encodeURIComponent(filePath)}`,
"blob",
);
const objectUrl = URL.createObjectURL(responseBlob);
const anchor = document.createElement("a");
anchor.href = objectUrl;
anchor.download = fileTitle;
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(objectUrl);
} catch (error) {
console.error("보고서 파일 다운로드 실패:", error);
alert("파일 다운로드 중 오류가 발생했습니다.");
}
};
if (!clsfSystmSn) {
return (
<PopupMissingParams
title={windowPopupDefinitions.reportFiles.title}
missingParams={["clsfSystmSn"]}
/>
);
}
return (
<div className="flex h-dvh flex-col overflow-hidden bg-white p-4">
<h1 className="mb-3 shrink-0 text-2xl font-semibold">
{windowPopupDefinitions.reportFiles.title}
</h1>
<div className="min-h-0 flex-1 overflow-auto">
<LoadingOverlay isLoading={isLoading} />
<UiTable
headName={`조회 결과 (${allFiles.length.toLocaleString("ko-KR")})건`}
tableData={files}
headlist={REPORT_FILES_HEADLIST}
pageSize={10}
total={allFiles.length}
onPageChange={setCurPage}
cellClick={(index) => {
if (typeof index !== "number" || !files[index]) return;
const target = files[index];
handleDownload(target.fileSn, target.fileTitle, target.filePath);
}}
/>
</div>
</div>
);
}
@@ -0,0 +1,27 @@
import ReportTab from "@/app/(map-layout)/map/searchModal/reportTab";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import { getPopupParamValue } from "./popupContentUtils";
export default function ReportTabPopupContent({
searchParams,
}: WindowPopupContentProps) {
const ctpvNm = getPopupParamValue(searchParams.ctpvNm);
const sggNm = getPopupParamValue(searchParams.sggNm);
return (
<div className="flex h-dvh flex-col overflow-hidden bg-white p-4">
<h1 className="mb-3 shrink-0 text-2xl font-semibold">
{windowPopupDefinitions.reportTab.title}
</h1>
<div className="min-h-0 flex-1 overflow-hidden">
<ReportTab
open={true}
isSearch={false}
ctpvNm={ctpvNm || undefined}
sggNm={sggNm || undefined}
/>
</div>
</div>
);
}
@@ -0,0 +1,5 @@
import SearchModal from "@/app/(map-layout)/map/searchModal/searchModal";
export default function SearchModalPopupContent() {
return <SearchModal renderMode="popup" />;
}
@@ -0,0 +1,36 @@
import Ssc from "@/app/(map-layout)/map/components/popupComponent/Ssc";
import { windowPopupDefinitions } from "../model/popupDefinitions";
import type { WindowPopupContentProps } from "../model/types";
import PopupMissingParams from "./PopupMissingParams";
import { getPopupParamValue } from "./popupContentUtils";
export default function SscDetailPopupContent({
searchParams,
}: WindowPopupContentProps) {
const chmbrXcnts = getPopupParamValue(searchParams.chmbrXcnts);
const chmbrYdnts = getPopupParamValue(searchParams.chmbrYdnts);
const missingParams = [
!chmbrXcnts ? "chmbrXcnts" : "",
!chmbrYdnts ? "chmbrYdnts" : "",
].filter(Boolean);
if (missingParams.length > 0) {
return (
<PopupMissingParams
title={windowPopupDefinitions.sscDetail.title}
missingParams={missingParams}
/>
);
}
return (
<Ssc
featureData={null}
isMainSsc={true}
chmbrXcnts={chmbrXcnts}
chmbrYdnts={chmbrYdnts}
renderMode="popup"
/>
);
}
@@ -0,0 +1,6 @@
export const getPopupParamValue = (
value: string | string[] | undefined,
): string => {
if (Array.isArray(value)) return value[0] ?? "";
return value ?? "";
};