feat(chat): 会话状态机重塑——空白草稿态 + draftProject 重命名 + 空态提示

This commit is contained in:
lhl
2026-08-28 02:01:24 +08:00
parent 33df996f0b
commit 6bb7b5fa10
+24 -10
View File
@@ -446,11 +446,14 @@
<script>
let sid = null;
let currentProject = null;
let activeProject = null;
let draftProject = null; // 下一空白会话将绑定/已绑的项目(原 currentProject
let activeProject = null; // 当前已落库会话绑定的项目(来自后端)
let projects = [];
let drawerOpen = false;
let drawerSelected = null; // 当前抽屉中编辑的项目名(null = 新建模式)
let lastTriggerEl = null; // 打开抽屉/下拉前的焦点元素(C1)
let drawerDirty = false; // 抽屉表单是否有未保存改动(B6)
let drawerSnapshot = null; // loadDrawerForm 时的字段快照(B6
const chatEl = document.getElementById('chat');
const inputEl = document.getElementById('input');
@@ -702,19 +705,28 @@ function updateUploadBar() {
}
}
// ---------- 空态/欢迎渲染 ----------
function renderEmptyOrWelcome() {
chatEl.innerHTML = '';
if (draftProject === null) {
addMsg('assistant', '请新建项目或者选择项目');
} else {
addMsg('assistant', '你好!我是 Genesis 概要设计书生成 Agent。<br>请先在上方📎上传<strong>要件定义 xlsx</strong>'
+ (draftProject ? '(模板/规则/代码库已由项目「' + esc(draftProject) + '」提供)' : '与<strong>模板 docx</strong>')
+ ',然后告诉我:<br>· 「生成概要设计书」(自动解析→影响→生成→QA)<br>· 「用中文生成」 / 「现在什么状态?」');
}
}
// ---------- 会话创建/加载 ----------
async function newSession() {
const d = await api('POST', '/api/sessions', { user_id: 'default', project: currentProject || null });
sid = d.session_id;
activeProject = d.project || null;
badge.textContent = '会话: ' + (d.name || '新会话');
sid = null;
activeProject = null;
try { localStorage.removeItem('genesis_session'); } catch (e) { /* 忽略 */ }
chatEl.innerHTML = '';
badge.textContent = '未创建会话';
updateUploadBar();
await refreshSessions();
try { localStorage.setItem('genesis_session', sid); } catch (e) { /* 忽略 */ }
addMsg('assistant', '你好!我是 Genesis 概要设计书生成 Agent。<br>请先在上方📎上传<strong>要件定义 xlsx</strong>'
+ (activeProject ? '(模板/规则/代码库已由项目「' + esc(activeProject) + '」提供)' : '与<strong>模板 docx</strong>')
+ ',然后告诉我:<br>· 「生成概要设计书」(自动解析→影响→生成→QA)<br>· 「用中文生成」 / 「现在什么状态?」');
renderEmptyOrWelcome();
}
async function loadSession(id) {
@@ -722,6 +734,8 @@ async function loadSession(id) {
const rec = await api('GET', '/api/sessions/' + id);
sid = id;
activeProject = rec.project || null;
draftProject = rec.project || null; // 载入既有会话时,顶栏与侧边栏过滤对齐该会话项目
applyProjectContext();
badge.textContent = '会话: ' + (rec.name || '新会话');
const msgs = await api('GET', '/api/chat/' + id + '/messages');
chatEl.innerHTML = '';