api 작업진행중
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
const BASE_URL = process.env.NEXT_PUBLIC_SEWERAGE_API_URL || '';
|
||||
|
||||
export const postData = async (url: string, data: object): Promise<any> => {
|
||||
const options: RequestInit = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
const res = await fetch(`${BASE_URL}/${url}`, options);
|
||||
const resData = await res.json();
|
||||
return resData;
|
||||
};
|
||||
|
||||
export const postMutiPart = async (url: string, data: FormData): Promise<any> => {
|
||||
const options: RequestInit = {
|
||||
method: "POST",
|
||||
body: data,
|
||||
};
|
||||
const res = await fetch(`${BASE_URL}/${url}`, options);
|
||||
const resData = await res.json();
|
||||
return resData;
|
||||
};
|
||||
|
||||
export const putData = async (url: string, data: object): Promise<any> => {
|
||||
const options: RequestInit = {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
const res = await fetch(`${BASE_URL}/${url}`, options);
|
||||
const resData = await res.json();
|
||||
return resData;
|
||||
};
|
||||
|
||||
export const getData = async (url: string): Promise<any> => {
|
||||
const res = await fetch(`${BASE_URL}/${url}`, {
|
||||
method: "GET",
|
||||
});
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
return data;
|
||||
}
|
||||
throw new Error('Failed to fetch data');
|
||||
};
|
||||
|
||||
export const deleteData = async (url: string, data?: object): Promise<any> => {
|
||||
const options: RequestInit = {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: data ? JSON.stringify(data) : undefined,
|
||||
};
|
||||
const res = await fetch(`${BASE_URL}/${url}`, options);
|
||||
const resData = await res.json();
|
||||
return resData;
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import { Button, Table, TableBody, TableCell, TableHead, TableHeader, TableRow }
|
||||
import { use, useEffect, useState } from "react";
|
||||
import { SwtrmtFcltCol } from "./table";
|
||||
import { useGisContext } from "@common/business_components/ui/map/Gis";
|
||||
import { getData } from "@/components/lib/api";
|
||||
const inputColumn = [
|
||||
{ id: "title", title: "설치주제", type: "select", options: ["BTL", "재정사업"] },
|
||||
{ id: "guyeok", title: "처리구역", type: "select", options: ["구역1", "구역2"] },
|
||||
@@ -16,7 +17,7 @@ const inputColumn = [
|
||||
// TODO:
|
||||
const FeatureClickEventPopup = ({ onClose, featureData }: { onClose: () => void, featureData: any }) => {
|
||||
const { gisMap } = useGisContext() as unknown as { checkedLayerIds: React.MutableRefObject<number[]>; treeData: { lyrSn: number }[] | null; gisCore: any; gisMap: any; };
|
||||
const featureProperties = featureData.getProperties(); // 피처의 속성 가져오기
|
||||
const featureId = featureData.getId(); // 피처의 속성 가져오기
|
||||
const [layerNm, setLayerNm] = useState<string>(""); // 레이어 이름 상태
|
||||
// 피쳐데이터의 현재 레이어 이름 가져오는 함수
|
||||
const getSelectedLayers = () => {
|
||||
@@ -61,10 +62,12 @@ const FeatureClickEventPopup = ({ onClose, featureData }: { onClose: () => void,
|
||||
updateData(inspectionData, setInspectionData);
|
||||
}
|
||||
};
|
||||
function transformFeatureDataToArray(featureProperties: any, keys: string[]) {
|
||||
async function transformFeatureDataToArray(featureId: any, keys: string[]) {
|
||||
const data = await getData(`v1/map/features/${featureId}`);
|
||||
// 필요한 키만 추출하여 새로운 객체 생성
|
||||
console.log("data", data);
|
||||
const transformedData = keys.reduce((acc, key) => {
|
||||
acc[key] = featureProperties[key] !== undefined ? featureProperties[key] : "N/A"; // 값이 없으면 "N/A"로 처리
|
||||
acc[key] = data[key] !== undefined ? data[key] : "N/A"; // 값이 없으면 "N/A"로 처리
|
||||
return acc;
|
||||
}, {} as Record<string, any>);
|
||||
|
||||
@@ -72,8 +75,8 @@ const FeatureClickEventPopup = ({ onClose, featureData }: { onClose: () => void,
|
||||
return [transformedData];
|
||||
}
|
||||
const keys = SwtrmtFcltCol.map((column) => column.id);
|
||||
const transformedFeatureData = transformFeatureDataToArray(featureProperties, keys);
|
||||
useEffect(() => { setLayerNm(getSelectedLayers()) }, [featureProperties]);
|
||||
const transformedFeatureData = transformFeatureDataToArray(featureId, keys);
|
||||
useEffect(() => { setLayerNm(getSelectedLayers()) }, [featureId]);
|
||||
const renderSection = (title: string, data: { year: string; type: string }[], sectionKey: string) => (
|
||||
<div>
|
||||
{/* 섹션 제목 */}
|
||||
@@ -124,7 +127,7 @@ const FeatureClickEventPopup = ({ onClose, featureData }: { onClose: () => void,
|
||||
</button>
|
||||
</div>
|
||||
<div className="overflow-y-auto flex-1">
|
||||
<VerticalTable headName='LX 연계정보' tableData={transformedFeatureData} headlist={SwtrmtFcltCol} pageSize={20} total={0} children={undefined} cellClick={undefined} onPageChange={function (page: number): void {
|
||||
<VerticalTable headName='LX 연계정보' tableData={[]} headlist={SwtrmtFcltCol} pageSize={20} total={0} children={undefined} cellClick={undefined} onPageChange={function (page: number): void {
|
||||
throw new Error("Function not implemented.");
|
||||
}}></VerticalTable>
|
||||
<VerticalTable headName='자체 입력정보' tableData={[]} headlist={inputColumn} pageSize={20} total={0} children={undefined} cellClick={undefined} isEditable={true} onPageChange={function (page: number): void {
|
||||
|
||||
Reference in New Issue
Block a user