import TableEmpty from '../../common/table/TableEmpty'; import React, { useMemo, useState } from 'react'; import CardTable from '../../common/ui/CardTable'; import { isRoot } from '../../../helpers'; import { getChannelsColumns } from './ChannelsColumnDefs'; const ChannelsTable = (channelsData) => { const { channels, loading, searching, activePage, pageSize, channelCount, selectedChannels, compactMode, visibleColumns, setSelectedChannels, handlePageChange, handlePageSizeChange, handleRow, t, COLUMN_KEYS, // Column functions and data updateChannelBalance, manageChannel, manageTag, submitTagEdit, testChannel, setCurrentTestChannel, setShowModelTestModal, setEditingChannel, setShowEdit, setShowEditTag, setEditingTag, copySelectedChannel, refresh, // Multi-key management setShowMultiKeyManageModal, setCurrentMultiKeyChannel, // Auto-ban exclusion isChannelExcluded, autoBanExclusionFilter, // Daily quota info dailyQuotaInfo, idSort, setIdSort, enableTagMode, loadChannels, } = channelsData; const [idSortOrder, setIdSortOrder] = useState('descend'); const handleTableChange = ({ sorter, extra, action }) => { if ((action ?? extra?.action) !== 'sort') return; const order = sorter?.columnKey === COLUMN_KEYS.ID ? sorter.order : null; setIdSortOrder(order || 'descend'); const nextIdSort = Boolean(order); if (nextIdSort === idSort) return; localStorage.setItem('id-sort', String(nextIdSort)); setIdSort(nextIdSort); loadChannels(activePage, pageSize, nextIdSort, enableTagMode); }; // Filter channels based on auto-ban exclusion filter const filteredChannels = useMemo(() => { if (!autoBanExclusionFilter || autoBanExclusionFilter === 'all') { return channels; } return channels .map((channel) => { // 处理标签聚合模式 if (channel.children !== undefined) { const filteredChildren = channel.children.filter((child) => { const excluded = isChannelExcluded ? isChannelExcluded(child.id) : false; if (autoBanExclusionFilter === 'excluded') { return excluded; } else if (autoBanExclusionFilter === 'included') { return !excluded; } return true; }); if (filteredChildren.length === 0) { return null; } return { ...channel, children: filteredChildren, }; } // 非标签模式 const excluded = isChannelExcluded ? isChannelExcluded(channel.id) : false; if (autoBanExclusionFilter === 'excluded') { return excluded ? channel : null; } else if (autoBanExclusionFilter === 'included') { return !excluded ? channel : null; } return channel; }) .filter(Boolean); }, [channels, autoBanExclusionFilter, isChannelExcluded]); // Get all columns const allColumns = useMemo(() => { return getChannelsColumns({ t, COLUMN_KEYS, updateChannelBalance, manageChannel, manageTag, submitTagEdit, testChannel, setCurrentTestChannel, setShowModelTestModal, setEditingChannel, setShowEdit, setShowEditTag, setEditingTag, copySelectedChannel, refresh, activePage, channels, setShowMultiKeyManageModal, setCurrentMultiKeyChannel, isChannelExcluded, dailyQuotaInfo, }); }, [ t, COLUMN_KEYS, updateChannelBalance, manageChannel, manageTag, submitTagEdit, testChannel, setCurrentTestChannel, setShowModelTestModal, setEditingChannel, setShowEdit, setShowEditTag, setEditingTag, copySelectedChannel, refresh, activePage, channels, setShowMultiKeyManageModal, setCurrentMultiKeyChannel, isChannelExcluded, dailyQuotaInfo, ]); // Filter columns based on visibility settings const getVisibleColumns = () => { return allColumns.filter((column) => visibleColumns[column.key]); }; const visibleColumnsList = getVisibleColumns(); const tableColumns = useMemo(() => { const sortableColumns = visibleColumnsList.map((column) => column.key === COLUMN_KEYS.ID ? { ...column, sorter: (a, b) => { if (a.children !== undefined || b.children !== undefined) return 0; return Number(a.id) - Number(b.id); }, sortOrder: idSort ? idSortOrder : null, } : column, ); return compactMode ? sortableColumns.map(({ fixed, ...rest }) => rest) : sortableColumns; }, [compactMode, visibleColumnsList, COLUMN_KEYS.ID, idSort, idSortOrder]); return ( channel.key ?? String(channel.id), ), getCheckboxProps: (record) => ({ disabled: record.children !== undefined, }), onChange: (selectedRowKeys, selectedRows) => { setSelectedChannels(selectedRows); }, } : null } empty={} className='rounded-xl overflow-hidden' size='middle' loading={loading || searching} /> ); }; export default ChannelsTable;