발전시물레이션 excel, pdf 다운 처리 추가

This commit is contained in:
leeyongjae 2024-11-21 13:24:10 +09:00
parent a6ccd78ad1
commit d27ca6cd58
3 changed files with 71 additions and 4 deletions

View File

@ -38,6 +38,10 @@ import DocDownOptionPop from '../estimate/popup/DocDownOptionPop'
import { FloorPlanContext } from '@/app/floor-plan/FloorPlanProvider'
import EstimateCopyPop from '../estimate/popup/EstimateCopyPop'
import { floorPlanObjectState } from '@/store/floorPlanObjectAtom'
import { pwrGnrSimTypeState } from '@/store/simulatorAtom'
import { useAxios } from '@/hooks/useAxios'
export default function CanvasMenu(props) {
const { menuNumber, setMenuNumber } = props
const pathname = usePathname()
@ -189,6 +193,54 @@ export default function CanvasMenu(props) {
return ([2, 3].some((num) => num === canvasSetting?.roofSizeSet) && menu.index === 2) || (menuNumber === 4 && menu.index === 2)
}
// Excel/PDF
const { promisePost } = useAxios(globalLocale)
const objectRecoil = useRecoilValue(floorPlanObjectState)
const pwrGnrSimTypeRecoil = useRecoilValue(pwrGnrSimTypeState)
const { plans } = usePlan()
const plan = plans.find((plan) => plan.isCurrent === true)
const handleExcelPdfFileDown = async (donwloadType, drawingFlg) => {
const url = '/api/estimate/excel-download'
const params = {
objectNo: objectRecoil.floorPlanObjectNo,
planNo: plan?.id,
schDownload: donwloadType,
schDrawingFlg: drawingFlg,
pwrGnrSimType: pwrGnrSimTypeRecoil.type,
}
const options = { responseType: 'blob' }
await promisePost({ url: url, data: params, option: options })
.then((resultData) => {
if (resultData) {
let fileName = 'unknow'
const blob = new Blob([resultData.data], { type: resultData.headers['content-type'] || 'application/octet-stream' })
const fileUrl = window.URL.createObjectURL(blob)
const link = document.createElement('a')
link.href = fileUrl
//
const contentDisposition = resultData.headers['content-disposition']
if (contentDisposition) {
fileName = contentDisposition.split('filename=')[1].replace(/['"]/g, '')
}
link.download = fileName
document.body.appendChild(link)
link.click()
link.remove()
window.URL.revokeObjectURL(fileUrl)
}
})
.catch((error) => {
alert('File does not exist.')
})
}
return (
<div className={`canvas-menu-wrap ${[2, 3, 4].some((num) => num === menuNumber) ? 'active' : ''}`}>
<div className="canvas-menu-inner">
@ -299,11 +351,11 @@ export default function CanvasMenu(props) {
{menuNumber === 6 && (
<>
<div className="ico-btn-from">
<button className="btn-frame gray ico-flx">
<button type="button" className="btn-frame gray ico-flx" onClick={() => handleExcelPdfFileDown('EXCEL', '2')}>
<span className="ico ico01"></span>
<span>{getMessage('plan.menu.simulation.excel')}</span>
</button>
<button className="btn-frame gray ico-flx">
<button type="button" className="btn-frame gray ico-flx" onClick={() => handleExcelPdfFileDown('PDF', '2')}>
<span className="ico ico01"></span>
<span>{getMessage('plan.menu.simulation.pdf')}</span>
</button>

View File

@ -5,8 +5,9 @@ import { Bar } from 'react-chartjs-2'
import dayjs from 'dayjs'
import { useEffect, useState, useRef } from 'react'
import { useRecoilValue } from 'recoil'
import { useRecoilValue, useRecoilState } from 'recoil'
import { floorPlanObjectState } from '@/store/floorPlanObjectAtom'
import { pwrGnrSimTypeState } from '@/store/simulatorAtom'
import { useAxios } from '@/hooks/useAxios'
import { useMessage } from '@/hooks/useMessage'
@ -107,6 +108,8 @@ export default function Simulator() {
if (objectNo) {
fetchObjectDetail(objectNo)
fetchSimulatorNotice()
setPwrGnrSimType('D')
setPwrRecoil({ ...pwrRecoil, type: 'D' })
}
}, [objectNo, plan])
@ -168,8 +171,10 @@ export default function Simulator() {
// , list type
const [pwrGnrSimType, setPwrGnrSimType] = useState('D')
const [pwrRecoil, setPwrRecoil] = useRecoilState(pwrGnrSimTypeState)
const handleChartChangeData = (type) => {
setPwrGnrSimType(type)
setPwrRecoil({ ...pwrRecoil, type: type })
switch (type) {
case 'A':
setChartData(hatsudenryouAll)
@ -251,9 +256,11 @@ export default function Simulator() {
<select
style={{ width: '30%' }}
className="select-light"
value={pwrGnrSimType}
defaultValue={`D`}
onChange={(e) => {
handleChartChangeData(e.target.value)
setPwrGnrSimType(e.target.value)
}}
>
<option value={`A`}>積雪考慮なし(ピークカットなし発電量)</option>

View File

@ -0,0 +1,8 @@
import { atom } from 'recoil'
export const pwrGnrSimTypeState = atom({
key: 'pwrGnrSimType',
default: {
type: 'D',
},
})