sync: 同步 monkey-ai@weiyuan(ddc5b9443) 的 web/ 到 ui-optimization
- 合入 weiyuan 新功能前端:分佣 V2 / 伙伴工作台、智能路由、企业资金与分析、官网设置与预约演示等, semi-ui 已全部迁移到 antd 6 / @/components/ui,不重新引入 Semi - 分佣二级菜单与页头去重、伙伴入口探测(企业伙伴走企业中心「企业分佣」)、超管侧栏入口恢复 - 适配层 DatePicker / TimePicker 统一 onChange(Date|Date[]|null, 文本) 契约;生产构建剔除调试日志 - 图片链接刷新:同任务请求复用、后台刷新不弹全局错误、离页停止批量请求 - 恢复 bun.lock(与 package-lock.json 共存);docs 规范与 CHANGELOG 更新 - 停止跟踪 .env.playwright.local(本地登录凭据,已加入 .gitignore)
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
/*
|
||||
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, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Empty,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { Plus } from '../common/icons/ActionIcons';
|
||||
import { copy, showError, showSuccess } from '../../helpers';
|
||||
import { deleteProfile, listCandidateModels, listProfiles } from './api';
|
||||
import ProfileEditor from './ProfileEditor';
|
||||
import SimulateModal from './SimulateModal';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
const ProfileTable = ({ mode, orgId, canWrite = true, emptyHint }) => {
|
||||
const { t } = useTranslation();
|
||||
const [list, setList] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState('');
|
||||
const [editing, setEditing] = useState(null); // null 关闭;{} 新建;profile 编辑
|
||||
const [simulating, setSimulating] = useState(null);
|
||||
const [models, setModels] = useState([]);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
try {
|
||||
setList((await listProfiles(mode, orgId)) || []);
|
||||
} catch (e) {
|
||||
setError(e?.message || t('加载失败'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [mode, orgId, t]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!canWrite) return;
|
||||
listCandidateModels(mode, orgId)
|
||||
.then(setModels)
|
||||
.catch(() => setModels([]));
|
||||
}, [mode, orgId, canWrite]);
|
||||
|
||||
const strategyText = (s) =>
|
||||
({ quality: t('质量优先'), balanced: t('平衡'), cost: t('成本优先') })[s] ||
|
||||
s;
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('虚拟模型'),
|
||||
dataIndex: 'virtual_model',
|
||||
width: 280,
|
||||
render: (v, r) => (
|
||||
<div className='min-w-0'>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
className='smart-router-mono smart-router-copy'
|
||||
aria-label={`${t('复制')} ${v}`}
|
||||
onClick={async () => {
|
||||
if (await copy(v)) showSuccess(t('已复制'));
|
||||
}}
|
||||
>
|
||||
{v}
|
||||
</Button>
|
||||
<div>
|
||||
<Text
|
||||
type='secondary'
|
||||
className='smart-router-sub smart-router-name'
|
||||
ellipsis={{ tooltip: r.name }}
|
||||
>
|
||||
{r.name}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('策略'),
|
||||
dataIndex: 'strategy',
|
||||
width: 110,
|
||||
render: strategyText,
|
||||
},
|
||||
{
|
||||
title: t('候选模型'),
|
||||
dataIndex: 'models',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (ms) => (
|
||||
<span className='smart-router-num'>
|
||||
{(ms || []).filter((m) => m.enabled).length}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('默认模型'),
|
||||
dataIndex: 'default_model',
|
||||
width: 220,
|
||||
render: (v) => <span className='smart-router-mono'>{v}</span>,
|
||||
},
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 140,
|
||||
render: (v, r) => (
|
||||
<Space size={8}>
|
||||
{v === 1 ? (
|
||||
<Tag color='success' variant='filled'>
|
||||
{t('启用')}
|
||||
</Tag>
|
||||
) : (
|
||||
<Tag color='default' variant='filled'>
|
||||
{t('停用')}
|
||||
</Tag>
|
||||
)}
|
||||
{r.jev_allowed && (
|
||||
<Tag color='blue' variant='filled'>
|
||||
Jev
|
||||
</Tag>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
key: 'actions',
|
||||
fixed: 'right',
|
||||
width: 180,
|
||||
render: (_, r) => (
|
||||
<Space size={8} wrap>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => setSimulating(r)}
|
||||
disabled={!canWrite}
|
||||
>
|
||||
{t('试路由')}
|
||||
</Button>
|
||||
{canWrite && (
|
||||
<>
|
||||
<Button type='link' size='small' onClick={() => setEditing(r)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title={t('确认删除该集合?')}
|
||||
description={t('使用该虚拟模型名的请求将返回"模型不存在"。')}
|
||||
okButtonProps={{ danger: true }}
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
await deleteProfile(mode, orgId, r.id);
|
||||
showSuccess(t('已删除'));
|
||||
load();
|
||||
} catch (e) {
|
||||
if (e?.message) showError(e.message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='smart-router-stack'>
|
||||
<div className='smart-router-toolbar'>
|
||||
<Text type='secondary' className='smart-router-sub'>
|
||||
{emptyHint}
|
||||
</Text>
|
||||
{canWrite && (
|
||||
<Button
|
||||
type='primary'
|
||||
icon={<Plus size={16} />}
|
||||
onClick={() => setEditing({})}
|
||||
>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{error ? (
|
||||
<Alert
|
||||
type='error'
|
||||
showIcon
|
||||
title={error}
|
||||
action={
|
||||
<Button size='small' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<Table
|
||||
rowKey='id'
|
||||
size='middle'
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
pagination={false}
|
||||
scroll={{ x: 'max-content' }}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由集合')}
|
||||
>
|
||||
{canWrite && (
|
||||
<Button type='primary' onClick={() => setEditing({})}>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</Empty>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<ProfileEditor
|
||||
visible={editing !== null}
|
||||
mode={mode}
|
||||
orgId={orgId}
|
||||
profile={editing && editing.id ? editing : null}
|
||||
candidateModels={models}
|
||||
onClose={() => setEditing(null)}
|
||||
onSaved={() => {
|
||||
setEditing(null);
|
||||
load();
|
||||
}}
|
||||
/>
|
||||
<SimulateModal
|
||||
visible={!!simulating}
|
||||
mode={mode}
|
||||
orgId={orgId}
|
||||
profile={simulating}
|
||||
onClose={() => setSimulating(null)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ProfileTable;
|
||||
Reference in New Issue
Block a user