first init
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
const DEV_PORT_COMMON = "11081";
|
||||
const DEV_PORT_FO = "11082";
|
||||
const DEV_PORT_WR = "11080";
|
||||
|
||||
export const LOCAL_URL_COMMON = `http://192.168.1.129:${DEV_PORT_COMMON}/api/v1`;
|
||||
export const DEV_URL_COMMON = `http://con.mind-one.co.kr:${DEV_PORT_COMMON}/api/v1`;
|
||||
|
||||
export const LOCAL_URL_FO = `http://192.168.1.129:${DEV_PORT_FO}/api/v1`;
|
||||
export const DEV_URL_FO = `http://con.mind-one.co.kr:${DEV_PORT_FO}/api/v1`;
|
||||
|
||||
export const LOCAL_URL_WR = `http://192.168.1.129:${DEV_PORT_WR}/api/v1`;
|
||||
export const DEV_URL_WR = `http://con.mind-one.co.kr:${DEV_PORT_WR}/api/v1`;
|
||||
@@ -0,0 +1 @@
|
||||
export * from './env';
|
||||
@@ -0,0 +1,79 @@
|
||||
import { DEV_URL_COMMON, DEV_URL_FO, DEV_URL_WR } from "./config/env";
|
||||
|
||||
export const getFetch = async (part : string, url: string) => {
|
||||
let reqUrl = "";
|
||||
reqUrl = part === "fo" ? DEV_URL_FO+url : part === "wr" ? DEV_URL_WR+url : DEV_URL_COMMON+url;
|
||||
const response = await fetch(reqUrl , {
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
}
|
||||
});
|
||||
if(!response.ok) {
|
||||
throw new Error(`오류 발생: ${response.status}`);
|
||||
}
|
||||
const res = await response.json()
|
||||
return res;
|
||||
}
|
||||
|
||||
export const getFetchAreaList = async (url: string) => {
|
||||
const response = await fetch(url , {
|
||||
method: "GET",
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
}
|
||||
});
|
||||
if(!response.ok) {
|
||||
throw new Error(`오류 발생: ${response.status}`);
|
||||
}
|
||||
const res = await response.json()
|
||||
return res;
|
||||
}
|
||||
|
||||
export const postFetch = async (part : string, url: string, params: unknown) => {
|
||||
let reqUrl = "";
|
||||
reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_COMMON+url;
|
||||
const response = await fetch(reqUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
if(!response.ok) {
|
||||
throw new Error(`오류 발생: ${response.status}`);
|
||||
}
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
export const putFetch = async (part : string, url: string, params: unknown) => {
|
||||
let reqUrl = "";
|
||||
reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_COMMON+url;
|
||||
const response = await fetch(reqUrl, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
if(!response.ok) {
|
||||
throw new Error(`오류 발생: ${response.status}`);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
export const deleteFetch = async (part : string, url: string, params: unknown) => {
|
||||
let reqUrl = "";
|
||||
reqUrl = part === "fo" ? DEV_URL_FO+url : DEV_URL_COMMON+url;
|
||||
const response = await fetch(reqUrl, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(params),
|
||||
});
|
||||
if(!response.ok) {
|
||||
throw new Error(`오류 발생: ${response.status}`);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
type DataFormProps = {
|
||||
type: string;
|
||||
column: string;
|
||||
item: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export default function DataForm({ type, column, item }: DataFormProps) {
|
||||
if(item) {
|
||||
const value = item[column];
|
||||
switch(type){
|
||||
case 'date':
|
||||
if(value && typeof value === 'string' && value.length >= 8)
|
||||
item[column] = value.substring(0, 4) + "-" + value.substring(4, 6) + "-" + value.substring(6, 8);
|
||||
break;
|
||||
case 'number':
|
||||
if(value && value != '') {
|
||||
item[column] = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
case 'float1':
|
||||
if(value) {
|
||||
item[column] = String(value).includes('.')?String(Math.round(parseFloat(value.toString().replace(/,/g, '')) * 10) / 10).split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.')
|
||||
: String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
case 'float2':
|
||||
if(value) {
|
||||
item[column] = String(value).includes('.')?String(Math.round(parseFloat(value.toString().replace(/,/g, '')) * 100) / 100).split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.')
|
||||
: String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
case 'float3':
|
||||
if(value) {
|
||||
item[column] = String(value).includes('.')?String(Math.round(parseFloat(value.toString().replace(/,/g, '')) * 1000) / 1000).split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.')
|
||||
: String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import { useFoStore } from '@/app/store';
|
||||
import { DatePickerRange, SelectBox } from '@common/business_components/ui';
|
||||
import ListDiv from '@common/business_components/ui/list_div';
|
||||
import { Table, TableCell, TableHead, TableRow } from '@common/components/ui';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
type FacilityTermModalHeaderProps<T extends { msrDt: string }> = {
|
||||
fcltyCd : string;
|
||||
fcltyName: string;
|
||||
tabName: string;
|
||||
searchYear: string;
|
||||
searchList: T[];
|
||||
ref: React.RefObject<ReturnType<T>>;
|
||||
queryClick:(returnType:ReturnType<T>) => void;
|
||||
}
|
||||
|
||||
export type ReturnType<T> = {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
tabName: string;
|
||||
filteredList: T[];
|
||||
}
|
||||
|
||||
export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
searchList,
|
||||
fcltyName,
|
||||
tabName,
|
||||
searchYear,
|
||||
queryClick,
|
||||
ref
|
||||
}: FacilityTermModalHeaderProps<T & { msrDt: string }>) {
|
||||
const {Common} = useFoStore((state) => state);
|
||||
const { selectFlowPanel } = Common;
|
||||
const [startDate, setStartDate] = useState<Date>(new Date(Number(searchYear), 0, 1));
|
||||
const [endDate, setEndDate] = useState<Date>(new Date(Number(searchYear), 11, 31));
|
||||
const startPickerRef = useRef<HTMLDivElement>(null);
|
||||
const endPickerRef = useRef<HTMLDivElement>(null);
|
||||
const [flowPanel, setFlowPanel] = useState<string>(selectFlowPanel[0]?.val ?? '00');
|
||||
const [copySearchList, setCopySearchList] = useState<T[]>(searchList);
|
||||
const [standSearchList, setStandSearchList] = useState<T[]>(searchList);
|
||||
|
||||
const isDateInRanges = (date: Date) => {
|
||||
const standYear = parseInt(searchYear);
|
||||
const dateRanges = [];
|
||||
|
||||
if (tabName.includes("_summer")) {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 5, 1),
|
||||
end: new Date(standYear, 7, 31)
|
||||
});
|
||||
} else if (tabName.includes("_winter")) {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 0, 1),
|
||||
end: new Date(standYear, 1, 28)
|
||||
});
|
||||
} else {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 0, 1),
|
||||
end: new Date(standYear, 11, 31)
|
||||
});
|
||||
}
|
||||
|
||||
return dateRanges.some(range => {
|
||||
const start = new Date(range.start);
|
||||
const end = new Date(range.end);
|
||||
return date >= start && date <= end;
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
let startDate = new Date(Number(searchYear), 0, 1);
|
||||
let endDate = new Date(Number(searchYear), 11, 31);
|
||||
|
||||
if(tabName.includes("_summer")) {
|
||||
startDate = new Date(Number(searchYear), 5, 1);
|
||||
endDate = new Date(Number(searchYear), 7, 31);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else if (tabName.includes("_winter")) {
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 1, 28);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else {
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 11, 31);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
}
|
||||
|
||||
let filteredData: T[] = [];
|
||||
|
||||
if(tabName.includes("_rain")) {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const rainEffectDay = (item as T & { rainEffectDay: number }).rainEffectDay;
|
||||
if(flowPanel === '1') {
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay>0 && infoRnDay < 3;
|
||||
} else if(flowPanel === '2'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 3 && infoRnDay < 10;
|
||||
} else if(flowPanel === '3'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 10 && infoRnDay < 20;
|
||||
} else if(flowPanel === '4'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 20 && infoRnDay < 30;
|
||||
} else if(flowPanel === '5'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 30 && infoRnDay < 40;
|
||||
} else if(flowPanel === '6'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 40 && infoRnDay < 50;
|
||||
} else if(flowPanel === '7'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 50 && infoRnDay < 60;
|
||||
} else if(flowPanel === '8'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 60;
|
||||
} else {
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && (infoRnDay>0 || rainEffectDay ===1);
|
||||
}
|
||||
});
|
||||
} else if(tabName.includes("_chuncheon")) {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay==0;
|
||||
});
|
||||
} else {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
}
|
||||
|
||||
setCopySearchList(filteredData);
|
||||
setStandSearchList(filteredData);
|
||||
}, [searchList, searchYear, tabName, flowPanel]);
|
||||
|
||||
const handleStartDateSelect = (day: Date | undefined) => {
|
||||
if(day && day > endDate) {
|
||||
alert('종료일은 시작일 이전일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedDate = day ?? startDate;
|
||||
setStartDate(selectedDate);
|
||||
const button = startPickerRef.current?.querySelector('button');
|
||||
if (button) {
|
||||
setTimeout(() => button.click(), 0);
|
||||
}
|
||||
|
||||
const filteredData = standSearchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
setCopySearchList(filteredData);
|
||||
};
|
||||
|
||||
const handleEndDateSelect = (day: Date | undefined) => {
|
||||
if(day && day < startDate) {
|
||||
alert('종료일은 시작일 이후일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedDate = day ?? endDate;
|
||||
setEndDate(selectedDate);
|
||||
const button = endPickerRef.current?.querySelector('button');
|
||||
if (button) {
|
||||
setTimeout(() => button.click(), 0);
|
||||
}
|
||||
|
||||
const filteredData = standSearchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
setCopySearchList(filteredData);
|
||||
};
|
||||
|
||||
const fncSetFilteredList = useCallback(() => {
|
||||
queryClick({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
tabName: tabName,
|
||||
filteredList: copySearchList
|
||||
});
|
||||
}, [queryClick, startDate, endDate, tabName, copySearchList]);
|
||||
|
||||
useEffect(() => {
|
||||
fncSetFilteredList();
|
||||
}, [fncSetFilteredList]);
|
||||
|
||||
useEffect(() => {
|
||||
if(ref && ref.current) {
|
||||
const customRef = ref.current;
|
||||
customRef.startDate = startDate;
|
||||
customRef.endDate = endDate;
|
||||
customRef.tabName = tabName;
|
||||
customRef.filteredList = copySearchList;
|
||||
}
|
||||
}, [startDate, endDate, tabName, copySearchList, ref]);
|
||||
|
||||
return (
|
||||
<ListDiv className="!h-[80px]">
|
||||
<div className="!m-[0.5rem] max-h-[40rem] overflow-auto">
|
||||
<Table>
|
||||
<thead>
|
||||
<TableRow className="!h-[20px]">
|
||||
<TableHead className="w-[120px]">{'시설명'}</TableHead>
|
||||
{tabName === "tab_term_rain" ? <TableCell className="w-[300px]">{fcltyName}</TableCell> :
|
||||
<TableCell className="w-[380px]">{fcltyName}</TableCell>}
|
||||
{tabName === "tab_term_rain" && (
|
||||
<>
|
||||
<TableHead className="w-[120px]">{'강수구분'}</TableHead>
|
||||
<TableCell className="w-[250px]">
|
||||
<div className="justify-center">
|
||||
<SelectBox
|
||||
selectArray={selectFlowPanel}
|
||||
value={flowPanel}
|
||||
onSelectValue={(val) => setFlowPanel(val.toString())}
|
||||
className="mx-3 w-[150px]"
|
||||
label=""
|
||||
selectClass="w-full p-1 border rounded bg-white"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</>
|
||||
)}
|
||||
<TableHead className="w-[120px]">{'년/월'}</TableHead>
|
||||
<TableCell className="">
|
||||
<div className="flex">
|
||||
<div ref={startPickerRef} className="flex justify-center">
|
||||
<DatePickerRange
|
||||
mode="single"
|
||||
selected={startDate}
|
||||
onSelect={(date) => handleStartDateSelect(date as Date)}
|
||||
className="w-full p-1 border rounded bg-white"
|
||||
disabled={(date) => !isDateInRanges(date)}
|
||||
defaultMonth={startDate}
|
||||
/>
|
||||
</div>
|
||||
<h3 className="justify-center px-5">~</h3>
|
||||
<div ref={endPickerRef} className="flex justify-center">
|
||||
<DatePickerRange
|
||||
mode="single"
|
||||
selected={endDate}
|
||||
onSelect={(date) => handleEndDateSelect(date as Date)}
|
||||
className="w-full p-1 border rounded bg-white"
|
||||
disabled={(date) => !isDateInRanges(date)}
|
||||
defaultMonth={endDate}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</thead>
|
||||
</Table>
|
||||
</div>
|
||||
</ListDiv>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
import { useFoStore } from '@/app/store';
|
||||
import { SelectBox } from '@common/business_components/ui';
|
||||
import ListDiv from '@common/business_components/ui/list_div';
|
||||
import { DatePicker, Table, TableCell, TableHead, TableRow } from '@common/components/ui';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
type FacilityTermModalHeaderProps<T extends { msrDt: string }> = {
|
||||
fcltyCd : string;
|
||||
fcltyName: string;
|
||||
tabName: string;
|
||||
searchYear: string;
|
||||
searchList: T[];
|
||||
ref: React.RefObject<ReturnType<T>>;
|
||||
queryClick:(returnType:ReturnType<T>) => void;
|
||||
}
|
||||
|
||||
export type ReturnType<T> = {
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
tabName: string;
|
||||
filteredList: T[];
|
||||
}
|
||||
|
||||
export default function FacilityTermModalHeaderMonth<T extends { msrDt: string }>({
|
||||
searchList,
|
||||
fcltyName,
|
||||
tabName,
|
||||
searchYear,
|
||||
queryClick,
|
||||
ref
|
||||
}: FacilityTermModalHeaderProps<T & { msrDt: string }>) {
|
||||
const {Common} = useFoStore((state) => state);
|
||||
const { selectFlowPanel } = Common;
|
||||
const [startDate, setStartDate] = useState<Date>(new Date(Number(searchYear), 0, 1));
|
||||
const [endDate, setEndDate] = useState<Date>(new Date(Number(searchYear), 11, 31));
|
||||
const startPickerRef = useRef<HTMLDivElement>(null);
|
||||
const endPickerRef = useRef<HTMLDivElement>(null);
|
||||
const [flowPanel, setFlowPanel] = useState<string>(selectFlowPanel[0]?.val ?? '00');
|
||||
const [copySearchList, setCopySearchList] = useState<T[]>(searchList);
|
||||
|
||||
/* const isDateInRanges = (date: Date) => {
|
||||
const standYear = parseInt(searchYear);
|
||||
const dateRanges = [];
|
||||
|
||||
if (tabName.includes("_summer")) {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 5, 1),
|
||||
end: new Date(standYear, 7, 31)
|
||||
});
|
||||
} else if (tabName.includes("_winter")) {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 0, 1),
|
||||
end: new Date(standYear, 1, 28)
|
||||
});
|
||||
} else {
|
||||
dateRanges.push({
|
||||
start: new Date(standYear, 0, 1),
|
||||
end: new Date(standYear, 11, 31)
|
||||
});
|
||||
}
|
||||
|
||||
return dateRanges.some(range => {
|
||||
const start = new Date(range.start);
|
||||
const end = new Date(range.end);
|
||||
return date >= start && date <= end;
|
||||
});
|
||||
}; */
|
||||
|
||||
useEffect(() => {
|
||||
let startDate = new Date(Number(searchYear), 0, 1);
|
||||
let endDate = new Date(Number(searchYear), 11, 31);
|
||||
|
||||
if(tabName.includes("_summer")) {
|
||||
startDate = new Date(Number(searchYear), 5, 1);
|
||||
endDate = new Date(Number(searchYear), 7, 31);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else if (tabName.includes("_winter")) {
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 1, 28);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else {
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 11, 31);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
}
|
||||
|
||||
let filteredData: T[] = [];
|
||||
|
||||
if(tabName.includes("_rain")) {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const rainEffectDay = (item as T & { rainEffectDay: number }).rainEffectDay;
|
||||
|
||||
if(flowPanel === '1') {
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay>0 && infoRnDay < 3;
|
||||
} else if(flowPanel === '2'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 3 && infoRnDay < 10;
|
||||
} else if(flowPanel === '3'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 10 && infoRnDay < 20;
|
||||
} else if(flowPanel === '4'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 20 && infoRnDay < 30;
|
||||
} else if(flowPanel === '5'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 30 && infoRnDay < 40;
|
||||
} else if(flowPanel === '6'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 40 && infoRnDay < 50;
|
||||
} else if(flowPanel === '7'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 50 && infoRnDay < 60;
|
||||
} else if(flowPanel === '8'){
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 60;
|
||||
} else {
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && (infoRnDay>0 || rainEffectDay ===1);
|
||||
}
|
||||
});
|
||||
} else if(tabName.includes("_chuncheon")) {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const infoRnDay = (item as T & { infoRnDay: number }).infoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay==0;
|
||||
});
|
||||
} else {
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
}
|
||||
|
||||
setCopySearchList(filteredData);
|
||||
}, [searchList, searchYear, tabName, flowPanel]);
|
||||
|
||||
const handleStartDateSelect = (day: Date | undefined) => {
|
||||
if(day && day > endDate) {
|
||||
alert('종료일은 시작일 이전일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedDate = day ?? startDate;
|
||||
setStartDate(selectedDate);
|
||||
const button = startPickerRef.current?.querySelector('button');
|
||||
if (button) {
|
||||
setTimeout(() => button.click(), 0);
|
||||
}
|
||||
|
||||
const filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
setCopySearchList(filteredData);
|
||||
};
|
||||
|
||||
const handleEndDateSelect = (day: Date | undefined) => {
|
||||
if(day && day < startDate) {
|
||||
alert('종료일은 시작일 이후일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedDate = day ?? endDate;
|
||||
setEndDate(selectedDate);
|
||||
const button = endPickerRef.current?.querySelector('button');
|
||||
if (button) {
|
||||
setTimeout(() => button.click(), 0);
|
||||
}
|
||||
|
||||
const filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate());
|
||||
return itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly;
|
||||
});
|
||||
setCopySearchList(filteredData);
|
||||
};
|
||||
|
||||
const fncSetFilteredList = useCallback(() => {
|
||||
queryClick({
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
tabName: tabName,
|
||||
filteredList: copySearchList
|
||||
});
|
||||
}, [queryClick, startDate, endDate, tabName, copySearchList]);
|
||||
|
||||
useEffect(() => {
|
||||
fncSetFilteredList();
|
||||
}, [fncSetFilteredList]);
|
||||
|
||||
useEffect(() => {
|
||||
if(ref && ref.current) {
|
||||
const customRef = ref.current;
|
||||
customRef.startDate = startDate;
|
||||
customRef.endDate = endDate;
|
||||
customRef.tabName = tabName;
|
||||
customRef.filteredList = copySearchList;
|
||||
}
|
||||
}, [startDate, endDate, tabName, copySearchList, ref]);
|
||||
|
||||
return (
|
||||
<ListDiv className="!h-[100px]">
|
||||
<div className="card !m-[1.2rem] max-h-[40rem] overflow-auto !p-0r">
|
||||
<Table>
|
||||
<thead>
|
||||
<TableRow>
|
||||
<TableHead className="w-[120px]">{'시설명'}</TableHead>
|
||||
{tabName === "tab_term_rain" ? <TableCell className="w-[300px]">{fcltyName}</TableCell> :
|
||||
<TableCell className="w-[380px]">{fcltyName}</TableCell>}
|
||||
{tabName === "tab_term_rain" && (
|
||||
<>
|
||||
<TableHead className="w-[120px]">{'강수구분'}</TableHead>
|
||||
<TableCell className="w-[250px]">
|
||||
<div className="justify-center">
|
||||
<SelectBox
|
||||
selectArray={selectFlowPanel}
|
||||
value={flowPanel}
|
||||
onSelectValue={(val) => setFlowPanel(val.toString())}
|
||||
className="mx-3 w-[150px]"
|
||||
label=""
|
||||
selectClass="w-full p-1 border rounded bg-white"
|
||||
/>
|
||||
</div>
|
||||
</TableCell>
|
||||
</>
|
||||
)}
|
||||
<TableHead className="w-[120px]">{'년/월'}</TableHead>
|
||||
<TableCell className="">
|
||||
<div className="flex">
|
||||
<div ref={startPickerRef} className="flex justify-center">
|
||||
<DatePicker
|
||||
mode="single"
|
||||
selected={startDate}
|
||||
onSelect={(date) => handleStartDateSelect(date as Date)}
|
||||
className="w-full p-1 border rounded bg-white"
|
||||
defaultMonth={startDate}
|
||||
/>
|
||||
</div>
|
||||
<h3 className="justify-center px-5">~</h3>
|
||||
<div ref={endPickerRef} className="flex justify-center">
|
||||
<DatePicker
|
||||
mode="single"
|
||||
selected={endDate}
|
||||
onSelect={(date) => handleEndDateSelect(date as Date)}
|
||||
className="w-full p-1 border rounded bg-white"
|
||||
defaultMonth={endDate}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</thead>
|
||||
</Table>
|
||||
</div>
|
||||
</ListDiv>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { TableHead, TableRow } from "@common/components/ui";
|
||||
import type { TableUpperProps } from "../../store/dashboard";
|
||||
|
||||
const HeadMakeColSpan = ({ upHeadList, layoutNum }: { upHeadList: TableUpperProps[], layoutNum: string }) => {
|
||||
return (
|
||||
layoutNum === 'A' ? (
|
||||
<>
|
||||
<TableRow className="bg-gray-50">{upHeadList.map((head: TableUpperProps) =>
|
||||
(head.id === 'trtFrfNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'laeNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id == 'fctCpc' || head.id == 'planInputWaterQlty' || head.id == 'designInputWaterQlty' ? <TableHead rowSpan={2} className="w-40" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'trstOprEtpNm' ? <TableHead className="w-1/15" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.upName === 'upChangeRe' && head.upSequnce === 1 ? <TableHead className="bg-gray-50" style={{ whiteSpace: 'pre-line' }} key={head.id} rowSpan={1} colSpan={2}>{'행정구역'}</TableHead> :
|
||||
!head.upName ? <TableHead rowSpan={2} className="w-1/20 bg-gray-20" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> : null))}
|
||||
</TableRow>
|
||||
<TableRow className="bg-gray-50">
|
||||
{upHeadList.map((head: TableUpperProps) => {
|
||||
if (head.upName === 'upChangeRe') {
|
||||
return <TableHead key={head.id} style={{ whiteSpace: 'pre-line' }} className="w-40 bg-gray-50">{head.title}</TableHead>;
|
||||
}
|
||||
})}
|
||||
</TableRow>
|
||||
</>
|
||||
) : layoutNum === 'R' ? (
|
||||
<>
|
||||
<TableRow className="bg-gray-50">{upHeadList.map((head: TableUpperProps) =>
|
||||
(head.id === 'trtFrfNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'laeNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id == 'fctCpc' || head.id == 'planInputWaterQlty' || head.id == 'designInputWaterQlty' ? <TableHead rowSpan={2} className="w-40" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'trstOprEtpNm' ? <TableHead className="w-1/15" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.upName === 'upChangeRe' && head.upSequnce === 1 ? <TableHead className="w-75 bg-gray-50" style={{ whiteSpace: 'pre-line' }} key={head.id} rowSpan={1} colSpan={3}>{'유역'}</TableHead> :
|
||||
!head.upName ? <TableHead rowSpan={2} className="w-1/20 bg-gray-20" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> : null))}
|
||||
</TableRow>
|
||||
<TableRow className="bg-gray-50">
|
||||
{upHeadList.map((head: TableUpperProps) => {
|
||||
if (head.upName === 'upChangeRe') {
|
||||
return <TableHead key={head.id} style={{ whiteSpace: 'pre-line' }} className="w-40 bg-gray-50">{head.title}</TableHead>;
|
||||
}
|
||||
})}
|
||||
</TableRow>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<TableRow className="bg-gray-50">{upHeadList.map((head: TableUpperProps) =>
|
||||
(head.id === 'trtFrfNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'laeNm' ? <TableHead className="w-1/12" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.id == 'fctCpc' || head.id == 'planInputWaterQlty' || head.id == 'designInputWaterQlty' ? <TableHead rowSpan={2} className="w-40" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> :
|
||||
head.id === 'trstOprEtpNm' ? <TableHead className="w-1/15" rowSpan={2} key={head.id}>{head.title}</TableHead> :
|
||||
head.upName === 'upChangeRe1' && head.upSequnce === 1 ? <TableHead className="w-75 bg-gray-50" style={{ whiteSpace: 'pre-line' }} key={head.id} rowSpan={1} colSpan={3}>{'권역'}</TableHead> :
|
||||
head.upName === 'upChangeRe2' && head.upSequnce === 1 ? <TableHead className="w-75 bg-gray-50" style={{ whiteSpace: 'pre-line' }} key={head.id} rowSpan={1} colSpan={2}>{'행정구역'}</TableHead> :
|
||||
!head.upName ? <TableHead rowSpan={2} className="w-1/20 bg-gray-20" style={{ whiteSpace: 'pre-line' }} key={head.id}>{head.title}</TableHead> : null))}
|
||||
</TableRow>
|
||||
<TableRow className="bg-gray-50">
|
||||
{upHeadList.map((head: TableUpperProps) => {
|
||||
if (head.upName === 'upChangeRe1' || head.upName === 'upChangeRe2') {
|
||||
return <TableHead key={head.id} style={{ whiteSpace: 'pre-line' }} className="w-40 bg-gray-50">{head.title}</TableHead>;
|
||||
}
|
||||
})}
|
||||
</TableRow>
|
||||
</>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export { HeadMakeColSpan };
|
||||
@@ -0,0 +1,108 @@
|
||||
import { useFoStore } from '@/app/store';
|
||||
import type { facilityListProps } from '@/app/store/processFacility';
|
||||
import { Label } from '@common/components/ui';
|
||||
import React, { useEffect, useState, useRef, useCallback } from 'react'
|
||||
|
||||
type thisProps = {
|
||||
label: string | undefined;
|
||||
setValue : (fcltyCd?: string, fcltyNm?: string, fcltyCpc?: number | '', trtFrfNm?: string | '', efflWqltStndrdNm?: string | '') => void;
|
||||
sidoSigun? : string | undefined;
|
||||
fcltyName? : string | undefined;
|
||||
}
|
||||
|
||||
export default function SearchInputText({label=undefined, setValue=()=>{}, sidoSigun=undefined, fcltyName=undefined} :thisProps) {
|
||||
|
||||
const { ProcessFacilityList, searchProcessFacilitySearching } = useFoStore((state) => state);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [textValue, setTextValue] = useState(fcltyName || '');
|
||||
const wrapperRef = useRef<HTMLDivElement>(null);
|
||||
const processFacilityList = ProcessFacilityList?.processFacilityList || [];
|
||||
|
||||
const handleInputChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const value = e.target.value;
|
||||
setTextValue(value);
|
||||
if (value) {
|
||||
setIsOpen(true);
|
||||
if(sidoSigun) {
|
||||
searchProcessFacilitySearching(1, 4999, 'A', sidoSigun, '0', '0', '0', value);
|
||||
} else {
|
||||
searchProcessFacilitySearching(1, 4999, '0', '0', '0', '0', '0', value);
|
||||
}
|
||||
} else {
|
||||
setIsOpen(false);
|
||||
}
|
||||
}, [searchProcessFacilitySearching, sidoSigun]);
|
||||
|
||||
const onInputFocus = useCallback(() => {
|
||||
setIsOpen(true);
|
||||
if(sidoSigun) {
|
||||
searchProcessFacilitySearching(1, 4999, 'A', sidoSigun, '0', '0', '0');
|
||||
} else {
|
||||
searchProcessFacilitySearching(1, 4999, '0', '0', '0', '0', '0');
|
||||
}
|
||||
}, [searchProcessFacilitySearching, sidoSigun]);
|
||||
|
||||
useEffect(() => {
|
||||
setTextValue(fcltyName || '');
|
||||
}, [fcltyName]);
|
||||
|
||||
const handleSuggestionClick = useCallback((bscFctCd: string, bscFctNm: string, fctCpc: number | '', trtFrfNm: string | '', efflWqltStndrdNm: string | '') => {
|
||||
console.log('bscFctNm : ', bscFctNm);
|
||||
console.log('bscFctCd : ', bscFctCd);
|
||||
console.log('fctCpc : ', fctCpc);
|
||||
console.log('trtFrfNm : ', trtFrfNm);
|
||||
console.log('efflWqltStndrdNm : ', efflWqltStndrdNm);
|
||||
setTextValue(bscFctNm);
|
||||
setValue(bscFctCd, bscFctNm, fctCpc, trtFrfNm, efflWqltStndrdNm);
|
||||
setIsOpen(false);
|
||||
}, [setValue]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (wrapperRef.current && !wrapperRef.current.contains(event.target as Node)) {
|
||||
setIsOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={'relative'} ref={wrapperRef}>
|
||||
{label && <Label className="w-20 text-xl text-gray-600 justify-self-center">{label}</Label>}
|
||||
<input
|
||||
type="text"
|
||||
value={textValue}
|
||||
onChange={handleInputChange}
|
||||
onFocus={onInputFocus}
|
||||
className="w-[200px] ml-6 px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
placeholder={`${label}을(를) 입력하세요`}
|
||||
/>
|
||||
{isOpen && processFacilityList.length > 0 && (
|
||||
<div className="absolute z-10 w-[300px] px-2 py-1 !mt-5 ml-20 bg-white border border-gray-300 rounded-md shadow-lg h-90 overflow-auto">
|
||||
<div className="max-h-72">
|
||||
{processFacilityList.map((item : facilityListProps, index : number) => (
|
||||
<div
|
||||
key={index}
|
||||
className="w-full text-left pl-1 pr-10 py-2 hover:bg-gray-100 cursor-pointer overflow-auto"
|
||||
onClick={() => handleSuggestionClick(item.bscFctCd, item.bscFctNm, Number(item.fctCpc), item.trtFrfNm, item.efflWqltStndrdNm)}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
handleSuggestionClick(item.bscFctCd, item.bscFctNm, Number(item.fctCpc), item.trtFrfNm, item.efflWqltStndrdNm);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{item.sido} {item.gugun} <span className="float-right">{item.bscFctNm}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user