feat: 参考原型图 ui优化提交 企业端-企业中心 相关的页面
This commit is contained in:
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Switch } from 'antd';
|
||||
import {
|
||||
Table,
|
||||
Button,
|
||||
@@ -27,11 +28,11 @@ import {
|
||||
Tag,
|
||||
Select,
|
||||
} from '@/components/ui';
|
||||
import { RefreshCw, Plus, Users } from 'lucide-react';
|
||||
import { RefreshCw, Plus } from 'lucide-react';
|
||||
import { API } from '../../helpers/api';
|
||||
import { showError, collectPagedItems } from '../../helpers';
|
||||
import OrgPageHeader from './components/OrgPageHeader';
|
||||
import OrgPanel from './components/OrgPanel';
|
||||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||||
import OrgModal from './components/OrgModal';
|
||||
import OrgScopedLimitButtons from './components/OrgScopedLimitButtons';
|
||||
|
||||
@@ -42,6 +43,7 @@ const OrgProjects = ({ orgId }) => {
|
||||
const { t } = useTranslation();
|
||||
const [list, setList] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [updatingProjectId, setUpdatingProjectId] = useState(null);
|
||||
const [members, setMembers] = useState([]); // 企业全部成员(用于成员选择)
|
||||
|
||||
const [modalVisible, setModalVisible] = useState(false);
|
||||
@@ -53,7 +55,7 @@ const OrgProjects = ({ orgId }) => {
|
||||
const [addMemberIds, setAddMemberIds] = useState([]); // 支持一次添加多个成员
|
||||
const [addMemberRole, setAddMemberRole] = useState('project_member');
|
||||
|
||||
const [tokenModal, setTokenModal] = useState(null); // 当前管理令牌的项目
|
||||
const [tokenModal, setTokenModal] = useState(null); // 当前管理密钥的项目
|
||||
const [orgTokens, setOrgTokens] = useState([]);
|
||||
|
||||
const fetchList = useCallback(async () => {
|
||||
@@ -158,19 +160,34 @@ const OrgProjects = ({ orgId }) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDisable = async (record) => {
|
||||
const handleStatusChange = async (record, enabled) => {
|
||||
if (updatingProjectId !== null) return;
|
||||
setUpdatingProjectId(record.id);
|
||||
try {
|
||||
const res = await API.delete(`/api/org/project/${record.id}`, {
|
||||
headers: getOrgHeaders(orgId),
|
||||
});
|
||||
const url = `/api/org/project/${record.id}`;
|
||||
const config = { headers: getOrgHeaders(orgId) };
|
||||
const res = enabled
|
||||
? await API.put(
|
||||
url,
|
||||
{ code: record.code, name: record.name, status: 1 },
|
||||
config,
|
||||
)
|
||||
: await API.delete(url, config);
|
||||
if (res.data.success) {
|
||||
Toast.success(t('项目已停用'));
|
||||
fetchList();
|
||||
Toast.success(t('项目已更新'));
|
||||
setList((items) =>
|
||||
items.map((item) =>
|
||||
item.id === record.id ? { ...item, status: enabled ? 1 : 2 } : item,
|
||||
),
|
||||
);
|
||||
await fetchList();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err.message);
|
||||
} finally {
|
||||
setUpdatingProjectId(null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -287,104 +304,116 @@ const OrgProjects = ({ orgId }) => {
|
||||
}));
|
||||
}, [members, projectMembers]);
|
||||
|
||||
// 列宽与渲染对齐原型 EnterpriseProjects(150/350/120/140/300,scroll.x 1060);
|
||||
const columns = [
|
||||
{ title: t('项目编码'), dataIndex: 'code' },
|
||||
{ title: t('项目名称'), dataIndex: 'name' },
|
||||
{
|
||||
title: t('项目编码'),
|
||||
dataIndex: 'code',
|
||||
width: 150,
|
||||
render: (v) => <span className='oc-number'>{v}</span>,
|
||||
},
|
||||
{ title: t('项目名称'), dataIndex: 'name', width: 350 },
|
||||
{
|
||||
title: t('状态'),
|
||||
dataIndex: 'status',
|
||||
width: 90,
|
||||
render: (v) => (
|
||||
<Tag color={v === 1 ? 'green' : 'grey'}>
|
||||
{v === 1 ? t('启用') : t('停用')}
|
||||
</Tag>
|
||||
width: 120,
|
||||
render: (v, record) => (
|
||||
<Popconfirm
|
||||
title={t('确认停用该项目?')}
|
||||
content={t('停用后保留历史,不再接受新调用绑定')}
|
||||
disabled={v !== 1 || updatingProjectId !== null}
|
||||
onConfirm={() => handleStatusChange(record, false)}
|
||||
>
|
||||
<Switch
|
||||
size='small'
|
||||
checked={v === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
aria-label={`${record.name} ${t('状态')}`}
|
||||
loading={updatingProjectId === record.id}
|
||||
disabled={updatingProjectId !== null}
|
||||
onChange={(checked) => {
|
||||
if (checked) handleStatusChange(record, true);
|
||||
}}
|
||||
/>
|
||||
</Popconfirm>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('到期时间'),
|
||||
dataIndex: 'expired_at',
|
||||
width: 120,
|
||||
width: 140,
|
||||
render: (v) => (v ? new Date(v * 1000).toLocaleDateString() : '-'),
|
||||
},
|
||||
{
|
||||
title: t('操作'),
|
||||
width: 420,
|
||||
width: 300,
|
||||
render: (_, record) => (
|
||||
<div className='flex items-center gap-2 flex-wrap'>
|
||||
<OrgRowActions>
|
||||
<OrgScopedLimitButtons
|
||||
orgId={orgId}
|
||||
record={record}
|
||||
apiBase='/api/org/project'
|
||||
scopeLabel='项目'
|
||||
onSaved={fetchList}
|
||||
variant='link'
|
||||
/>
|
||||
<Button
|
||||
size='small'
|
||||
theme='light'
|
||||
icon={<Users size={14} />}
|
||||
onClick={() => openMembers(record)}
|
||||
>
|
||||
<Button type='link' onClick={() => openMembers(record)}>
|
||||
{t('成员')}
|
||||
</Button>
|
||||
<Button size='small' theme='light' onClick={() => openTokens(record)}>
|
||||
{t('令牌')}
|
||||
<Button type='link' onClick={() => openTokens(record)}>
|
||||
{t('密钥')}
|
||||
</Button>
|
||||
<Button size='small' theme='light' onClick={() => openEdit(record)}>
|
||||
<Button type='link' onClick={() => openEdit(record)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
{record.status === 1 && (
|
||||
<Popconfirm
|
||||
title={t('确认停用该项目?')}
|
||||
content={t('停用后保留历史,不再接受新调用绑定')}
|
||||
onConfirm={() => handleDisable(record)}
|
||||
>
|
||||
<Button size='small' theme='light' type='danger'>
|
||||
{t('停用')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
)}
|
||||
</div>
|
||||
</OrgRowActions>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className='uc-page'>
|
||||
<div className='uc-page oc-page'>
|
||||
<OrgPageHeader
|
||||
title={t('项目管理')}
|
||||
subtitle={t('项目成员与项目预算')}
|
||||
actions={
|
||||
subtitle={t('管理项目成员、模型范围与密钥归属')}
|
||||
/>
|
||||
|
||||
<OrgListCard
|
||||
title={t('项目列表')}
|
||||
tools={
|
||||
<>
|
||||
<Button
|
||||
theme='light'
|
||||
icon={<RefreshCw size={14} />}
|
||||
onClick={fetchList}
|
||||
>
|
||||
<Button icon={<RefreshCw size={16} />} onClick={fetchList}>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
icon={<Plus size={14} />}
|
||||
icon={<Plus size={16} />}
|
||||
onClick={openCreate}
|
||||
>
|
||||
{t('新建项目')}
|
||||
</Button>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
|
||||
<OrgPanel padding='p-2'>
|
||||
>
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={list}
|
||||
loading={loading}
|
||||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||||
pagination={{
|
||||
pageSize: 15,
|
||||
showSizeChanger: false,
|
||||
showTotal: (total) => t('共 {{total}} 条', { total }),
|
||||
}}
|
||||
rowKey='id'
|
||||
scroll={{ x: 1060 }}
|
||||
/>
|
||||
</OrgPanel>
|
||||
</OrgListCard>
|
||||
|
||||
{/* 项目创建/编辑 */}
|
||||
<OrgModal
|
||||
className='oc-dialog'
|
||||
width={560}
|
||||
title={editing ? t('编辑项目') : t('新建项目')}
|
||||
visible={modalVisible}
|
||||
onOk={handleSubmit}
|
||||
@@ -420,6 +449,8 @@ const OrgProjects = ({ orgId }) => {
|
||||
|
||||
{/* 项目成员管理 */}
|
||||
<OrgModal
|
||||
className='oc-dialog oc-dialog-table'
|
||||
width={760}
|
||||
title={`${t('项目成员')} - ${memberModal?.name || ''}`}
|
||||
visible={!!memberModal}
|
||||
onCancel={() => setMemberModal(null)}
|
||||
@@ -489,17 +520,18 @@ const OrgProjects = ({ orgId }) => {
|
||||
/>
|
||||
</OrgModal>
|
||||
|
||||
{/* 项目令牌绑定 */}
|
||||
{/* 项目密钥绑定 */}
|
||||
<OrgModal
|
||||
title={`${t('项目令牌')} - ${tokenModal?.name || ''}`}
|
||||
className='oc-dialog oc-dialog-table'
|
||||
title={`${t('项目密钥')} - ${tokenModal?.name || ''}`}
|
||||
visible={!!tokenModal}
|
||||
onCancel={() => setTokenModal(null)}
|
||||
footer={null}
|
||||
width={560}
|
||||
width={760}
|
||||
>
|
||||
<Table
|
||||
columns={[
|
||||
{ title: t('令牌'), dataIndex: 'name' },
|
||||
{ title: t('密钥'), dataIndex: 'name' },
|
||||
{
|
||||
title: t('当前归属'),
|
||||
dataIndex: 'project_id',
|
||||
|
||||
Reference in New Issue
Block a user