From 489be4ce19095b3c7d3d3d63cf6574352b1432fc Mon Sep 17 00:00:00 2001 From: leedj312 Date: Tue, 25 Mar 2025 17:36:17 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B9=97=EB=AC=BC=EC=9D=B4=EC=9A=A9=EC=8B=9C?= =?UTF-8?q?=EC=84=A4=20=EB=93=B1=EB=A1=9D=20=EC=88=98=EC=A0=95=20=EB=B0=8F?= =?UTF-8?q?=20=EA=B3=B5=ED=86=B5=EC=BD=94=EB=93=9C=20api=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ruseFcltMng/fcltReg/rainReg/page.tsx | 41 ++++-- apps/wr/app/store/common/code/index.ts | 130 ++++++++++++++++++ apps/wr/app/store/index.tsx | 5 +- apps/wr/app/store/store.tsx | 13 +- apps/wr/components/lib/api/index.ts | 7 +- apps/wr/components/lib/config/env.ts | 5 + .../ui/form/fcltReg/rainReg/component.tsx | 63 +++++---- 7 files changed, 214 insertions(+), 50 deletions(-) create mode 100644 apps/wr/app/store/common/code/index.ts diff --git a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx index 74e4d48e0..77dbfb881 100644 --- a/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx +++ b/apps/wr/app/ruseFcltMng/fcltReg/rainReg/page.tsx @@ -1,11 +1,10 @@ 'use client' import { useWrStore } from "@/app/store"; -import type { TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg" +import type { bdstType, rainRuseType, TableUpperProps } from "@/app/store/ruseFcltMng/fcltReg/rainReg" import { RainRegForm } from "@/components/ui/form/fcltReg/rainReg/component"; import { ScrollArea, SearchDiv, SearchInput, UiTable } from "@common/business_components"; import { Button, TableHead, TableRow } from "@common/components"; -import { useEffect } from "react"; - +import { useEffect, useState } from "react"; export const headMakeColSpan = (upHeadList: TableUpperProps[]) => { return (<> @@ -20,17 +19,14 @@ export const headMakeColSpan = (upHeadList: TableUpperProps[]) => { ) } - - export default function Home() { - const { rain,init ,dataInit} = useWrStore((state) => { - console.log(state) + const { rain, code,init } = useWrStore((state) => { return state }); const {bdstObj, rainRuseObj } =rain - + const [rinBdstForm, setRinBdstForm] = useState (); + const [bdstTable, setbdstTable] = useState (); const nodeList = headMakeColSpan(rain.upHeadList); - const headName = () => { return (

○건축물 목록

@@ -38,12 +34,33 @@ export default function Home() { } useEffect(() => { - console.log(rain) if (!rain.isInit) { init(); } }, [rain.isInit,init]); + + useEffect ( () => { + if(code.sggCd.length>0){ + const table= bdstObj.map((item) => { + const sggText= code.sggCd.find((cd)=>cd.val.toString() === item.sggCd )?.text; + const cityText= code.cityCd.find((cd)=>cd.val.toString() === item.ctpvCd )?.text; + return( + {...item, + sggText:sggText, + cityText:cityText + }) + }) + setbdstTable(table) + } +}, [code,bdstObj]); + const cellClick=(val:number)=>{ + let data + if(bdstObj.length>0) { + data =rainRuseObj.filter((item)=> item.bdstInfoFk===val) + setRinBdstForm(data) + } + } return ( @@ -66,13 +83,13 @@ export default function Home() {
- + {nodeList}
- +
diff --git a/apps/wr/app/store/common/code/index.ts b/apps/wr/app/store/common/code/index.ts new file mode 100644 index 000000000..2bc1784a3 --- /dev/null +++ b/apps/wr/app/store/common/code/index.ts @@ -0,0 +1,130 @@ +import { getFectch } from "@/components/lib/api"; + +// Description: 공통코드 +type selectArray = { + text: string; + val: string | number; +}; + +export const bdstUsgCd: selectArray[] = [ + { val: 1, text: "운동장" }, + { val: 2, text: "체육관" }, + { val: 3, text: "공공업무시설" }, + { val: 4, text: "공공기관의청사" }, + { val: 5, text: "아파트" }, + { val: 6, text: "연립주택" }, + { val: 7, text: "다세대주택" }, + { val: 8, text: "기숙사" }, + { val: 9, text: "초등학교" }, + { val: 10, text: "중학교" }, + { val: 11, text: "고등학교" }, + { val: 12, text: "전문대학" }, + { val: 13, text: "대학및대학교" }, + { val: 14, text: "골프장" }, + { val: 15, text: "대규모점포" }, + { val: 16, text: "기타" }, +]; + +export const rainFcltCd = [ + { val: "1", text: "지붕" }, + { val: "2", text: "건물옥상" }, + { val: "3", text: "골프장 연못" }, + { val: "4", text: "운동장 바닥" }, + { val: "5", text: "운동장 지붕" }, + { val: "6", text: "주차장" }, + { val: "7", text: "태양광패널" }, + { val: "8", text: "연못" }, + { val: "9", text: "기타" }, + { val: "10", text: "확인불가" }, +]; + +export type comCodeState = { + code: { + isInit: boolean; + rainFcltCd: selectArray[]; + bdstUsgCd: selectArray[]; + cityCd: selectArray[]; + sggCd: selectArray[]; + }; +}; + +export type comCodeType = comCodeState & comCodeActions; + +export const getSggCd = async (set: any) => { + const sgg = await getFectch("common", "/addr/sgg"); + const sggCd = sgg.map((item: any) => ({ + val: item.sggCd, + text: item.sggKornNm, + })); + set((state: comCodeState) => ({ + code: { + ...state.code, + sggCd: sggCd, + }, + })); +}; +export const getCityCd = async (set: any) => { + const city = await getFectch("common", "/addr/city"); + const cityCd = city.map((item: any) => ({ + val: item.mctpvCd, + text: item.mctpvKornNm, + })); + set((state: comCodeState) => ({ + code: { + ...state.code, + cityCd: cityCd, + }, + })); +}; + +export const comCodeStateExport: comCodeState = { + code: { + isInit: false, + rainFcltCd: rainFcltCd, + bdstUsgCd: bdstUsgCd, + cityCd: [], + sggCd: [], + }, +}; + +export type comCodeActions = { + codeInit: () => void; +}; + + + + +export const codeActionExport: (set: any) => comCodeActions = (set: any) => { + return { + codeInit: async () => { + const sgg = await getFectch("common", "/addr/sgg"); + + const sggCd = sgg.map((item: any) => ({ + val: item.sggCd, + text: item.sggKornNm, + })); + + const city = await getFectch("common", "/addr/city"); + const cityCd = city.map((item: any) => ({ + val: item.mctpvCd, + text: item.mctpvKornNm, + })); + + return set((state: comCodeState) => ({ + code: { + ...state.code, + sggCd: sggCd, + cityCd: cityCd, + }, + })); + }, + divCityCd: async(cd: number) => { + set((state: comCodeState) => ({ + code: { + ...state.code, + sggCd:state.code.sggCd.filter((item) => { return Number(item.val.toString().slice(0,2)) === cd }), + }, + })); + }, + }; +}; diff --git a/apps/wr/app/store/index.tsx b/apps/wr/app/store/index.tsx index 1b759c30e..23b580772 100644 --- a/apps/wr/app/store/index.tsx +++ b/apps/wr/app/store/index.tsx @@ -1,4 +1,3 @@ -'use client' import { type ReactNode, createContext, useContext, useRef } from 'react' import { useStore } from 'zustand' @@ -15,12 +14,12 @@ export interface StoreProviderProps { children: ReactNode } -export const StoreProvider = ({ +export const StoreProvider = ({ children, }: StoreProviderProps) => { const storeRef = useRef(null) if (!storeRef.current) { - storeRef.current = StoreZus() + storeRef.current = StoreZus() } return ( diff --git a/apps/wr/app/store/store.tsx b/apps/wr/app/store/store.tsx index 18395789a..4a94a03fa 100644 --- a/apps/wr/app/store/store.tsx +++ b/apps/wr/app/store/store.tsx @@ -29,18 +29,22 @@ import { type htdflFacState, type htdflFacType, } from "./ruseFcltMng/fcltReg/htdflReg"; +import { codeActionExport, comCodeStateExport, getCityCd, getSggCd, type comCodeState, type comCodeType } from "./common/code"; -export type WrStore = pubFacType & +export type WrStore = comCodeType& + pubFacType & rainFacType & rswtFacType & matDmdType & htdflFacType; -export const StoreZus = ( - initState: rainFacState & +export const StoreZus = ( + initState: comCodeState& + rainFacState & pubFacState & rswtFacState & matDmdState & htdflFacState = { + ...comCodeStateExport, ...pubFacStateExport, ...rainFacStateExport, ...rswtFacStateExport, @@ -49,6 +53,8 @@ export const StoreZus = ( } ) => { return createStore()((set) => { + getSggCd(set), + getCityCd(set) return { ...initState, ...pubFacActionsExport(set), @@ -56,6 +62,7 @@ export const StoreZus = ( ...rswtFacActionsExport(set), ...matDmdActionsExport(set), ...htdflFacActionsExport(set), + ...codeActionExport(set), }; }); }; diff --git a/apps/wr/components/lib/api/index.ts b/apps/wr/components/lib/api/index.ts index 9d6114578..ff690f411 100644 --- a/apps/wr/components/lib/api/index.ts +++ b/apps/wr/components/lib/api/index.ts @@ -1,11 +1,12 @@ //8880 -import { DEV_URL_WR } from "../config/env"; +import { DEV_URL_COMMON, DEV_URL_WR } from "../config/env"; -export const getFectch = async (url: string) => { - const response = await fetch( DEV_URL_WR+url , { +export const getFectch = async( type:string , url: string) => { + const div = type === 'common' ? DEV_URL_COMMON : DEV_URL_WR + const response = await fetch( div+url , { method: "GET", headers: { accept: "application/json", diff --git a/apps/wr/components/lib/config/env.ts b/apps/wr/components/lib/config/env.ts index 82aaa5026..24352c2f3 100644 --- a/apps/wr/components/lib/config/env.ts +++ b/apps/wr/components/lib/config/env.ts @@ -2,5 +2,10 @@ const LOCAL_PORT = "3000"; const DEV_PORT = "8880"; + +const DEV_PORT_COMMON = "8881"; // common + export const LOCAL_URL_WR = `http://localhost:${LOCAL_PORT}/api/v1`; export const DEV_URL_WR = `http://192.168.1.193:${DEV_PORT}/api/v1`; + +export const DEV_URL_COMMON = `http:///192.168.1.193:${DEV_PORT_COMMON}/api/v1`; diff --git a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx index b5bfe4535..4748e042f 100644 --- a/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx +++ b/apps/wr/components/ui/form/fcltReg/rainReg/component.tsx @@ -7,18 +7,18 @@ import { useForm } from "react-hook-form"; import { z } from "zod"; import { FormUi } from "@common/business_components"; import { useWrStore } from "@/app/store"; -import { selectClass } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; +import { selectClass, type rainRuseType } from "@/app/store/ruseFcltMng/fcltReg/rainReg"; +import { useEffect } from "react"; const formSchema = z .object({ - facilityName: z.string().min(2).max(50), - instlCmptnDt: z.string(), - instlCst: z.string(), - chmaraKndCd: z.string(), - chmaraSz: z.string(), - chmaraYn: z.string(), - chmaraCpct: z.string(), - chmaraProcs: z.string(), + instlCmptnDt: z.date(), + instlCst: z.number(), + pntfColKnd: z.string(), + pntfColArea: z.number(), + filtrTrtmfctPrs: z.string(), + filtrTrtmfctYn: z.string(), + filtrTrtmfctCpct: z.string(), instlCstSprtYn: z.string(), instlCstSprtAmt: z.string(), grntchCstSprtYn: z.string(), @@ -28,22 +28,27 @@ const formSchema = z grntchBdstCertNo: z.string(), grntchBdstCertGrd: z.string(), }) - .readonly(); -export function RainRegForm() { - const { rain } = useWrStore((state) => state); +export function RainRegForm({data}:{data:rainRuseType[]} ) { + const { rain ,code} = useWrStore((state) => state); + const {rainFcltCd } = code + useEffect(() => { + console.log(data); + if (data && data.length > 0) { + form.reset(data[0]); // Assuming the first item matches the form schema + } + }, [data]); const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { - facilityName: "", - instlCmptnDt: "", - instlCst: "", - chmaraKndCd: "", - chmaraYn: "", - chmaraSz: "", - chmaraCpct: "", - chmaraProcs: "", + instlCmptnDt: new Date(), + instlCst: 0, + pntfColKnd: "", + pntfColArea: 0, + filtrTrtmfctYn: "N", + filtrTrtmfctCpct: "", + filtrTrtmfctPrs: "", instlCstSprtYn: "", instlCstSprtAmt: "", grntchCstSprtYn: "", @@ -87,9 +92,9 @@ export function RainRegForm() { field.onChange(e.target.value ? new Date(e.target.value) : undefined)} + value={field.value ? field.value.toISOString().split('T')[0] : ""} /> )} @@ -125,14 +130,14 @@ export function RainRegForm() {
( @@ -143,7 +148,7 @@ export function RainRegForm() {
( ( ( (