커뮤니티 파일 다운로드 파라미터 수정
This commit is contained in:
parent
645bd21f30
commit
370617ff63
@ -54,31 +54,6 @@ export default function ArchiveTable({ clsCode }) {
|
||||
fetchData()
|
||||
}, [search.searchValue, search.searchFlag])
|
||||
|
||||
// 상세 파일 목록 조회
|
||||
const handleDetailFileListDown = async (noticeNo) => {
|
||||
const url = `/api/board/detail`
|
||||
const params = new URLSearchParams({
|
||||
noticeNo: noticeNo,
|
||||
})
|
||||
const apiUrl = `${url}?${params.toString()}`
|
||||
|
||||
const resultData = await get({ url: apiUrl })
|
||||
|
||||
if (resultData) {
|
||||
if (resultData.result.code === 200) {
|
||||
const boardDetailFileList = resultData.data.listFile
|
||||
|
||||
if (boardDetailFileList && Array.isArray(boardDetailFileList)) {
|
||||
boardDetailFileList.forEach((boardFile) => {
|
||||
handleFileDown(boardFile)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
alert(resultData.result.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{boardList.length > 0 ? (
|
||||
@ -101,7 +76,7 @@ export default function ArchiveTable({ clsCode }) {
|
||||
</div>
|
||||
<div className="file-down-box">
|
||||
{/* 첨부파일 */}
|
||||
<button type="button" className="file-down-btn" onClick={() => handleDetailFileListDown(board.noticeNo)}></button>
|
||||
<button type="button" className="file-down-btn" onClick={() => handleFileDown(board.noticeNo, 'Y')}></button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
@ -41,6 +41,7 @@ export default function Table({ clsCode }) {
|
||||
schTitle: search.searchValue ? search.searchValue : '',
|
||||
startRow: startRow,
|
||||
endRow: endRow,
|
||||
schMainYn: 'N',
|
||||
})
|
||||
const apiUrl = `${url}?${params.toString()}`
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ export default function BoardDetailModal({ noticeNo, setOpen }) {
|
||||
<dt>{getMessage('board.sub.fileList')}</dt>
|
||||
{boardDetail.listFile.map((boardFile) => (
|
||||
<dd key={boardFile.encodeFileNo}>
|
||||
<button type="button" className="down" onClick={() => handleFileDown(boardFile)}>
|
||||
<button type="button" className="down" onClick={() => handleFileDown(boardFile.fileNo, 'N')}>
|
||||
{boardFile.srcFileNm}
|
||||
</button>
|
||||
</dd>
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import { useAxios } from '@/hooks/useAxios'
|
||||
|
||||
// 파일 다운로드
|
||||
export const handleFileDown = async (file) => {
|
||||
export const handleFileDown = async (keyNo, zipYn) => {
|
||||
const { promiseGet } = useAxios()
|
||||
|
||||
const url = `/api/board/file/download`
|
||||
const params = new URLSearchParams({
|
||||
encodeFileNo: file.encodeFileNo,
|
||||
keyNo: keyNo,
|
||||
zipYn: zipYn,
|
||||
})
|
||||
const options = { responseType: 'blob' }
|
||||
const apiUrl = `${url}?${params.toString()}`
|
||||
@ -18,8 +19,17 @@ export const handleFileDown = async (file) => {
|
||||
const fileUrl = window.URL.createObjectURL(blob)
|
||||
const link = document.createElement('a')
|
||||
|
||||
const contentDisposition = resultData.headers.get('content-disposition')
|
||||
let filename = 'filename'
|
||||
if (contentDisposition) {
|
||||
const matches = contentDisposition.match(/filename="?([^"]+)"?/)
|
||||
if (matches && matches[1]) {
|
||||
filename = matches[1]
|
||||
}
|
||||
}
|
||||
|
||||
link.download = decodeURIComponent(filename)
|
||||
link.href = fileUrl
|
||||
link.download = file.srcFileNm
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user