87 lines
2.7 KiB
JavaScript
87 lines
2.7 KiB
JavaScript
// app/static/js/index.js
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
loadSessions();
|
|
});
|
|
|
|
async function startResearch() {
|
|
const input = document.getElementById('questionInput');
|
|
const question = input.value.trim();
|
|
|
|
if (!question) {
|
|
alert('请输入研究问题');
|
|
return;
|
|
}
|
|
|
|
const startBtn = document.getElementById('startBtn');
|
|
const loading = document.getElementById('loading');
|
|
|
|
startBtn.disabled = true;
|
|
loading.style.display = 'flex';
|
|
|
|
try {
|
|
const result = await api.createResearch(question);
|
|
|
|
if (result.session_id) {
|
|
// 跳转到研究页面
|
|
window.location.href = `/research/${result.session_id}`;
|
|
} else {
|
|
alert('创建研究失败: ' + (result.error || '未知错误'));
|
|
}
|
|
} catch (error) {
|
|
console.error('Error:', error);
|
|
alert('创建研究失败,请重试');
|
|
} finally {
|
|
startBtn.disabled = false;
|
|
loading.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
async function loadSessions() {
|
|
try {
|
|
const data = await api.getSessions();
|
|
|
|
if (data.sessions && data.sessions.length > 0) {
|
|
const historySection = document.getElementById('historySection');
|
|
const sessionList = document.getElementById('sessionList');
|
|
|
|
historySection.style.display = 'block';
|
|
sessionList.innerHTML = '';
|
|
|
|
data.sessions.forEach(session => {
|
|
const item = document.createElement('div');
|
|
item.className = 'session-item';
|
|
item.onclick = () => {
|
|
window.location.href = `/research/${session.id}`;
|
|
};
|
|
|
|
item.innerHTML = `
|
|
<div class="session-question">${session.question}</div>
|
|
<div class="session-meta">
|
|
<span class="status-badge ${session.status}">${getStatusText(session.status)}</span>
|
|
<span class="session-date">${new Date(session.created_at).toLocaleDateString()}</span>
|
|
</div>
|
|
`;
|
|
|
|
sessionList.appendChild(item);
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Failed to load sessions:', error);
|
|
}
|
|
}
|
|
|
|
function getStatusText(status) {
|
|
const statusMap = {
|
|
'pending': '等待中',
|
|
'analyzing': '分析中',
|
|
'outlining': '制定大纲',
|
|
'researching': '研究中',
|
|
'writing': '撰写中',
|
|
'reviewing': '审核中',
|
|
'completed': '已完成',
|
|
'error': '错误',
|
|
'cancelled': '已取消'
|
|
};
|
|
return statusMap[status] || status;
|
|
} |