34e318454d
- 公共表格:统一分组标签、状态开关和危险操作确认,支持防重复提交和失败重试,修复浮层触发组件的 ref 转发。 - 控制台:统一用户和渠道编辑抽屉,修正分组回填与提交格式,对齐系统设置操作区和预约列表。 - 企业中心:调整技能中心页签和窄屏布局,优化质量监控提示栏、效能分析及成本对账,统一消耗明细和审计日志筛选。 - 用户中心及公共页面:优化密钥和消费记录展示,对齐模型超市筛选,统一公开与内嵌客户端下载页。 - 同步多语言文案、组件规范与移动端视口要求。
286 lines
7.8 KiB
React
286 lines
7.8 KiB
React
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
|
import '../../../console/module-alignment.css';
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
|
import {
|
|
SideSheet,
|
|
Button,
|
|
Typography,
|
|
Space,
|
|
Tag,
|
|
Card,
|
|
Avatar,
|
|
Spin,
|
|
Empty,
|
|
} from '@/components/ui';
|
|
import { IconPlus, IconLayers } from '@/components/ui/icons';
|
|
import {
|
|
IllustrationNoResult,
|
|
IllustrationNoResultDark,
|
|
} from '../../../common/illustrations';
|
|
import {
|
|
API,
|
|
showError,
|
|
showSuccess,
|
|
stringToColor,
|
|
} from '../../../../helpers';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
|
|
import CardTable from '../../../common/ui/CardTable';
|
|
import EditPrefillGroupModal from './EditPrefillGroupModal';
|
|
import {
|
|
renderLimitedItems,
|
|
renderDescription,
|
|
} from '../../../common/ui/RenderUtils';
|
|
|
|
const { Text } = Typography;
|
|
|
|
const PrefillGroupManagement = ({ visible, onClose }) => {
|
|
const { t } = useTranslation();
|
|
const isMobile = useIsMobile();
|
|
const [loading, setLoading] = useState(false);
|
|
const [groups, setGroups] = useState([]);
|
|
const [showEdit, setShowEdit] = useState(false);
|
|
const [editingGroup, setEditingGroup] = useState({ id: undefined });
|
|
|
|
const typeOptions = [
|
|
{ label: t('模型组'), value: 'model' },
|
|
{ label: t('标签组'), value: 'tag' },
|
|
{ label: t('端点组'), value: 'endpoint' },
|
|
];
|
|
|
|
// 加载组列表
|
|
const loadGroups = useCallback(async () => {
|
|
setLoading(true);
|
|
try {
|
|
const res = await API.get('/api/prefill_group');
|
|
if (res.data.success) {
|
|
setGroups(res.data.data || []);
|
|
} else {
|
|
showError(res.data.message || t('获取组列表失败'));
|
|
}
|
|
} catch (error) {
|
|
showError(t('获取组列表失败'));
|
|
}
|
|
setLoading(false);
|
|
}, [t]);
|
|
|
|
// 删除组
|
|
const deleteGroup = async (id) => {
|
|
try {
|
|
const res = await API.delete(`/api/prefill_group/${id}`);
|
|
if (res.data.success) {
|
|
showSuccess(t('删除成功'));
|
|
loadGroups();
|
|
return true;
|
|
} else {
|
|
showError(res.data.message || t('删除失败'));
|
|
}
|
|
} catch (error) {
|
|
showError(t('删除失败'));
|
|
}
|
|
return false;
|
|
};
|
|
|
|
// 编辑组
|
|
const handleEdit = (group = {}) => {
|
|
setEditingGroup(group);
|
|
setShowEdit(true);
|
|
};
|
|
|
|
// 关闭编辑
|
|
const closeEdit = () => {
|
|
setShowEdit(false);
|
|
setTimeout(() => {
|
|
setEditingGroup({ id: undefined });
|
|
}, 300);
|
|
};
|
|
|
|
// 编辑成功回调
|
|
const handleEditSuccess = () => {
|
|
closeEdit();
|
|
loadGroups();
|
|
};
|
|
|
|
// 表格列定义
|
|
const columns = [
|
|
{
|
|
title: t('组名'),
|
|
dataIndex: 'name',
|
|
key: 'name',
|
|
render: (text, record) => (
|
|
<Space>
|
|
<Text strong>{text}</Text>
|
|
<Tag color='white' shape='circle' size='small'>
|
|
{typeOptions.find((opt) => opt.value === record.type)?.label ||
|
|
record.type}
|
|
</Tag>
|
|
</Space>
|
|
),
|
|
},
|
|
{
|
|
title: t('描述'),
|
|
dataIndex: 'description',
|
|
key: 'description',
|
|
render: (text) => renderDescription(text, 150),
|
|
},
|
|
{
|
|
title: t('项目内容'),
|
|
dataIndex: 'items',
|
|
key: 'items',
|
|
render: (items, record) => {
|
|
try {
|
|
if (record.type === 'endpoint') {
|
|
const obj =
|
|
typeof items === 'string'
|
|
? JSON.parse(items || '{}')
|
|
: items || {};
|
|
const keys = Object.keys(obj);
|
|
if (keys.length === 0)
|
|
return <Text type='tertiary'>{t('暂无项目')}</Text>;
|
|
return renderLimitedItems({
|
|
items: keys,
|
|
renderItem: (key, idx) => (
|
|
<Tag
|
|
key={idx}
|
|
size='small'
|
|
shape='circle'
|
|
color={stringToColor(key)}
|
|
>
|
|
{key}
|
|
</Tag>
|
|
),
|
|
maxDisplay: 3,
|
|
});
|
|
}
|
|
const itemsArray =
|
|
typeof items === 'string' ? JSON.parse(items) : items;
|
|
if (!Array.isArray(itemsArray) || itemsArray.length === 0) {
|
|
return <Text type='tertiary'>{t('暂无项目')}</Text>;
|
|
}
|
|
return renderLimitedItems({
|
|
items: itemsArray,
|
|
renderItem: (item, idx) => (
|
|
<Tag
|
|
key={idx}
|
|
size='small'
|
|
shape='circle'
|
|
color={stringToColor(item)}
|
|
>
|
|
{item}
|
|
</Tag>
|
|
),
|
|
maxDisplay: 3,
|
|
});
|
|
} catch {
|
|
return <Text type='tertiary'>{t('数据格式错误')}</Text>;
|
|
}
|
|
},
|
|
},
|
|
{
|
|
title: t('操作'),
|
|
key: 'action',
|
|
fixed: 'right',
|
|
width: 140,
|
|
render: (_, record) => (
|
|
<Space className='console-module-row-actions'>
|
|
<Button type='link' size='small' onClick={() => handleEdit(record)}>
|
|
{t('编辑')}
|
|
</Button>
|
|
<TableActionPopconfirm
|
|
title={t('确定删除此组?')}
|
|
onConfirm={() => deleteGroup(record.id)}
|
|
>
|
|
<Button size='small' type='link' danger>
|
|
{t('删除')}
|
|
</Button>
|
|
</TableActionPopconfirm>
|
|
</Space>
|
|
),
|
|
},
|
|
];
|
|
|
|
useEffect(() => {
|
|
if (visible) {
|
|
loadGroups();
|
|
}
|
|
}, [visible, loadGroups]);
|
|
|
|
return (
|
|
<>
|
|
<SideSheet
|
|
rootClassName='console-model-drawer'
|
|
placement='right'
|
|
title={t('预填组管理')}
|
|
classNames={{ header: 'prefill-management-header' }}
|
|
visible={visible}
|
|
onCancel={onClose}
|
|
width={isMobile ? '100%' : 800}
|
|
bodyStyle={{ padding: '0' }}
|
|
>
|
|
<Spin spinning={loading}>
|
|
<div className='p-2'>
|
|
<Card className='!rounded-2xl shadow-sm border-0'>
|
|
<div className='console-model-section'>
|
|
<Avatar size='small' color='blue'>
|
|
<IconLayers size={16} />
|
|
</Avatar>
|
|
<div>
|
|
<Text className='text-lg font-medium'>{t('组列表')}</Text>
|
|
<div className='text-xs text-gray-600'>
|
|
{t('管理模型、标签、端点等预填组')}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className='flex justify-end mb-4'>
|
|
<Button
|
|
className='console-create-action'
|
|
type='primary'
|
|
theme='solid'
|
|
size='small'
|
|
icon={<IconPlus />}
|
|
onClick={() => handleEdit()}
|
|
>
|
|
{t('新建组')}
|
|
</Button>
|
|
</div>
|
|
{groups.length > 0 ? (
|
|
<CardTable
|
|
columns={columns}
|
|
dataSource={groups}
|
|
rowKey='id'
|
|
hidePagination={true}
|
|
size='small'
|
|
scroll={{ x: 'max-content' }}
|
|
/>
|
|
) : (
|
|
<Empty
|
|
image={
|
|
<IllustrationNoResult style={{ width: 150, height: 150 }} />
|
|
}
|
|
darkModeImage={
|
|
<IllustrationNoResultDark
|
|
style={{ width: 150, height: 150 }}
|
|
/>
|
|
}
|
|
description={t('暂无预填组')}
|
|
style={{ padding: 30 }}
|
|
/>
|
|
)}
|
|
</Card>
|
|
</div>
|
|
</Spin>
|
|
</SideSheet>
|
|
|
|
{/* 编辑组件 */}
|
|
<EditPrefillGroupModal
|
|
visible={showEdit}
|
|
onClose={closeEdit}
|
|
editingGroup={editingGroup}
|
|
onSuccess={handleEditSuccess}
|
|
/>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default PrefillGroupManagement;
|