// 예시 텍스트 설정 function setExample(element) { document.getElementById('searchInput').value = element.textContent; } // 쿼리 파싱 및 분석 async function parseQuery() { const input = document.getElementById('searchInput').value.trim(); if (!input) { alert('검색할 내용을 입력해주세요!'); return; } // UI 상태 변경 document.getElementById('loadingSection').style.display = 'block'; document.getElementById('resultSection').style.display = 'none'; document.getElementById('searchBtn').disabled = true; try { const response = await fetch('/api/parse', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ text: input }) }); if (!response.ok) { throw new Error('서버 오류가 발생했습니다.'); } const data = await response.json(); displayResults(data); } catch (error) { alert('오류: ' + error.message); console.error('Error:', error); } finally { document.getElementById('loadingSection').style.display = 'none'; document.getElementById('searchBtn').disabled = false; } } // 결과 표시 function displayResults(data) { const resultContent = document.getElementById('resultContent'); let html = ''; if (data.transaction_type) { html += `
추출된 정보가 없습니다. 더 구체적으로 입력해주세요.
'; } resultContent.innerHTML = html; document.getElementById('resultSection').style.display = 'block'; } // Enter 키로 검색 document.addEventListener('DOMContentLoaded', function() { document.getElementById('searchInput').addEventListener('keypress', function(e) { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); parseQuery(); } }); });