119 lines
3.1 KiB
TypeScript
119 lines
3.1 KiB
TypeScript
import { fetchType, getFetch, getFetchWithCount } from "@/components/lib/api";
|
|
import type { CommonTableProps } from "../../common/type/header";
|
|
import type { customLdrmnt } from "../../matDmd/ldrmntCoSttn";
|
|
import {
|
|
ldrmntHeadListExport,
|
|
ldrmntNodeListExport,
|
|
} from "../../matDmd/ldrmntCoSttn/headList";
|
|
|
|
|
|
export const ldrmntMapSize = 20;
|
|
export type ldrmntMapState = {
|
|
ldrmntMap: {
|
|
ldrmntMapHeadList: CommonTableProps[];
|
|
ldrmntMapNodeList: CommonTableProps[];
|
|
isInit: boolean;
|
|
ldrmntMapRes: customLdrmnt[];
|
|
ldrmntMapResCount: number;
|
|
};
|
|
};
|
|
|
|
type ldrmntMapActions = {
|
|
ldrmntMapInit: (page: number, total: number, con: string) => void;
|
|
ldrmntMapSearch: (
|
|
page: number,
|
|
total: number,
|
|
con: string,
|
|
coNm: string
|
|
) => void;
|
|
ldrmntMapDetile:(featureCd:string) => Promise<customLdrmnt | undefined>;
|
|
};
|
|
|
|
export type ldrmntMapType = ldrmntMapState & ldrmntMapActions;
|
|
|
|
export const ldrmntMapStateExport: ldrmntMapState = {
|
|
ldrmntMap: {
|
|
ldrmntMapHeadList: ldrmntHeadListExport,
|
|
ldrmntMapNodeList: ldrmntNodeListExport,
|
|
isInit: false,
|
|
ldrmntMapRes: [],
|
|
ldrmntMapResCount: 1,
|
|
},
|
|
};
|
|
|
|
export const ldrmntMapActionsExport: (set: any) => ldrmntMapActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
ldrmntMapInit: async (page: number, total: number, con: string) => {
|
|
try {
|
|
const ldrmntMapRes = await getFetchWithCount(
|
|
fetchType.WR,
|
|
`/reuseFc/request/temp/${page}/${total}/${con}`
|
|
);
|
|
|
|
set((state: ldrmntMapState) => {
|
|
return {
|
|
...state,
|
|
ldrmntMap: {
|
|
...state.ldrmntMap,
|
|
ldrmntMapRes: ldrmntMapRes.data,
|
|
ldrmntMapResCount: ldrmntMapRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},
|
|
ldrmntMapSearch: async (
|
|
page: number,
|
|
total: number,
|
|
con: string,
|
|
coNm: string
|
|
) => {
|
|
let searchUrl = "";
|
|
|
|
if (con !== "") {
|
|
if (coNm !== "") {
|
|
searchUrl = `/reuseFc/request/temp/${page}/${total}/${con}/${coNm}`;
|
|
} else {
|
|
searchUrl = `/reuseFc/request/temp/${page}/${total}/${con}`;
|
|
}
|
|
}
|
|
try {
|
|
const ldrmntMapRes = await getFetchWithCount(fetchType.WR, searchUrl);
|
|
set((state: ldrmntMapState) => {
|
|
return {
|
|
...state,
|
|
ldrmntMap: {
|
|
...state.ldrmntMap,
|
|
ldrmntMapRes: ldrmntMapRes.data,
|
|
ldrmntMapResCount: ldrmntMapRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
},ldrmntMapDetile: async (featureCd: string) => {
|
|
try {
|
|
|
|
const ldrmtDetail = await getFetch(fetchType.WR,
|
|
`/reuseFc/request/temp/1/4/0/${featureCd}` )
|
|
if(ldrmtDetail&&ldrmtDetail.length>0){
|
|
|
|
return ldrmtDetail[0];
|
|
}else{
|
|
return null;
|
|
}
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw error; // 호출부에서 catch 가능하도록
|
|
}
|
|
}
|
|
};
|
|
};
|