2aa9d73325
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
160 lines
4.9 KiB
React
160 lines
4.9 KiB
React
import { Plus as ActionPlus } from '@/components/common/icons/ActionIcons';
|
|
import React from 'react';
|
|
import { Modal } from '@/components/ui';
|
|
import { Button } from 'antd';
|
|
import { IconEdit, IconClose } from '@/components/ui/icons';
|
|
import {
|
|
getLobeHubIcon,
|
|
showError,
|
|
showSuccess,
|
|
isRoot,
|
|
} from '../../../helpers';
|
|
import { API } from '../../../helpers';
|
|
import './models-vendor-tabs.css';
|
|
|
|
const ModelsTabs = ({
|
|
activeVendorKey,
|
|
setActiveVendorKey,
|
|
vendorCounts,
|
|
vendors,
|
|
loadModels,
|
|
activePage,
|
|
pageSize,
|
|
setActivePage,
|
|
setShowAddVendor,
|
|
setShowEditVendor,
|
|
setEditingVendor,
|
|
loadVendors,
|
|
t,
|
|
}) => {
|
|
const canManageVendors = isRoot();
|
|
|
|
const handleTabChange = (key) => {
|
|
setActiveVendorKey(key);
|
|
setActivePage(1);
|
|
loadModels(1, pageSize, key);
|
|
};
|
|
|
|
const handleEditVendor = (vendor, e) => {
|
|
e.stopPropagation();
|
|
setEditingVendor(vendor);
|
|
setShowEditVendor(true);
|
|
};
|
|
|
|
const handleDeleteVendor = async (vendor, e) => {
|
|
e.stopPropagation();
|
|
try {
|
|
const res = await API.delete(`/api/vendors/${vendor.id}`);
|
|
if (res.data.success) {
|
|
showSuccess(t('供应商删除成功'));
|
|
// 如果删除的是当前选中的供应商,切换到"全部"
|
|
if (activeVendorKey === String(vendor.id)) {
|
|
setActiveVendorKey('all');
|
|
loadModels(1, pageSize, 'all');
|
|
} else {
|
|
loadModels(activePage, pageSize, activeVendorKey);
|
|
}
|
|
loadVendors(); // 重新加载供应商列表
|
|
} else {
|
|
showError(res.data.message || t('删除失败'));
|
|
}
|
|
} catch (error) {
|
|
showError(error.response?.data?.message || t('删除失败'));
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className='models-vendor-toolbar'>
|
|
<div className='models-vendor-list' role='group' aria-label={t('供应商')}>
|
|
<div
|
|
className={`models-vendor-group${activeVendorKey === 'all' ? ' is-selected' : ''}`}
|
|
>
|
|
<Button
|
|
type='text'
|
|
className='models-vendor-filter'
|
|
aria-pressed={activeVendorKey === 'all'}
|
|
onClick={() => handleTabChange('all')}
|
|
>
|
|
<span>{t('全部')}</span>
|
|
<span className='models-vendor-count'>{vendorCounts.all || 0}</span>
|
|
</Button>
|
|
</div>
|
|
{vendors.map((vendor) => {
|
|
const key = String(vendor.id);
|
|
return (
|
|
<div
|
|
key={key}
|
|
className={`models-vendor-group${activeVendorKey === key ? ' is-selected' : ''}`}
|
|
>
|
|
<Button
|
|
type='text'
|
|
className='models-vendor-filter'
|
|
aria-pressed={activeVendorKey === key}
|
|
onClick={() => handleTabChange(key)}
|
|
>
|
|
<span className='models-vendor-icon'>
|
|
{getLobeHubIcon(vendor.icon || 'Layers', 14)}
|
|
</span>
|
|
<span className='models-vendor-name' title={vendor.name}>
|
|
{vendor.name}
|
|
</span>
|
|
<span className='models-vendor-count'>
|
|
{vendorCounts[vendor.id] || 0}
|
|
</span>
|
|
</Button>
|
|
{canManageVendors && (
|
|
<div className='models-vendor-actions'>
|
|
<Button
|
|
type='text'
|
|
size='small'
|
|
icon={<IconEdit />}
|
|
aria-label={`${t('编辑')}${vendor.name}`}
|
|
title={t('编辑')}
|
|
onClick={(e) => handleEditVendor(vendor, e)}
|
|
/>
|
|
<Button
|
|
type='text'
|
|
danger
|
|
size='small'
|
|
icon={<IconClose />}
|
|
aria-label={`${t('删除')}${vendor.name}`}
|
|
title={t('删除')}
|
|
onClick={(e) => {
|
|
e.stopPropagation();
|
|
Modal.confirm({
|
|
title: t('确认删除'),
|
|
content: t(
|
|
'确定要删除供应商 "{{name}}" 吗?此操作不可撤销。',
|
|
{ name: vendor.name },
|
|
),
|
|
onOk: () => handleDeleteVendor(vendor, e),
|
|
okText: t('删除'),
|
|
cancelText: t('取消'),
|
|
type: 'warning',
|
|
okType: 'danger',
|
|
});
|
|
}}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
})}
|
|
</div>
|
|
{canManageVendors && (
|
|
<Button
|
|
className='console-create-action'
|
|
type='primary'
|
|
size='middle'
|
|
icon={<ActionPlus size={16} />}
|
|
onClick={() => setShowAddVendor(true)}
|
|
>
|
|
{t('新增供应商')}
|
|
</Button>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default ModelsTabs;
|