fix(menu): avoid refreshing session list when opening an existing chat

The route watcher in the sidebar treated any navigation away from the
creatChat pages as "a new session was created" and called
getMessageList(), which clears menuArr and re-fetches page 1. As a
result, clicking an existing session from /platform/creatChat caused
the whole session list to flicker.

Only refresh when the target chat id is not already in the list, which
is the real signal that a brand-new session was just created.
This commit is contained in:
wizardchen
2026-05-18 21:52:30 +08:00
committed by lyingbug
parent 4845955e9a
commit 6f00056572
+7 -4
View File
@@ -709,14 +709,17 @@ watch([() => route.name, () => route.params], (newvalue, oldvalue) => {
// 只在必要时刷新对话列表,避免不必要的重新加载导致列表抖动
// 需要刷新的情况:
// 1. 创建新会话后(从 creatChat/kbCreatChat 跳转到 chat/:id)
// 1. 创建新会话后(从 creatChat/kbCreatChat 跳转到 chat/:id 且该 id 不在列表里)
// 2. 删除会话后已在 delCard 中处理,不需要在这里刷新
const oldRouteNameStr = typeof oldvalue?.[0] === 'string' ? (oldvalue[0] as string) : (oldvalue?.[0] ? String(oldvalue[0]) : '')
const isCreatingNewSession = (oldRouteNameStr === 'globalCreatChat' || oldRouteNameStr === 'kbCreatChat') &&
const leavingCreatChat = (oldRouteNameStr === 'globalCreatChat' || oldRouteNameStr === 'kbCreatChat') &&
nameStr !== 'globalCreatChat' && nameStr !== 'kbCreatChat';
// 只有跳转到的目标会话不在当前列表里,才认为是"刚创建的新会话",
// 避免从 creatChat 点击已有 session 时把整个列表清空重拉造成抖动。
const newChatId = (newvalue[1] as any)?.chatid as string | undefined;
const targetIsNewSession = !!newChatId && !allSessionIds.value.includes(newChatId);
// 只在创建新会话时才刷新列表
if (isCreatingNewSession) {
if (leavingCreatChat && targetIsNewSession) {
getMessageList();
}