summaryrefslogtreecommitdiff
path: root/lib/welding/table/ocr-table-toolbar-actions.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/welding/table/ocr-table-toolbar-actions.tsx')
-rw-r--r--lib/welding/table/ocr-table-toolbar-actions.tsx55
1 files changed, 34 insertions, 21 deletions
diff --git a/lib/welding/table/ocr-table-toolbar-actions.tsx b/lib/welding/table/ocr-table-toolbar-actions.tsx
index a6a38adc..35171c29 100644
--- a/lib/welding/table/ocr-table-toolbar-actions.tsx
+++ b/lib/welding/table/ocr-table-toolbar-actions.tsx
@@ -497,34 +497,47 @@ export function OcrTableToolbarActions({ table }: OcrTableToolbarActionsProps) {
}
// 전체 데이터 내보내기
- const exportAllData = async () => {
- if (isExporting) return
- setIsExporting(true)
+const exportAllData = async () => {
+ if (isExporting) return
- try {
- toast.loading("전체 데이터를 가져오는 중...", {
- description: "잠시만 기다려주세요."
- })
-
- const allData = await getOcrAllRows()
- toast.dismiss()
+ setIsExporting(true)
- if (allData.length === 0) {
- toast.warning("내보낼 데이터가 없습니다.")
- return
- }
+ try {
+ const loadingToast = toast.loading("엑셀 파일을 생성 중입니다...", {
+ description: "대량 데이터 처리 중... 잠시만 기다려주세요."
+ })
- await exportOcrDataToExcel(allData, `OCR 결과 (전체 데이터 - ${allData.length}개 행)`)
- toast.success(`전체 데이터 ${allData.length}개 행이 성공적으로 내보내졌습니다.`)
+ // 서버에서 직접 엑셀 파일 받기
+ const response = await fetch('/api/ocr/export', {
+ method: 'GET',
+ })
- } catch (error) {
- console.error('전체 데이터 내보내기 오류:', error)
- toast.error('전체 데이터 내보내기 중 오류가 발생했습니다.')
- } finally {
- setIsExporting(false)
+ if (!response.ok) {
+ throw new Error('Export failed')
}
+
+ // Blob으로 변환 후 다운로드
+ const blob = await response.blob()
+ const url = window.URL.createObjectURL(blob)
+ const a = document.createElement('a')
+ a.href = url
+ a.download = `OCR_Export_${new Date().toISOString()}.xlsx`
+ document.body.appendChild(a)
+ a.click()
+ document.body.removeChild(a)
+ window.URL.revokeObjectURL(url)
+
+ toast.dismiss(loadingToast)
+ toast.success("엑셀 파일이 성공적으로 다운로드되었습니다.")
+
+ } catch (error) {
+ console.error('Export error:', error)
+ toast.error('데이터 내보내기 중 오류가 발생했습니다.')
+ } finally {
+ setIsExporting(false)
}
+}
// 삭제 후 콜백 - 테이블 새로고침
const handleDeleteSuccess = () => {