139 lines
6.1 KiB
TypeScript
139 lines
6.1 KiB
TypeScript
'use client'
|
|
import React, { useRef, useState } from 'react'
|
|
import { Button, DatePicker, Input } from '@common/components/ui'
|
|
import { z } from 'zod'
|
|
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { useForm } from 'react-hook-form'
|
|
import FormSection from '@/components/ui/formSection'
|
|
import BaseLayout from '../BaseLayout'
|
|
import { filePicked, FileUpload } from '@common/business_components/ui'
|
|
import { excelToflowRateData, excelToMatchingResultData, excelToTimePatternData } from '../../components/lib/utils/excelToJson'
|
|
import { postData } from '@/components/lib/api'
|
|
|
|
const formSchema = z.object({
|
|
managenm: z.string(),
|
|
region: z.string(),
|
|
suyeonga: z.number(),
|
|
inputdate: z.coerce.date(),
|
|
rtkSource: z.string(),
|
|
suyeongaPlace: z.string(),
|
|
pattern: z.string()
|
|
})
|
|
const region: { text: string, val: number }[] = [{ text: '양평', val: 1 }, { text: '강남', val: 2 }, { text: 'test', val: 3 }]
|
|
const IrSetting = () => {
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
managenm: "",
|
|
region: "",
|
|
suyeonga: 0,
|
|
inputdate: new Date(),
|
|
rtkSource: "",
|
|
suyeongaPlace: "",
|
|
pattern: ""
|
|
}
|
|
})
|
|
const [file1, setFile1] = useState<File | null>(null);
|
|
const [file2, setFile2] = useState<File | null>(null);
|
|
const [file3, setFile3] = useState<File | null>(null);
|
|
const [file4, setFile4] = useState<File | null>(null);
|
|
const [selectedDate, setSelectedDate] = useState(new Date())
|
|
const fileInputRef1 = useRef<HTMLInputElement>(null)
|
|
const fileInputRef2 = useRef<HTMLInputElement>(null)
|
|
const fileInputRef3 = useRef<HTMLInputElement>(null)
|
|
const fileInputRef4 = useRef<HTMLInputElement>(null)
|
|
|
|
// 버튼 클릭 핸들러
|
|
const handleAnalysisClick = async () => {
|
|
const file1 = fileInputRef1.current?.files?.[0]
|
|
const file2 = fileInputRef2.current?.files?.[0]
|
|
const file3 = fileInputRef3.current?.files?.[0]
|
|
|
|
if (!file1 || !file2 || !file3) {
|
|
alert('모든 파일을 선택해주세요.')
|
|
return
|
|
}
|
|
|
|
let json2: any = null;
|
|
let json3: any = null;
|
|
|
|
await filePicked(file2, 0).then((res) => {
|
|
if (res !== undefined) json2 = excelToMatchingResultData(res);
|
|
});
|
|
await filePicked(file3, 0).then((res) => {
|
|
if (res !== undefined) json3 = excelToTimePatternData(res);
|
|
});
|
|
|
|
|
|
console.log(file1)
|
|
console.log(json2)
|
|
console.log(json3)
|
|
}
|
|
|
|
|
|
// 버튼 클릭 핸들러
|
|
const handleUploadClick = async () => {
|
|
const file4 = fileInputRef4.current?.files?.[0];
|
|
|
|
if (!file4) {
|
|
alert('파일을 선택해주세요.')
|
|
return
|
|
}
|
|
let json4: any = null;
|
|
await filePicked(file4, 0).then((res) => {
|
|
console.log(res);
|
|
if (res !== undefined) json4 = excelToflowRateData(res);
|
|
});
|
|
console.log(json4);
|
|
|
|
// json4가 존재하면 postData로 백엔드에 전송
|
|
if (json4) {
|
|
try {
|
|
const response = await postData('your-backend-endpoint', json4); // 'your-backend-endpoint'를 실제 API 경로로 변경
|
|
console.log('업로드 결과:', response);
|
|
alert('업로드가 완료되었습니다.');
|
|
} catch (error) {
|
|
console.error('업로드 실패:', error);
|
|
alert('업로드에 실패했습니다.');
|
|
}
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<BaseLayout titleName={{ mainTitle: '침입수 분석', firstCardTitle: '침입수 분석 자료 입력', secondCardTitle: '실측자료 등록' }} form={form} onSubmitEvent={() => { }} graphBtn={false} searchBox={{ title: '분석 대장지역 선택' }} >
|
|
<div className="grid gap-4">
|
|
<FormSection name='suyeongaPlace' form={form} titleNm='▷ 오수관망도'><div className="">
|
|
<Input id="fileNm" ref={fileInputRef1} type="file" />
|
|
</div></FormSection>
|
|
<FormSection name='suyeonga' form={form} titleNm='▷ 수용가-맨홀 매칭결과'><div className="w-[150px]">
|
|
<Input id="fileNm" ref={fileInputRef2} type="file" accept=".xls, .xlsx, .xlsm, .xltx" />
|
|
</div></FormSection>
|
|
<FormSection name='pattern' form={form} titleNm='▷ 오수량 시간패턴'><div className="w-[150px]">
|
|
<Input id="fileNm" ref={fileInputRef3} type="file" accept=".xls, .xlsx, .xlsm, .xltx" />
|
|
</div></FormSection>
|
|
<FormSection name='inputdate' form={form} titleNm='▷ 상수사용량 적용기간'>
|
|
<DatePicker selected={selectedDate} onSelect={(date: Date | undefined) => { if (date) setSelectedDate(date) }} mode={"single"} />
|
|
</FormSection>
|
|
<FormSection name='rtkSource' form={form} titleNm='▷ 오수전환율'><Input className="h-[3.2rem] text-center text-xl w-[150px]" /></FormSection>
|
|
<FormSection name='analysis information' form={form} titleNm='▷ 분석 정보'><Input className="h-[3.2rem] text-center text-xl w-[150px]" /></FormSection>
|
|
<div className="flex justify-center mt-1">
|
|
<Button type="submit" onClick={handleAnalysisClick}>침입수분석 실행</Button>
|
|
</div>
|
|
</div>
|
|
<div className="flex items-center gap-24">
|
|
<FormSection name='region' form={form} titleNm='▷ 유량자료 등록'>
|
|
<div className="w-[150px]">
|
|
<Input id="fileNm" ref={fileInputRef4} type="file" accept=".xls, .xlsx, .xlsm, .xltx" />
|
|
</div>
|
|
</FormSection>
|
|
<div className='mt-1'>
|
|
<Button type="submit" onClick={handleUploadClick}>자료 업로드</Button>
|
|
</div>
|
|
</div>
|
|
</BaseLayout>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default IrSetting |