Files
frontend/apps/wr/components/lib/func/commom.tsx
T

80 lines
2.3 KiB
TypeScript

import type { comCodeState, } from "@/app/store/common/code";
import { filePickedBlob, type SelectDataType } from "@common/business_components/ui";
export const getCity = (val: string, sggCd: SelectDataType[]) => {
const data = sggCd
.filter((item) => String(item.val).substring(0, 2) === val)
.map((item) => ({
val: item.val,
text: item.text // 한국어 텍스트
}));
return data
};
// cd text 넣기
export const tableData = ( data: any,code:comCodeState)=>{
const chCode = code.code;
return data?.map((item: { sggCd: string; ctpvCd: string; reuseBuilding: { lawTrgtYn: any , bdstUsgCd:any}[]; }) => {
let returnData = {};
const sggText = chCode.sggCd.find(
(cd) => cd.val === String(item.sggCd)
)?.text;
const cityText = chCode.cityCd.find(
(cd) => cd.val === String(item.ctpvCd)
)?.text;
if (item?.reuseBuilding?.length >0) {
const bdsgUsgText = chCode.bdstUsgCd.find(
(cd) =>cd.val === item?.reuseBuilding[0]?.bdstUsgCd
)?.text
const lawTrgtYn = item?.reuseBuilding[0]?.lawTrgtYn
returnData= { ...item, sggText: sggText, cityText: cityText ,bdsgUsgText:bdsgUsgText ,lawTrgtYn:lawTrgtYn};
}else{
returnData= { ...item, sggText: sggText, cityText: cityText};
}
// console.log(" returnData ", returnData)
return returnData;
});
}
export const excelDownload =(excelList: [][], fileNm:string ,sampleFile:string ) =>{
if (excelList.length === 0) return;
fetch(`/${sampleFile}`, {})
.then(async (response) => {
if (!response.ok) {
throw Error(response.statusText)
}
// 받은 파일 바인너리 처리
const blobRet = await response.arrayBuffer()
// 버퍼에 있는 엑셀데이터 전달 후 json으로 변환
await filePickedBlob(blobRet, excelList,fileNm, 4)
})
}
//엑셀은 날짜가 숫자로 나와서 만든 함수
export const excelSerialToDateString = (excelDate: number|undefined): string => {
const excelEpoch = new Date(1899, 11, 30); // Excel 기준일 (1900-01-01보다 하루 전)
let date
if(excelDate){
date = new Date(excelEpoch.getTime() + excelDate * 86400000);
}else{
date =new Date()
}
return date.toISOString().split("T")[0] || ""; // "YYYY-MM-DD"
};