219 lines
7.3 KiB
React
219 lines
7.3 KiB
React
/*
|
|
Copyright (C) 2025 QuantumNous
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Affero General Public License as
|
|
published by the Free Software Foundation, either version 3 of the
|
|
License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Affero General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
For commercial licensing, please contact support@quantumnous.com
|
|
*/
|
|
|
|
import React from 'react';
|
|
import { Button, Dropdown, Modal, Switch, Typography } from '@/components/ui';
|
|
import CompactModeToggle from '../../common/ui/CompactModeToggle';
|
|
import { isRoot } from '../../../helpers';
|
|
|
|
// 批量删除/删除禁用渠道的确认文案:批量场景不逐个查反向引用,给固定影响说明
|
|
const renderBatchDeleteContent = (t) => (
|
|
<div>
|
|
<div>{t('此修改将不可逆')}</div>
|
|
<div style={{ marginTop: 8 }}>
|
|
{t('被删除的渠道若被其他渠道列为兜底,会自动从这些兜底链中移除')}
|
|
</div>
|
|
</div>
|
|
);
|
|
|
|
const ChannelsActions = ({
|
|
selectedChannels,
|
|
batchDeleteChannels,
|
|
setShowBatchSetTag,
|
|
testAllChannels,
|
|
fixChannelsAbilities,
|
|
updateAllChannelsBalance,
|
|
deleteAllDisabledChannels,
|
|
compactMode,
|
|
setCompactMode,
|
|
idSort,
|
|
enableTagMode,
|
|
setEnableTagMode,
|
|
loadChannels,
|
|
pageSize,
|
|
setActivePage,
|
|
t,
|
|
}) => {
|
|
return (
|
|
<div className='flex flex-col gap-2'>
|
|
{/* 第一行:批量操作按钮 + 设置开关 */}
|
|
<div className='flex flex-col md:flex-row justify-between gap-2'>
|
|
{/* 左侧:批量操作按钮 */}
|
|
<div className='flex flex-wrap md:flex-nowrap items-center gap-2 w-full md:w-auto order-2 md:order-1'>
|
|
{isRoot() && (
|
|
<Button
|
|
size='small'
|
|
disabled={!selectedChannels.length}
|
|
type='danger'
|
|
className='w-full md:w-auto'
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: t('确定是否要删除所选通道?'),
|
|
content: renderBatchDeleteContent(t),
|
|
onOk: () => batchDeleteChannels(),
|
|
});
|
|
}}
|
|
>
|
|
{t('删除所选通道')}
|
|
</Button>
|
|
)}
|
|
|
|
{isRoot() && (
|
|
<Button
|
|
size='small'
|
|
disabled={!selectedChannels.length}
|
|
type='tertiary'
|
|
onClick={() => setShowBatchSetTag(true)}
|
|
className='w-full md:w-auto'
|
|
>
|
|
{t('批量设置标签')}
|
|
</Button>
|
|
)}
|
|
|
|
<Dropdown
|
|
size='small'
|
|
trigger='click'
|
|
render={
|
|
<Dropdown.Menu>
|
|
{isRoot() && (
|
|
<Dropdown.Item>
|
|
<Button
|
|
size='small'
|
|
type='tertiary'
|
|
className='w-full'
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: t('确定?'),
|
|
content: t('确定要测试所有通道吗?'),
|
|
onOk: () => testAllChannels(),
|
|
size: 'small',
|
|
centered: true,
|
|
});
|
|
}}
|
|
>
|
|
{t('测试所有通道')}
|
|
</Button>
|
|
</Dropdown.Item>
|
|
)}
|
|
{isRoot() && (
|
|
<Dropdown.Item>
|
|
<Button
|
|
size='small'
|
|
className='w-full'
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: t('确定是否要修复数据库一致性?'),
|
|
content: t(
|
|
'进行该操作时,可能导致渠道访问错误,请仅在数据库出现问题时使用',
|
|
),
|
|
onOk: () => fixChannelsAbilities(),
|
|
size: 'sm',
|
|
centered: true,
|
|
});
|
|
}}
|
|
>
|
|
{t('修复数据库一致性')}
|
|
</Button>
|
|
</Dropdown.Item>
|
|
)}
|
|
{isRoot() && (
|
|
<Dropdown.Item>
|
|
<Button
|
|
size='small'
|
|
type='secondary'
|
|
className='w-full'
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: t('确定?'),
|
|
content: t('确定要更新所有已启用通道余额吗?'),
|
|
onOk: () => updateAllChannelsBalance(),
|
|
size: 'sm',
|
|
centered: true,
|
|
});
|
|
}}
|
|
>
|
|
{t('更新所有已启用通道余额')}
|
|
</Button>
|
|
</Dropdown.Item>
|
|
)}
|
|
{isRoot() && (
|
|
<Dropdown.Item>
|
|
<Button
|
|
size='small'
|
|
type='danger'
|
|
className='w-full'
|
|
onClick={() => {
|
|
Modal.confirm({
|
|
title: t('确定是否要删除禁用通道?'),
|
|
content: renderBatchDeleteContent(t),
|
|
onOk: () => deleteAllDisabledChannels(),
|
|
size: 'sm',
|
|
centered: true,
|
|
});
|
|
}}
|
|
>
|
|
{t('删除禁用通道')}
|
|
</Button>
|
|
</Dropdown.Item>
|
|
)}
|
|
</Dropdown.Menu>
|
|
}
|
|
>
|
|
<Button
|
|
size='small'
|
|
theme='light'
|
|
type='tertiary'
|
|
className='w-full md:w-auto'
|
|
>
|
|
{t('批量操作')}
|
|
</Button>
|
|
</Dropdown>
|
|
|
|
<CompactModeToggle
|
|
compactMode={compactMode}
|
|
setCompactMode={setCompactMode}
|
|
t={t}
|
|
/>
|
|
</div>
|
|
|
|
{/* 右侧:设置开关区域 */}
|
|
<div className='flex flex-col md:flex-row items-start md:items-center gap-2 w-full md:w-auto order-1 md:order-2'>
|
|
<div className='flex items-center justify-between w-full md:w-auto'>
|
|
<Typography.Text strong className='mr-2'>
|
|
{t('标签聚合模式')}
|
|
</Typography.Text>
|
|
<Switch
|
|
size='small'
|
|
checked={enableTagMode}
|
|
onChange={(v) => {
|
|
localStorage.setItem('enable-tag-mode', v + '');
|
|
setEnableTagMode(v);
|
|
setActivePage(1);
|
|
loadChannels(1, pageSize, idSort, v);
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ChannelsActions;
|