import { useEffect } from 'react'; import { useConnectionStore } from '../store/connectionStore'; import { useAgentStore } from '../store/agentStore'; import { useConfigStore } from '../store/configStore'; import { Radio, RefreshCw, MessageCircle, Settings } from 'lucide-react'; const CHANNEL_ICONS: Record = { feishu: '飞', qqbot: 'QQ', wechat: '微', }; // 可用频道类型(用于显示未配置的频道) const AVAILABLE_CHANNEL_TYPES = [ { type: 'feishu', name: '飞书 (Feishu)' }, { type: 'wechat', name: '微信' }, { type: 'qqbot', name: 'QQ 机器人' }, ]; interface ChannelListProps { onOpenSettings?: () => void; } export function ChannelList({ onOpenSettings }: ChannelListProps) { const connectionState = useConnectionStore((s) => s.connectionState); const loadPluginStatus = useAgentStore((s) => s.loadPluginStatus); const channels = useConfigStore((s) => s.channels); const loadChannels = useConfigStore((s) => s.loadChannels); const connected = connectionState === 'connected'; useEffect(() => { if (connected) { loadPluginStatus().then(() => loadChannels()); } }, [connected]); const handleRefresh = () => { loadPluginStatus().then(() => loadChannels()); }; // 去重:基于 channel id const uniqueChannels = channels.filter((ch, index, self) => index === self.findIndex(c => c.id === ch.id) ); // 获取已配置的频道类型 const configuredTypes = new Set(uniqueChannels.map(c => c.type)); // 未配置的频道类型 const unconfiguredTypes = AVAILABLE_CHANNEL_TYPES.filter(ct => !configuredTypes.has(ct.type)); if (!connected) { return (

IM 频道

连接 Gateway 后可用

); } return (
{/* Header */}
频道列表
{/* Configured channels */} {uniqueChannels.map((ch) => (
{CHANNEL_ICONS[ch.type] || }
{ch.label}
{ch.status === 'active' ? '已连接' : ch.status === 'error' ? ch.error || '错误' : '未配置'} {ch.accounts !== undefined && ch.accounts > 0 && ` · ${ch.accounts} 个账号`}
))} {/* Unconfigured channels - 只显示一次 */} {unconfiguredTypes.map((ct) => (
{CHANNEL_ICONS[ct.type] || }
{ct.name}
未配置
))} {/* Help text */}

在设置中配置 IM 频道

{onOpenSettings && ( )}
); }