修复权限操作
This commit is contained in:
@@ -60,6 +60,26 @@ export default function Chat() {
|
||||
handleChatAppChange: originalHandleChatAppChange,
|
||||
} = useChatApps();
|
||||
|
||||
// 调试日志 - 监听chatApps和currentChatApp变化
|
||||
useEffect(() => {
|
||||
console.log('[Chat] chatApps 更新:', {
|
||||
count: chatApps.length,
|
||||
apps: chatApps.map(app => ({
|
||||
app_id: app.app_id,
|
||||
app_name: app.app_name,
|
||||
is_default: app.is_default
|
||||
}))
|
||||
});
|
||||
}, [chatApps]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('[Chat] currentChatApp 更新:', currentChatApp ? {
|
||||
app_id: currentChatApp.app_id,
|
||||
app_name: currentChatApp.app_name,
|
||||
is_default: currentChatApp.is_default
|
||||
} : 'null');
|
||||
}, [currentChatApp]);
|
||||
|
||||
// 会话管理
|
||||
const {
|
||||
conversationList,
|
||||
@@ -405,14 +425,27 @@ export default function Chat() {
|
||||
* 切换应用后刷新加载对应的会话列表
|
||||
*/
|
||||
const handleChatAppChange = async (appId: string) => {
|
||||
console.log('🔄 [Chat] 切换对话应用:', appId);
|
||||
console.log('🔄 [Chat] 用户点击切换对话应用,目标ID:', appId);
|
||||
console.log('🔄 [Chat] 当前可用应用列表:', chatApps.map(app => ({
|
||||
app_id: app.app_id,
|
||||
app_name: app.app_name
|
||||
})));
|
||||
|
||||
// 查找目标应用
|
||||
const targetApp = chatApps.find(app => app.app_id === appId);
|
||||
if (!targetApp) {
|
||||
console.error('❌ [Chat] 未找到目标应用 ID:', appId);
|
||||
return;
|
||||
}
|
||||
console.log('🔄 [Chat] 找到目标应用:', targetApp.app_name);
|
||||
|
||||
// 调用原始的切换方法
|
||||
originalHandleChatAppChange(appId, async (app) => {
|
||||
console.log('🔄 [Chat] 应用已切换到:', app.app_name, '开始刷新会话列表...');
|
||||
console.log('✅ [Chat] originalHandleChatAppChange回调触发,传入应用:', app.app_name);
|
||||
|
||||
try {
|
||||
// 重新获取会话列表,传入新的应用ID获取该应用的会话
|
||||
console.log('📋 [Chat] 开始获取新应用的会话列表...');
|
||||
const conversationData = await fetchConversations(app.app_id);
|
||||
const conversations = (conversationData as any).data || [];
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
SearchOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Button, Dropdown, Input, Layout, Menu, Modal, Tooltip, message, theme, Select } from 'antd';
|
||||
import { forwardRef, useImperativeHandle, useState } from 'react';
|
||||
import { forwardRef, useImperativeHandle, useMemo, useState } from 'react';
|
||||
import type { ChatApp } from '~/api/dify-chat-apps/types';
|
||||
import type { ConversationItem } from '~/api/dify-chat';
|
||||
import { deleteConversation, renameConversation } from '~/api/dify-chat';
|
||||
@@ -68,6 +68,30 @@ const ChatSidebar = forwardRef<ChatSidebarRef, ChatSidebarProps>(({
|
||||
token: { colorBgContainer, borderRadiusLG },
|
||||
} = theme.useToken();
|
||||
|
||||
// 去重:防止后端返回重复的应用数据
|
||||
const uniqueChatApps = useMemo(() => {
|
||||
const appMap = new Map<string, ChatApp>();
|
||||
chatApps.forEach(app => {
|
||||
// 如果已经存在相同ID的应用,保留第一个(或检查is_default属性)
|
||||
if (!appMap.has(app.app_id)) {
|
||||
appMap.set(app.app_id, app);
|
||||
} else {
|
||||
// 如果重复的是默认应用,保留默认版本
|
||||
const existingApp = appMap.get(app.app_id)!;
|
||||
if (app.is_default && !existingApp.is_default) {
|
||||
appMap.set(app.app_id, app);
|
||||
}
|
||||
}
|
||||
});
|
||||
const unique = Array.from(appMap.values());
|
||||
console.log('[Sidebar] 应用去重:', {
|
||||
originalCount: chatApps.length,
|
||||
uniqueCount: unique.length,
|
||||
removed: chatApps.length - unique.length
|
||||
});
|
||||
return unique;
|
||||
}, [chatApps]);
|
||||
|
||||
// 过滤会话列表
|
||||
const filteredConversations = conversations.filter(conv =>
|
||||
conv.name.toLowerCase().includes(searchValue.toLowerCase())
|
||||
@@ -302,7 +326,7 @@ const ChatSidebar = forwardRef<ChatSidebarRef, ChatSidebarProps>(({
|
||||
placeholder="选择对话应用"
|
||||
size="small"
|
||||
>
|
||||
{(chatApps || []).map(app => (
|
||||
{uniqueChatApps.map(app => (
|
||||
<Select.Option key={app.app_id} value={app.app_id}>
|
||||
{app.app_name}
|
||||
</Select.Option>
|
||||
|
||||
Reference in New Issue
Block a user