feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面

This commit is contained in:
zhanjunhao
2026-11-09 21:45:37 +08:00
parent 54b3e0cc21
commit 5c0849e82b
242 changed files with 9242 additions and 5043 deletions
@@ -19,6 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Button, Tag } from '@/components/ui';
import { RefreshCw } from 'lucide-react';
import { isAdmin } from '../../../helpers';
const AdminTokensActions = ({
@@ -30,7 +31,7 @@ const AdminTokensActions = ({
const hasSelection = selectedRowKeys && selectedRowKeys.length > 0;
return (
<div className='flex flex-wrap items-center gap-2 w-full md:w-auto order-2 md:order-1'>
<div className='admin-tokens-tools'>
{hasSelection && (
<Tag color='violet' shape='circle' size='small'>
{t('已选 {{count}} 项', { count: selectedRowKeys.length })}
@@ -57,7 +58,7 @@ const AdminTokensActions = ({
</Button>
</>
)}
<Button size='small' type='tertiary' onClick={onRefresh}>
<Button icon={<RefreshCw size={16} />} onClick={onRefresh}>
{t('刷新')}
</Button>
</div>
@@ -18,15 +18,8 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Button,
Space,
Tag,
Typography,
Popover,
Dropdown,
} from '@/components/ui';
import { IconMore } from '@/components/ui/icons';
import { Button, Switch, Tag as AntTag } from 'antd';
import { Tag, Typography, Popover } from '@/components/ui';
import {
renderGroup,
renderQuota,
@@ -37,18 +30,33 @@ import {
const { Text } = Typography;
const statusMeta = {
1: { color: 'green', label: '已启用' },
2: { color: 'grey', label: '已禁用' },
3: { color: 'red', label: '已过期' },
4: { color: 'orange', label: '已耗尽' },
3: { color: 'error', label: '已过期' },
4: { color: 'warning', label: '已耗尽' },
};
const renderStatus = (status, t) => {
const meta = statusMeta[status] || { color: 'red', label: t('未知状态') };
const renderStatus = (status, record, t, showEnableDisableModal) => {
const meta =
statusMeta[status] ||
(![1, 2].includes(status) ? { color: 'error', label: '未知状态' } : null);
return (
<Tag color={meta.color} shape='circle' size='small'>
{t(meta.label)}
</Tag>
<div className='admin-tokens-status'>
<Switch
size='small'
checked={status === 1}
checkedChildren={t('启用')}
unCheckedChildren={t('禁用')}
aria-label={status === 1 ? t('禁用') : t('启用')}
disabled={!isAdmin() || Boolean(record.DeletedAt)}
onChange={() =>
showEnableDisableModal(record, status === 1 ? 'disable' : 'enable')
}
/>
{meta && (
<AntTag color={meta.color} bordered={false}>
{t(meta.label)}
</AntTag>
)}
</div>
);
};
@@ -72,21 +80,17 @@ const renderUserCell = (text, record, t) => {
);
};
const renderKey = (text, record) => {
const renderKey = (text) => {
// 后端已脱敏,前端再加 sk- 前缀
return (
<code className='text-xs bg-[var(--ui-color-fill-0)] px-2 py-0.5 rounded font-mono'>
sk-{text}
</code>
);
return <code className='admin-tokens-key'>sk-{text}</code>;
};
const renderQuotaCell = (text, record, t) => {
if (record.unlimited_quota) {
return (
<Tag color='violet' shape='circle' size='small'>
<AntTag color='success' bordered={false}>
{t('无限制')}
</Tag>
</AntTag>
);
}
const used = record.used_quota || 0;
@@ -103,9 +107,7 @@ const renderQuotaCell = (text, record, t) => {
);
return (
<Popover content={popoverContent} position='top'>
<Tag color='white' shape='circle' size='small'>
{renderQuota(remain)}
</Tag>
<span>{renderQuota(remain)}</span>
</Popover>
);
};
@@ -113,13 +115,8 @@ const renderQuotaCell = (text, record, t) => {
const renderTime = (ts, t) => {
if (!ts || ts === 0)
return <span className='text-[var(--ui-color-text-2)]'>—</span>;
if (ts === -1)
return (
<Tag color='blue' shape='circle' size='small'>
{t('永不过期')}
</Tag>
);
return <span className='text-xs'>{timestamp2string(ts)}</span>;
if (ts === -1) return <span>{t('永不过期')}</span>;
return <span>{timestamp2string(ts)}</span>;
};
const renderScope = (orgId, t) => {
@@ -140,51 +137,28 @@ const renderScope = (orgId, t) => {
const renderOperations = (
text,
record,
{ showEditTokenModal, showEnableDisableModal, showDeleteTokenModal, t },
{ showEditTokenModal, showDeleteTokenModal, t },
) => {
if (record.DeletedAt) return <></>;
const isEnabled = record.status === 1;
if (!isAdmin()) return null;
return (
<Space>
<div className='admin-tokens-row-actions'>
<Button
size='small'
type='tertiary'
type='link'
onClick={() => showEditTokenModal(record)}
>
{t('编辑')}
</Button>
{isEnabled ? (
<Button
size='small'
type='danger'
onClick={() => showEnableDisableModal(record, 'disable')}
>
{t('禁用')}
</Button>
) : (
<Button
size='small'
onClick={() => showEnableDisableModal(record, 'enable')}
>
{t('启用')}
</Button>
)}
<Dropdown
trigger='click'
position='bottomRight'
menu={[
{
node: 'item',
name: t('删除'),
type: 'danger',
onClick: () => showDeleteTokenModal(record),
},
]}
<Button
size='small'
type='link'
danger
onClick={() => showDeleteTokenModal(record)}
>
<Button size='small' type='tertiary' icon={<IconMore />} />
</Dropdown>
</Space>
{t('删除')}
</Button>
</div>
);
};
@@ -207,10 +181,13 @@ export const getAdminTokensColumns = ({
render: (text, record) => renderUserCell(text, record, t),
},
{
title: t('密钥名称'),
title: t('名称'),
dataIndex: 'name',
render: (text) => (
<span className='truncate inline-block max-w-[160px]' title={text}>
<span
className='admin-tokens-name truncate inline-block max-w-[160px]'
title={text}
>
{text || <Text type='tertiary'>—</Text>}
</span>
),
@@ -223,8 +200,9 @@ export const getAdminTokensColumns = ({
{
title: t('状态'),
dataIndex: 'status',
width: 90,
render: (text) => renderStatus(text, t),
width: 150,
render: (text, record) =>
renderStatus(text, record, t, showEnableDisableModal),
},
{
title: t('归属'),
@@ -248,11 +226,7 @@ export const getAdminTokensColumns = ({
title: t('已用额度'),
dataIndex: 'used_quota',
width: 110,
render: (text) => (
<Text type='tertiary' size='small'>
{renderQuota(text || 0)}
</Text>
),
render: (text) => <span>{renderQuota(text || 0)}</span>,
},
{
title: t('创建时间'),
@@ -273,14 +247,13 @@ export const getAdminTokensColumns = ({
render: (text) => renderTime(text, t),
},
{
title: '',
title: t('操作'),
dataIndex: 'operate',
fixed: 'right',
width: 200,
width: 130,
render: (text, record) =>
renderOperations(text, record, {
showEditTokenModal,
showEnableDisableModal,
showDeleteTokenModal,
t,
}),
@@ -18,29 +18,10 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Typography, Tag } from '@/components/ui';
import { IconKey } from '@/components/ui/icons';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
import { TableTitle } from '../../common/table/TableToolbar';
const { Text } = Typography;
const AdminTokensDescription = ({ compactMode, setCompactMode, t }) => {
return (
<div className='flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full'>
<div className='flex items-center gap-2 text-brand'>
<IconKey />
<Text>{t('密钥管理')}</Text>
<Tag color='orange' shape='circle' size='small'>
{t('管理员')}
</Tag>
</div>
<CompactModeToggle
compactMode={compactMode}
setCompactMode={setCompactMode}
t={t}
/>
</div>
);
};
const AdminTokensDescription = ({ t }) => (
<TableTitle>{t('密钥列表')}</TableTitle>
);
export default AdminTokensDescription;
@@ -20,12 +20,13 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useRef } from 'react';
import { Form, Button } from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import FilterSearchButton from '../../common/table/FilterSearchButton';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
const AdminTokensFilters = ({
formInitValues,
setFormApi,
searchTokens,
debouncedSearch,
loadTokens,
pageSize,
groupOptions,
@@ -34,61 +35,71 @@ const AdminTokensFilters = ({
t,
}) => {
const formApiRef = useRef(null);
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
() => searchTokens(pageSize),
);
const handleReset = () => {
if (!formApiRef.current) return;
formApiRef.current.reset();
cancelPendingSearch();
// 重置后立即用初始值刷新(不走 debounce)
loadTokens(1, pageSize, formInitValues);
};
return (
<Form
initValues={formInitValues}
initValues={{
...formInitValues,
group: formInitValues.group === '' ? undefined : formInitValues.group,
unlimited:
formInitValues.unlimited === ''
? undefined
: formInitValues.unlimited,
}}
getFormApi={(api) => {
setFormApi(api);
formApiRef.current = api;
}}
onSubmit={() => searchTokens(pageSize)}
onSubmit={submitSearch}
onValueChange={scheduleSearch}
allowEmpty
autoComplete='off'
layout='horizontal'
layout='vertical'
trigger='change'
className='w-full md:w-auto order-1 md:order-2'
className='admin-tokens-filter-form'
>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto flex-wrap'>
<div className='w-full md:w-56'>
<div className='admin-tokens-filter-grid'>
<div className='admin-tokens-filter-field'>
<Form.Input
field='keyword'
label={t('密钥名称 / Key 片段')}
prefix={<IconSearch />}
placeholder={t('密钥名称 / Key 片段')}
showClear
pure
size='small'
/>
</div>
<div className='w-full md:w-44'>
<div className='admin-tokens-filter-field'>
<Form.Input
field='user_keyword'
label={t('用户名/昵称')}
placeholder={t('用户名/昵称')}
showClear
pure
size='small'
/>
</div>
<div className='w-full md:w-28'>
<div className='admin-tokens-filter-field'>
<Form.Input
field='user_id'
label={t('用户ID')}
placeholder={t('用户ID')}
type='number'
showClear
pure
size='small'
/>
</div>
<div className='w-full md:w-44'>
<div className='admin-tokens-filter-field'>
<Form.Select
field='statuses'
label={t('状态')}
placeholder={t('状态(多选)')}
multiple
optionList={[
@@ -98,42 +109,36 @@ const AdminTokensFilters = ({
{ label: t('已耗尽'), value: 4 },
]}
showClear
pure
size='small'
className='w-full'
onChange={debouncedSearch}
/>
</div>
<div className='w-full md:w-36'>
<div className='admin-tokens-filter-field'>
<Form.Select
field='group'
label={t('分组')}
placeholder={t('分组')}
optionList={groupOptions}
showClear
pure
size='small'
className='w-full'
onChange={debouncedSearch}
/>
</div>
<div className='w-full md:w-32'>
<div className='admin-tokens-filter-field'>
<Form.Select
field='unlimited'
placeholder={t('额度类型')}
label={t('剩余额度')}
placeholder={t('剩余额度')}
optionList={[
{ label: t('无限额度'), value: true },
{ label: t('有限额度'), value: false },
]}
showClear
pure
size='small'
className='w-full'
onChange={debouncedSearch}
/>
</div>
<div className='w-full md:w-32'>
<div className='admin-tokens-filter-field'>
<Form.Select
field='org_scope'
label={t('归属')}
placeholder={t('归属')}
optionList={[
{ label: t('全部'), value: 'all' },
@@ -141,25 +146,13 @@ const AdminTokensFilters = ({
{ label: t('企业'), value: 'org' },
]}
showClear={false}
pure
size='small'
className='w-full'
onChange={debouncedSearch}
/>
</div>
<div className='flex gap-2 w-full md:w-auto'>
<Button
type='tertiary'
htmlType='submit'
loading={loading || searching}
size='small'
>
{t('查询')}
</Button>
<Button type='tertiary' onClick={handleReset} size='small'>
{t('重置')}
</Button>
</div>
</div>
<div className='admin-tokens-filter-actions'>
<Button onClick={handleReset}>{t('重置')}</Button>
<FilterSearchButton loading={loading || searching} />
</div>
</Form>
);
@@ -17,13 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo } from 'react';
import { Empty } from '@/components/ui';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getAdminTokensColumns } from './AdminTokensColumnDefs';
const AdminTokensTable = ({
@@ -32,7 +29,6 @@ const AdminTokensTable = ({
activePage,
pageSize,
tokenCount,
compactMode,
selectedRowKeys,
setSelectedRowKeys,
handlePageChange,
@@ -72,20 +68,6 @@ const AdminTokensTable = ({
[t],
);
const tableColumns = useMemo(
() =>
compactMode
? columns.map((col) => {
if (col.dataIndex === 'operate') {
const { fixed, ...rest } = col;
return rest;
}
return col;
})
: columns,
[compactMode, columns],
);
const rowSelection = {
selectedRowKeys,
onChange: (keys) => setSelectedRowKeys(keys),
@@ -93,10 +75,10 @@ const AdminTokensTable = ({
return (
<CardTable
columns={tableColumns}
columns={columns}
dataSource={tokens}
rowKey='id'
scroll={compactMode ? undefined : { x: 'max-content' }}
scroll={{ x: 'max-content' }}
pagination={{
currentPage: activePage,
pageSize: pageSize,
@@ -110,17 +92,8 @@ const AdminTokensTable = ({
loading={loading}
onRow={handleRow}
rowSelection={rowSelection}
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
className='overflow-hidden'
empty={<TableEmpty />}
className='admin-tokens-table overflow-hidden'
size='middle'
/>
);
@@ -0,0 +1,92 @@
.console-page .console-search-card .admin-tokens-filter-form {
display: block;
}
.admin-tokens-filter-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 1rem;
width: 100%;
}
.console-page .admin-tokens-filter-grid .ant-form-item-label > label {
color: var(--console-muted);
font-size: 13px;
}
.admin-tokens-filter-actions,
.admin-tokens-tools {
display: flex;
align-items: center;
justify-content: flex-end;
flex-wrap: wrap;
gap: 0.5rem;
}
.admin-tokens-filter-actions {
margin-top: 1rem;
}
.admin-tokens-toolbar {
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
gap: 1.25rem;
width: 100%;
margin-bottom: 0.25rem;
}
.admin-tokens-tools {
margin-inline-start: auto;
}
.console-page .console-table.admin-tokens-table .ant-table-thead > tr > th {
height: 46px;
padding-block: 0;
font-weight: 400;
}
.admin-tokens-name {
font-weight: 700;
}
.admin-tokens-key {
font-family: SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
font-size: 12px;
line-height: 21px;
}
.admin-tokens-status,
.admin-tokens-row-actions {
display: flex;
align-items: center;
gap: 6px;
}
.admin-tokens-status {
flex-wrap: wrap;
gap: 8px;
}
.admin-tokens-status .ant-tag {
margin-inline-end: 0;
}
.admin-tokens-row-actions .ant-btn {
height: auto;
padding: 0 4px;
font-size: 13px;
}
@media (max-width: 1100px) {
.admin-tokens-filter-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 768px) {
.admin-tokens-filter-grid {
grid-template-columns: minmax(0, 1fr);
}
}
+16 -22
View File
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import './admin-tokens.css';
import CardPro from '../../common/ui/CardPro';
import AdminTokensTable from './AdminTokensTable';
import AdminTokensActions from './AdminTokensActions';
@@ -79,9 +80,6 @@ const AdminTokensPage = () => {
handlePageSizeChange,
handleRow,
compactMode,
setCompactMode,
t,
} = data;
@@ -150,37 +148,34 @@ const AdminTokensPage = () => {
/>
<CardPro
type='type1'
descriptionArea={
<AdminTokensDescription
compactMode={compactMode}
setCompactMode={setCompactMode}
searchArea={
<AdminTokensFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchTokens={searchTokens}
debouncedSearch={debouncedSearch}
loadTokens={loadTokens}
pageSize={pageSize}
groupOptions={groupOptions}
loading={loading}
searching={searching}
t={t}
/>
}
type='type1'
actionsArea={
<div className='flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full'>
<div className='admin-tokens-toolbar'>
<AdminTokensDescription t={t} />
<AdminTokensActions
selectedRowKeys={selectedRowKeys}
onBatchAction={handleBatchClick}
onRefresh={refresh}
t={t}
/>
<AdminTokensFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchTokens={searchTokens}
debouncedSearch={debouncedSearch}
loadTokens={loadTokens}
pageSize={pageSize}
groupOptions={groupOptions}
loading={loading}
searching={searching}
t={t}
/>
</div>
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: activePage,
pageSize: pageSize,
total: tokenCount,
@@ -197,7 +192,6 @@ const AdminTokensPage = () => {
activePage={activePage}
pageSize={pageSize}
tokenCount={tokenCount}
compactMode={compactMode}
selectedRowKeys={selectedRowKeys}
setSelectedRowKeys={setSelectedRowKeys}
handlePageChange={handlePageChange}
@@ -24,7 +24,7 @@ const { Text } = Typography;
const AdminDeleteTokenModal = ({ visible, onCancel, onConfirm, token, t }) => {
if (!token) return null;
const isOrgToken = token.organization_id && token.organization_id > 0;
const isOrgToken = token.organization_id > 0;
return (
<Modal
@@ -20,10 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useEffect, useRef, useState } from 'react';
import { Modal, Form, Typography, Banner, Spin, Tag } from '@/components/ui';
import { API, showError, renderQuotaWithPrompt } from '../../../../helpers';
import {
quotaToMoney,
moneyToQuota,
} from '../../../common/ui/QuotaInput';
import { quotaToMoney, moneyToQuota } from '../../../common/ui/QuotaInput';
const { Text } = Typography;
@@ -131,7 +128,7 @@ const AdminEditTokenModal = ({
if (!token) return null;
const isOrgToken = token.organization_id && token.organization_id > 0;
const isOrgToken = token.organization_id > 0;
const curStatusMeta = statusMeta[token.status] || statusMeta[2];
return (
@@ -18,14 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Button,
Dropdown,
Modal,
Switch,
Typography,
Select,
} from '@/components/ui';
import { Button, Dropdown, Modal, Switch, Typography } from '@/components/ui';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
import { isRoot } from '../../../helpers';
@@ -40,7 +33,7 @@ const renderBatchDeleteContent = (t) => (
);
const ChannelsActions = ({
enableBatchDelete,
selectedChannels,
batchDeleteChannels,
setShowBatchSetTag,
testAllChannels,
@@ -50,17 +43,9 @@ const ChannelsActions = ({
compactMode,
setCompactMode,
idSort,
setIdSort,
setEnableBatchDelete,
enableTagMode,
setEnableTagMode,
statusFilter,
setStatusFilter,
getFormValues,
loadChannels,
searchChannels,
activeTypeKey,
activePage,
pageSize,
setActivePage,
t,
@@ -74,7 +59,7 @@ const ChannelsActions = ({
{isRoot() && (
<Button
size='small'
disabled={!enableBatchDelete}
disabled={!selectedChannels.length}
type='danger'
className='w-full md:w-auto'
onClick={() => {
@@ -92,7 +77,7 @@ const ChannelsActions = ({
{isRoot() && (
<Button
size='small'
disabled={!enableBatchDelete}
disabled={!selectedChannels.length}
type='tertiary'
onClick={() => setShowBatchSetTag(true)}
className='w-full md:w-auto'
@@ -209,54 +194,6 @@ const ChannelsActions = ({
{/* 右侧:设置开关区域 */}
<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('使用ID排序')}
</Typography.Text>
<Switch
size='small'
checked={idSort}
onChange={(v) => {
localStorage.setItem('id-sort', v + '');
setIdSort(v);
const { searchKeyword, searchGroup, searchModel } =
getFormValues();
if (
searchKeyword === '' &&
searchGroup === '' &&
searchModel === ''
) {
loadChannels(activePage, pageSize, v, enableTagMode);
} else {
searchChannels(
enableTagMode,
activeTypeKey,
statusFilter,
activePage,
pageSize,
v,
);
}
}}
/>
</div>
{isRoot() && (
<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={enableBatchDelete}
onChange={(v) => {
localStorage.setItem('enable-batch-delete', v + '');
setEnableBatchDelete(v);
}}
/>
</div>
)}
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('标签聚合模式')}
@@ -272,33 +209,6 @@ const ChannelsActions = ({
}}
/>
</div>
<div className='flex items-center justify-between w-full md:w-auto'>
<Typography.Text strong className='mr-2'>
{t('状态筛选')}
</Typography.Text>
<Select
size='small'
value={statusFilter}
onChange={(v) => {
localStorage.setItem('channel-status-filter', v);
setStatusFilter(v);
setActivePage(1);
loadChannels(
1,
pageSize,
idSort,
enableTagMode,
activeTypeKey,
v,
);
}}
>
<Select.Option value='all'>{t('全部')}</Select.Option>
<Select.Option value='enabled'>{t('已启用')}</Select.Option>
<Select.Option value='disabled'>{t('已禁用')}</Select.Option>
</Select>
</div>
</div>
</div>
</div>
@@ -17,15 +17,15 @@ 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 { writeClipboardText } from '../../../helpers/clipboard';
import React, { useState } from 'react';
import { Switch } from 'antd';
import {
Button,
Dropdown,
InputNumber,
Modal,
Progress,
Space,
SplitButtonGroup,
Tag,
Tooltip,
} from '@/components/ui';
@@ -42,9 +42,39 @@ import {
hoverOrClickTrigger,
} from '../../../helpers';
import { CHANNEL_OPTIONS } from '../../../constants';
import { IconTreeTriangleDown, IconMore } from '@/components/ui/icons';
import { IconTreeTriangleDown } from '@/components/ui/icons';
import { ShuffleBrandIcon } from '../../common/icons/BrandIcons';
function ChannelStatusSwitch({ record, manageChannel, t }) {
const [loading, setLoading] = useState(false);
return (
<Switch
size='small'
checked={record.status === 1}
checkedChildren={t('启用')}
unCheckedChildren={t('禁用')}
disabled={!isRoot()}
loading={loading}
aria-label={t('状态')}
onClick={(_, event) => event.stopPropagation()}
onChange={async (checked) => {
setLoading(true);
try {
await manageChannel(
record.id,
checked ? 'enable' : 'disable',
record,
);
} catch (error) {
showError(error.message);
} finally {
setLoading(false);
}
}}
/>
);
}
// 删除单个渠道的确认文案:若该渠道被其他渠道列为兜底,追加影响说明。
// 查询失败不阻塞删除,仅回退为原确认文案
const buildDeleteConfirmContent = async (channelId, t) => {
@@ -360,8 +390,7 @@ export const getChannelsColumns = ({
theme='outline'
onClick={(e) => {
e.stopPropagation();
navigator.clipboard
.writeText(record.remark)
writeClipboardText(record.remark)
.then(() => {
showSuccess(t('复制成功'));
})
@@ -425,13 +454,46 @@ export const getChannelsColumns = ({
title: t('状态'),
dataIndex: 'status',
render: (text, record, index) => {
const statusControl =
record.children !== undefined ? (
renderStatus(text, record.channel_info, t)
) : (
<Space>
<ChannelStatusSwitch
record={record}
manageChannel={manageChannel}
t={t}
/>
{record.channel_info?.is_multi_key && (
<span>
{(record.channel_info.multi_key_size || 0) -
Object.keys(record.channel_info.multi_key_status_list || {})
.length}
/{record.channel_info.multi_key_size || 0}
</span>
)}
</Space>
);
if (text === 3) {
if (record.other_info === '') {
record.other_info = '{}';
let otherInfo;
try {
otherInfo =
typeof record.other_info === 'string'
? JSON.parse(record.other_info)
: record.other_info;
} catch {
return statusControl;
}
let otherInfo = JSON.parse(record.other_info);
let reason = otherInfo['status_reason'];
let time = otherInfo['status_time'];
if (
!otherInfo ||
typeof otherInfo !== 'object' ||
Array.isArray(otherInfo) ||
(!otherInfo.status_reason && !otherInfo.status_time)
) {
return statusControl;
}
const reason = otherInfo.status_reason || '';
const time = otherInfo.status_time;
return (
<div>
<Tooltip
@@ -439,12 +501,12 @@ export const getChannelsColumns = ({
t('原因:') + reason + t(',时间:') + timestamp2string(time)
}
>
{renderStatus(text, record.channel_info, t)}
{statusControl}
</Tooltip>
</div>
);
} else {
return renderStatus(text, record.channel_info, t);
return statusControl;
}
},
},
@@ -660,7 +722,7 @@ export const getChannelsColumns = ({
},
{
key: COLUMN_KEYS.OPERATE,
title: '',
title: t('操作'),
dataIndex: 'operate',
fixed: 'right',
render: (text, record, index) => {
@@ -704,105 +766,63 @@ export const getChannelsColumns = ({
];
return (
<Space wrap>
<Space wrap className='console-module-row-actions'>
{isRoot() && (
<SplitButtonGroup
className='overflow-hidden'
aria-label={t('测试单个渠道操作项目组')}
>
<>
<Button
type='link'
size='small'
type='tertiary'
onClick={() => testChannel(record, '')}
>
{t('测试')}
</Button>
<Button
type='link'
size='small'
type='tertiary'
icon={<IconTreeTriangleDown />}
onClick={() => {
setCurrentTestChannel(record);
setShowModelTestModal(true);
}}
/>
</SplitButtonGroup>
)}
{isRoot() && (
<>
{record.status === 1 ? (
>
{t('批量测试')}
</Button>
<Button
type='link'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
}}
>
{t('编辑')}
</Button>
<Button
type='link'
danger
size='small'
onClick={moreMenuItems[0].onClick}
>
{t('删除')}
</Button>
<Button
type='link'
size='small'
onClick={moreMenuItems[1].onClick}
>
{t('复制')}
</Button>
{record.channel_info?.is_multi_key && (
<Button
type='danger'
size='small'
onClick={() =>
manageChannel(record.id, 'disable', record)
}
>
{t('禁用')}
</Button>
) : (
<Button
size='small'
onClick={() => manageChannel(record.id, 'enable', record)}
>
{t('启用')}
</Button>
)}
{record.channel_info?.is_multi_key ? (
<SplitButtonGroup aria-label={t('多密钥渠道操作项目组')}>
<Button
type='tertiary'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
}}
>
{t('编辑')}
</Button>
<Dropdown
trigger='click'
position='bottomRight'
menu={[
{
node: 'item',
name: t('多密钥管理'),
onClick: () => {
setCurrentMultiKeyChannel(record);
setShowMultiKeyManageModal(true);
},
},
]}
>
<Button
type='tertiary'
size='small'
icon={<IconTreeTriangleDown />}
/>
</Dropdown>
</SplitButtonGroup>
) : (
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setEditingChannel(record);
setShowEdit(true);
setCurrentMultiKeyChannel(record);
setShowMultiKeyManageModal(true);
}}
>
{t('编辑')}
{t('多密钥管理')}
</Button>
)}
<Dropdown
trigger='click'
position='bottomRight'
menu={moreMenuItems}
>
<Button icon={<IconMore />} type='tertiary' size='small' />
</Dropdown>
</>
)}
</Space>
@@ -814,21 +834,21 @@ export const getChannelsColumns = ({
{isRoot() && (
<>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => manageTag(record.key, 'enable')}
>
{t('启用全部')}
</Button>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => manageTag(record.key, 'disable')}
>
{t('禁用全部')}
</Button>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setShowEditTag(true);
+99 -128
View File
@@ -18,15 +18,12 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Button, Form } from '@/components/ui';
import { Form } from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import { isRoot } from '../../../helpers';
import { ConsoleFilterActions } from '../../console/ConsoleModuleFilters';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
const ChannelsFilters = ({
setEditingChannel,
setShowEdit,
refresh,
setShowColumnSelector,
formInitValues,
setFormApi,
searchChannels,
@@ -37,148 +34,122 @@ const ChannelsFilters = ({
searching,
autoBanExclusionFilter,
setAutoBanExclusionFilter,
statusFilter,
setStatusFilter,
t,
}) => {
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
() => searchChannels(enableTagMode),
);
return (
<div className='flex flex-col md:flex-row justify-between items-center gap-2 w-full'>
<div className='flex gap-2 w-full md:w-auto order-2 md:order-1'>
{isRoot() && (
<Button
size='small'
theme='light'
type='primary'
className='w-full md:w-auto'
onClick={() => {
setEditingChannel({
id: undefined,
});
setShowEdit(true);
}}
>
{t('添加渠道')}
</Button>
)}
<Button
size='small'
type='tertiary'
className='w-full md:w-auto'
onClick={refresh}
>
{t('刷新')}
</Button>
<Button
size='small'
type='tertiary'
onClick={() => setShowColumnSelector(true)}
className='w-full md:w-auto'
>
{t('列设置')}
</Button>
</div>
<div className='w-full'>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto order-1 md:order-2'>
<Form
initValues={formInitValues}
initValues={{
...formInitValues,
searchGroup: formInitValues.searchGroup || undefined,
}}
getFormApi={(api) => setFormApi(api)}
onSubmit={() => searchChannels(enableTagMode)}
onSubmit={submitSearch}
onValueChange={scheduleSearch}
allowEmpty={true}
autoComplete='off'
layout='horizontal'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='flex flex-col md:flex-row items-center gap-2 w-full'
className='console-module-filter-form'
>
<div className='relative w-full md:w-64'>
<Form.Input
size='small'
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('渠道ID,名称,密钥,API地址')}
showClear
pure
/>
<div className='console-module-filter-grid'>
<div className='console-module-field'>
<Form.Input
label={t('渠道ID,名称,密钥,API地址')}
size='small'
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('渠道ID,名称,密钥,API地址')}
showClear
/>
</div>
<div className='console-module-field'>
<Form.Input
label={t('模型名称')}
size='small'
field='searchModel'
prefix={<IconSearch />}
placeholder={t('模型关键字')}
showClear
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('分组')}
size='small'
field='searchGroup'
placeholder={t('选择分组')}
optionList={[...groupOptions]}
className='w-full'
showClear
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('自动封禁')}
size='small'
placeholder={t('自动封禁')}
value={autoBanExclusionFilter}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('参与'), value: 'included' },
{ label: t('已排除'), value: 'excluded' },
]}
className='w-full'
showClear
onChange={(value) => {
const newValue = value || 'all';
localStorage.setItem(
'channel-autoban-exclusion-filter',
newValue,
);
setAutoBanExclusionFilter(newValue);
scheduleSearch();
}}
/>
</div>
<div className='console-module-field'>
<Form.Select
label={t('状态')}
placeholder={t('全部状态')}
value={statusFilter}
onChange={(value) => {
localStorage.setItem('channel-status-filter', value);
setStatusFilter(value);
scheduleSearch();
}}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('已启用'), value: 'enabled' },
{ label: t('已禁用'), value: 'disabled' },
]}
/>
</div>
</div>
<div className='w-full md:w-48'>
<Form.Input
size='small'
field='searchModel'
prefix={<IconSearch />}
placeholder={t('模型关键字')}
showClear
pure
/>
</div>
<div className='w-full md:w-32'>
<Form.Select
size='small'
field='searchGroup'
placeholder={t('选择分组')}
optionList={[
{ label: t('选择分组'), value: null },
...groupOptions,
]}
className='w-full'
showClear
pure
onChange={() => {
// 延迟执行搜索,让表单值先更新
setTimeout(() => {
searchChannels(enableTagMode);
}, 0);
}}
/>
</div>
<div className='w-full md:w-32'>
<Form.Select
size='small'
field='autoBanExclusionFilter'
placeholder={t('自动封禁')}
value={autoBanExclusionFilter}
optionList={[
{ label: t('全部'), value: 'all' },
{ label: t('参与'), value: 'included' },
{ label: t('已排除'), value: 'excluded' },
]}
className='w-full'
showClear
pure
onChange={(value) => {
const newValue = value || 'all';
localStorage.setItem(
'channel-autoban-exclusion-filter',
newValue,
);
setAutoBanExclusionFilter(newValue);
}}
/>
</div>
<Button
size='small'
type='tertiary'
htmlType='submit'
<ConsoleFilterActions
loading={loading || searching}
className='w-full md:w-auto'
>
{t('查询')}
</Button>
<Button
size='small'
type='tertiary'
onClick={() => {
onReset={() => {
if (formApi) {
formApi.reset();
cancelPendingSearch();
setStatusFilter('all');
setAutoBanExclusionFilter('all');
localStorage.setItem('channel-status-filter', 'all');
localStorage.setItem('channel-autoban-exclusion-filter', 'all');
// 重置后立即查询,使用setTimeout确保表单重置完成
setTimeout(() => {
refresh();
searchChannels(enableTagMode, undefined, 'all');
}, 100);
}
}}
className='w-full md:w-auto'
>
{t('重置')}
</Button>
/>
</Form>
</div>
</div>
+47 -21
View File
@@ -17,13 +17,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo } from 'react';
import { Empty } from '@/components/ui';
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { isRoot } from '../../../helpers';
import { getChannelsColumns } from './ChannelsColumnDefs';
const ChannelsTable = (channelsData) => {
@@ -34,7 +32,7 @@ const ChannelsTable = (channelsData) => {
activePage,
pageSize,
channelCount,
enableBatchDelete,
selectedChannels,
compactMode,
visibleColumns,
setSelectedChannels,
@@ -66,8 +64,25 @@ const ChannelsTable = (channelsData) => {
autoBanExclusionFilter,
// Daily quota info
dailyQuotaInfo,
idSort,
setIdSort,
enableTagMode,
loadChannels,
} = channelsData;
const [idSortOrder, setIdSortOrder] = useState('descend');
const handleTableChange = ({ sorter, extra, action }) => {
if ((action ?? extra?.action) !== 'sort') return;
const order = sorter?.columnKey === COLUMN_KEYS.ID ? sorter.order : null;
setIdSortOrder(order || 'descend');
const nextIdSort = Boolean(order);
if (nextIdSort === idSort) return;
localStorage.setItem('id-sort', String(nextIdSort));
setIdSort(nextIdSort);
loadChannels(activePage, pageSize, nextIdSort, enableTagMode);
};
// Filter channels based on auto-ban exclusion filter
const filteredChannels = useMemo(() => {
if (!autoBanExclusionFilter || autoBanExclusionFilter === 'all') {
@@ -174,14 +189,28 @@ const ChannelsTable = (channelsData) => {
}, [visibleColumns, allColumns]);
const tableColumns = useMemo(() => {
const sortableColumns = visibleColumnsList.map((column) =>
column.key === COLUMN_KEYS.ID
? {
...column,
sorter: (a, b) => {
if (a.children !== undefined || b.children !== undefined)
return 0;
return Number(a.id) - Number(b.id);
},
sortOrder: idSort ? idSortOrder : null,
}
: column,
);
return compactMode
? visibleColumnsList.map(({ fixed, ...rest }) => rest)
: visibleColumnsList;
}, [compactMode, visibleColumnsList]);
? sortableColumns.map(({ fixed, ...rest }) => rest)
: sortableColumns;
}, [compactMode, visibleColumnsList, COLUMN_KEYS.ID, idSort, idSortOrder]);
return (
<CardTable
columns={tableColumns}
onChange={handleTableChange}
dataSource={filteredChannels}
scroll={compactMode ? undefined : { x: 'max-content' }}
pagination={{
@@ -197,24 +226,21 @@ const ChannelsTable = (channelsData) => {
expandAllRows={false}
onRow={handleRow}
rowSelection={
enableBatchDelete
isRoot()
? {
selectedRowKeys: selectedChannels.map(
(channel) => channel.key ?? String(channel.id),
),
getCheckboxProps: (record) => ({
disabled: record.children !== undefined,
}),
onChange: (selectedRowKeys, selectedRows) => {
setSelectedChannels(selectedRows);
},
}
: null
}
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
empty={<TableEmpty />}
className='rounded-xl overflow-hidden'
size='middle'
loading={loading || searching}
+29 -5
View File
@@ -19,8 +19,11 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Tabs, TabPane, Tag } from '@/components/ui';
import { Button } from 'antd';
import { Plus } from 'lucide-react';
import { CHANNEL_OPTIONS } from '../../../constants';
import { getChannelIcon } from '../../../helpers';
import { getChannelIcon, isRoot } from '../../../helpers';
import './channels-tabs.css';
const ChannelsTabs = ({
enableTagMode,
@@ -33,9 +36,30 @@ const ChannelsTabs = ({
pageSize,
idSort,
setActivePage,
setEditingChannel,
setShowEdit,
t,
}) => {
if (enableTagMode) return null;
const createButton = isRoot() ? (
<Button
className='console-create-action'
type='primary'
size='middle'
icon={<Plus size={16} />}
onClick={() => {
setEditingChannel({ id: undefined });
setShowEdit(true);
}}
>
{t('创建渠道')}
</Button>
) : null;
if (enableTagMode) {
return createButton ? (
<div className='flex justify-end'>{createButton}</div>
) : null;
}
const handleTabChange = (key) => {
setActiveTypeKey(key);
@@ -46,10 +70,10 @@ const ChannelsTabs = ({
return (
<Tabs
activeKey={activeTypeKey}
type='card'
collapsible
type='line'
onChange={handleTabChange}
className='mb-2'
className='channels-tabs mb-2'
tabBarExtraContent={createButton}
>
<TabPane
itemKey='all'
@@ -0,0 +1,5 @@
.channels-tabs > .ant-tabs-nav > .ant-tabs-extra-content {
align-self: flex-end;
/* Match the space below the tab labels above the navigation divider. */
margin-bottom: 12px;
}
+10
View File
@@ -19,6 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import ChannelsTable from './ChannelsTable';
import ChannelsActions from './ChannelsActions';
import ChannelsFilters from './ChannelsFilters';
@@ -64,11 +65,20 @@ const ChannelsPage = () => {
{/* Main Content */}
<CardPro
tableTitle={channelsData.t('渠道列表')}
tableActionsOffset
type='type3'
tabsArea={<ChannelsTabs {...channelsData} />}
actionsArea={<ChannelsActions {...channelsData} />}
searchArea={<ChannelsFilters {...channelsData} />}
tableActions={
<ColumnSettingsButton
open={channelsData.showColumnSelector}
onClick={() => channelsData.setShowColumnSelector(true)}
/>
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: channelsData.activePage,
pageSize: channelsData.pageSize,
total: channelsData.channelCount,
@@ -18,16 +18,15 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Checkbox } from '@/components/ui';
import { ColumnVisibilitySettings } from '../../../common/table/ColumnSettings';
import { getChannelsColumns } from '../ChannelsColumnDefs';
const ColumnSelectorModal = ({
showColumnSelector,
setShowColumnSelector,
visibleColumns,
handleColumnVisibilityChange,
handleSelectAll,
initDefaultColumns,
setVisibleColumns,
getDefaultColumnVisibility,
COLUMN_KEYS,
t,
// Props needed for getChannelsColumns
@@ -69,59 +68,14 @@ const ColumnSelectorModal = ({
});
return (
<Modal
title={t('列设置')}
visible={showColumnSelector}
onCancel={() => setShowColumnSelector(false)}
footer={
<div className='flex justify-end'>
<Button onClick={() => initDefaultColumns()}>{t('重置')}</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('取消')}
</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('确定')}
</Button>
</div>
}
>
<div style={{ marginBottom: 20 }}>
<Checkbox
checked={Object.values(visibleColumns).every((v) => v === true)}
indeterminate={
Object.values(visibleColumns).some((v) => v === true) &&
!Object.values(visibleColumns).every((v) => v === true)
}
onChange={(e) => handleSelectAll(e.target.checked)}
>
{t('全选')}
</Checkbox>
</div>
<div
className='flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4'
style={{ border: '1px solid var(--ui-color-border)' }}
>
{allColumns.map((column) => {
// Skip columns without title
if (!column.title) {
return null;
}
return (
<div key={column.key} className='w-1/2 mb-4 pr-2'>
<Checkbox
checked={!!visibleColumns[column.key]}
onChange={(e) =>
handleColumnVisibilityChange(column.key, e.target.checked)
}
>
{column.title}
</Checkbox>
</div>
);
})}
</div>
</Modal>
<ColumnVisibilitySettings
showColumnSelector={showColumnSelector}
setShowColumnSelector={setShowColumnSelector}
columns={allColumns.filter((column) => !!column.title)}
visibleColumns={visibleColumns}
setVisibleColumns={setVisibleColumns}
getDefaultColumnVisibility={getDefaultColumnVisibility}
/>
);
};
@@ -17,6 +17,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import '../../../console/module-alignment.css';
import React, { useEffect, useState, useRef, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import {
@@ -60,18 +61,14 @@ import ChannelKeyDisplay from '../../../common/ui/ChannelKeyDisplay';
import { useSecureVerification } from '../../../../hooks/common/useSecureVerification';
import { createApiCalls } from '../../../../services/secureVerification';
import {
IconSave,
IconClose,
IconServer,
IconSetting,
IconCode,
IconGlobe,
IconBolt,
IconChevronUp,
IconChevronDown,
} from '@/components/ui/icons';
const { Text, Title } = Typography;
const { Text } = Typography;
const MODEL_MAPPING_EXAMPLE = {
'gpt-3.5-turbo': 'gpt-3.5-turbo-0125',
@@ -351,23 +348,6 @@ const EditChannelModal = (props) => {
t,
]);
// 表单块导航相关状态
const formSectionRefs = useRef({
basicInfo: null,
apiConfig: null,
modelConfig: null,
advancedSettings: null,
channelExtraSettings: null,
});
const [currentSectionIndex, setCurrentSectionIndex] = useState(0);
const formSections = [
'basicInfo',
'apiConfig',
'modelConfig',
'advancedSettings',
'channelExtraSettings',
];
const formContainerRef = useRef(null);
const doubaoApiClickCountRef = useRef(0);
const initialModelsRef = useRef([]);
const initialModelMappingRef = useRef('');
@@ -411,43 +391,6 @@ const EditChannelModal = (props) => {
});
};
// 表单导航功能
const scrollToSection = (sectionKey) => {
const sectionElement = formSectionRefs.current[sectionKey];
if (sectionElement) {
sectionElement.scrollIntoView({
behavior: 'smooth',
block: 'start',
inline: 'nearest',
});
}
};
const navigateToSection = (direction) => {
const availableSections = formSections.filter((section) => {
if (section === 'apiConfig') {
return showApiConfigCard;
}
return true;
});
let newIndex;
if (direction === 'up') {
newIndex =
currentSectionIndex > 0
? currentSectionIndex - 1
: availableSections.length - 1;
} else {
newIndex =
currentSectionIndex < availableSections.length - 1
? currentSectionIndex + 1
: 0;
}
setCurrentSectionIndex(newIndex);
scrollToSection(availableSections[newIndex]);
};
const handleApiConfigSecretClick = () => {
if (inputs.type !== 45) return;
const next = doubaoApiClickCountRef.current + 1;
@@ -1055,8 +998,6 @@ const EditChannelModal = (props) => {
fetchModelGroups();
// 重置手动输入模式状态
setUseManualInput(false);
// 重置导航状态
setCurrentSectionIndex(0);
} else {
// 统一的模态框关闭重置逻辑
resetModalState();
@@ -1655,7 +1596,7 @@ const EditChannelModal = (props) => {
const batchAllowed = !isEdit || isMultiKeyChannel;
const batchExtra = batchAllowed ? (
<Space>
<Space wrap className='console-channel-key-actions'>
{!isEdit && (
<Checkbox
disabled={isEdit}
@@ -1827,76 +1768,25 @@ const EditChannelModal = (props) => {
return (
<>
<SideSheet
placement={isEdit ? 'right' : 'left'}
title={
<Space>
<Tag color='blue' shape='circle'>
{isEdit ? t('编辑') : t('新建')}
</Tag>
<Title heading={4} className='m-0'>
{isEdit ? t('更新渠道信息') : t('创建新的渠道')}
</Title>
</Space>
}
rootClassName='console-channel-drawer'
classNames={{ header: 'console-channel-editor-header' }}
placement='right'
title={isEdit ? t('更新渠道信息') : t('创建新的渠道')}
bodyStyle={{ padding: '0' }}
visible={props.visible}
width={isMobile ? '100%' : 600}
footer={
<div className='flex justify-between items-center'>
<div className='flex gap-2'>
<Button
size='small'
type='tertiary'
icon={<IconChevronUp />}
onClick={() => navigateToSection('up')}
style={{
borderRadius: '50%',
width: '32px',
height: '32px',
padding: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
title={t('上一个表单块')}
/>
<Button
size='small'
type='tertiary'
icon={<IconChevronDown />}
onClick={() => navigateToSection('down')}
style={{
borderRadius: '50%',
width: '32px',
height: '32px',
padding: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
title={t('下一个表单块')}
/>
</div>
<Space>
<Button
theme='solid'
onClick={() => formApiRef.current?.submitForm()}
icon={<IconSave />}
>
{t('提交')}
</Button>
<Button
theme='light'
type='primary'
onClick={handleCancel}
icon={<IconClose />}
>
{t('取消')}
</Button>
</Space>
<div className='console-channel-footer'>
<Button onClick={handleCancel}>{t('取消')}</Button>
<Button
theme='solid'
type='primary'
onClick={() => formApiRef.current?.submitForm()}
>
{t('提交')}
</Button>
</div>
}
closeIcon={null}
onCancel={() => handleCancel()}
>
<Form
@@ -1907,16 +1797,12 @@ const EditChannelModal = (props) => {
>
{() => (
<Spin spinning={loading}>
<div className='p-2' ref={formContainerRef}>
<div ref={(el) => (formSectionRefs.current.basicInfo = el)}>
<div className='console-channel-sections p-2'>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Basic Info */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='blue'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='blue'>
<IconServer size={16} />
</Avatar>
<div>
@@ -2438,9 +2324,8 @@ const EditChannelModal = (props) => {
<Form.Input
field='openai_organization'
label={t('组织')}
placeholder={t('请输入组织org-xxx')}
placeholder={t('组织 org-xxx(留空使用默认组织)')}
showClear
helpText={t('组织,不填则为默认组织')}
onChange={(value) =>
handleInputChange('openai_organization', value)
}
@@ -2451,18 +2336,14 @@ const EditChannelModal = (props) => {
{/* API Configuration Card */}
{showApiConfigCard && (
<div ref={(el) => (formSectionRefs.current.apiConfig = el)}>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: API Config */}
<div
className='flex items-center mb-2'
className='console-channel-section'
onClick={handleApiConfigSecretClick}
>
<Avatar
size='small'
color='green'
className='mr-2 shadow-md'
>
<Avatar size='small' color='green'>
<IconGlobe size={16} />
</Avatar>
<div>
@@ -2679,15 +2560,11 @@ const EditChannelModal = (props) => {
)}
{/* Model Configuration Card */}
<div ref={(el) => (formSectionRefs.current.modelConfig = el)}>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Model Config */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='purple'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='purple'>
<IconCode size={16} />
</Avatar>
<div>
@@ -2740,7 +2617,7 @@ const EditChannelModal = (props) => {
};
}}
extraText={
<Space wrap>
<Space wrap className='console-channel-model-actions'>
<Button
size='small'
type='primary'
@@ -2778,13 +2655,15 @@ const EditChannelModal = (props) => {
<Button
size='small'
type='tertiary'
onClick={() => {
onClick={async () => {
if (inputs.models.length === 0) {
showInfo(t('没有模型可以复制'));
return;
}
try {
copy(inputs.models.join(','));
if (!(await copy(inputs.models.join(',')))) {
throw new Error('Clipboard copy failed');
}
showSuccess(t('模型列表已复制到剪贴板'));
} catch (error) {
showError(t('复制失败'));
@@ -2888,17 +2767,11 @@ const EditChannelModal = (props) => {
</div>
{/* Advanced Settings Card */}
<div
ref={(el) => (formSectionRefs.current.advancedSettings = el)}
>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Advanced Settings */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='orange'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='orange'>
<IconSetting size={16} />
</Avatar>
<div>
@@ -3432,19 +3305,11 @@ const EditChannelModal = (props) => {
</div>
{/* Channel Extra Settings Card */}
<div
ref={(el) =>
(formSectionRefs.current.channelExtraSettings = el)
}
>
<div>
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
{/* Header: Channel Extra Settings */}
<div className='flex items-center mb-2'>
<Avatar
size='small'
color='violet'
className='mr-2 shadow-md'
>
<div className='console-channel-section'>
<Avatar size='small' color='violet'>
<IconBolt size={16} />
</Avatar>
<div>
@@ -17,19 +17,12 @@ 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 {
Modal,
Button,
Input,
Table,
Tag,
Typography,
Select,
} from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import React, { useState } from 'react';
import { Modal, Button, Input, Table, Tag, Typography, Select } from 'antd';
import { Search } from 'lucide-react';
import { copy, showError, showInfo, showSuccess } from '../../../../helpers';
import { MODEL_TABLE_PAGE_SIZE } from '../../../../constants';
import './model-test-modal.css';
const ModelTestModal = ({
showModelTestModal,
@@ -48,19 +41,19 @@ const ModelTestModal = ({
setModelTablePage,
selectedEndpointType,
setSelectedEndpointType,
allSelectingRef,
isMobile,
t,
}) => {
const [paginationSize, setPaginationSize] = useState(MODEL_TABLE_PAGE_SIZE);
const hasChannel = Boolean(currentTestChannel);
const models =
typeof currentTestChannel?.models === 'string'
? currentTestChannel.models.split(',').filter(Boolean)
: [];
const filteredModels = hasChannel
? currentTestChannel.models
.split(',')
.filter((model) =>
model.toLowerCase().includes(modelSearchKeyword.toLowerCase()),
)
: [];
const filteredModels = models.filter((model) =>
model.toLowerCase().includes(modelSearchKeyword.toLowerCase()),
);
const endpointTypeOptions = [
{ value: '', label: t('自动检测') },
@@ -100,8 +93,7 @@ const ModelTestModal = ({
const handleSelectSuccess = () => {
if (!currentTestChannel) return;
const successKeys = currentTestChannel.models
.split(',')
const successKeys = models
.filter((m) => m.toLowerCase().includes(modelSearchKeyword.toLowerCase()))
.filter((m) => {
const result = modelTestResults[`${currentTestChannel.id}-${m}`];
@@ -126,34 +118,27 @@ const ModelTestModal = ({
{
title: t('状态'),
dataIndex: 'status',
width: 112,
render: (text, record) => {
const testResult =
modelTestResults[`${currentTestChannel.id}-${record.model}`];
const isTesting = testingModels.has(record.model);
if (isTesting) {
return (
<Tag color='blue' shape='circle'>
{t('测试中')}
</Tag>
);
return <Tag color='processing'>{t('测试中')}</Tag>;
}
if (!testResult) {
return (
<Tag color='grey' shape='circle'>
{t('未开始')}
</Tag>
);
return <Tag>{t('未开始')}</Tag>;
}
return (
<div className='flex items-center gap-2'>
<Tag color={testResult.success ? 'green' : 'red'} shape='circle'>
<div className='model-test-status'>
<Tag color={testResult.success ? 'success' : 'error'}>
{testResult.success ? t('成功') : t('失败')}
</Tag>
{testResult.success && (
<Typography.Text type='tertiary'>
<Typography.Text type='secondary'>
{t('请求时长: ${time}s').replace(
'${time}',
testResult.time.toFixed(2),
@@ -165,13 +150,15 @@ const ModelTestModal = ({
},
},
{
title: '',
title: t('操作'),
dataIndex: 'operate',
width: 72,
align: 'left',
render: (text, record) => {
const isTesting = testingModels.has(record.model);
return (
<Button
type='tertiary'
type='link'
onClick={() =>
testChannel(
currentTestChannel,
@@ -191,9 +178,7 @@ const ModelTestModal = ({
const dataSource = (() => {
if (!hasChannel) return [];
const start = (modelTablePage - 1) * MODEL_TABLE_PAGE_SIZE;
const end = start + MODEL_TABLE_PAGE_SIZE;
return filteredModels.slice(start, end).map((model) => ({
return filteredModels.map((model) => ({
model,
key: model,
}));
@@ -202,114 +187,110 @@ const ModelTestModal = ({
return (
<Modal
title={
hasChannel ? (
<div className='flex flex-col gap-2 w-full'>
<div className='flex items-center gap-2'>
<Typography.Text
strong
className='!text-[var(--ui-color-text-0)] !text-base'
>
{currentTestChannel.name} {t('渠道的模型测试')}
</Typography.Text>
<Typography.Text type='tertiary' size='small'>
{t('共')} {currentTestChannel.models.split(',').length}{' '}
{t('个模型')}
</Typography.Text>
</div>
</div>
) : null
hasChannel ? `${currentTestChannel.name} ${t('渠道的模型测试')}` : null
}
visible={showModelTestModal}
open={showModelTestModal}
onCancel={handleCloseModal}
footer={
hasChannel ? (
<div className='flex justify-end'>
<div className='model-test-footer'>
{isBatchTesting ? (
<Button type='danger' onClick={handleCloseModal}>
<Button danger onClick={handleCloseModal}>
{t('停止测试')}
</Button>
) : (
<Button type='tertiary' onClick={handleCloseModal}>
{t('取消')}
</Button>
<Button onClick={handleCloseModal}>{t('取消')}</Button>
)}
<Button
type='primary'
onClick={batchTestModels}
loading={isBatchTesting}
disabled={isBatchTesting}
disabled={isBatchTesting || selectedModelKeys.length === 0}
>
{isBatchTesting
? t('测试中...')
: t('批量测试${count}个模型').replace(
'${count}',
filteredModels.length,
)}
{isBatchTesting ? t('测试中...') : t('批量测试')}
</Button>
</div>
) : null
}
maskClosable={!isBatchTesting}
className='!rounded-lg'
size={isMobile ? 'full-width' : 'large'}
rootClassName='console-overlay model-test-modal'
width={isMobile ? 'calc(100vw - 32px)' : 514.8}
centered
styles={{ body: { maxHeight: 'none', overflow: 'visible' } }}
>
{hasChannel && (
<div className='model-test-scroll'>
<div className='model-test-content'>
{/* 端点类型选择器 */}
<div className='flex items-center gap-2 w-full mb-2'>
<Typography.Text strong>{t('端点类型')}:</Typography.Text>
<div className='model-test-endpoint'>
<Typography.Text strong id='model-test-endpoint-label'>
{t('端点类型')}:
</Typography.Text>
<Select
value={selectedEndpointType}
onChange={setSelectedEndpointType}
optionList={endpointTypeOptions}
className='!w-full'
options={endpointTypeOptions}
aria-labelledby='model-test-endpoint-label'
placeholder={t('选择端点类型')}
/>
</div>
{/* 搜索与操作按钮 */}
<div className='flex items-center justify-end gap-2 w-full mb-2'>
<div className='model-test-toolbar'>
<Input
placeholder={t('搜索模型...')}
value={modelSearchKeyword}
onChange={(v) => {
setModelSearchKeyword(v);
onChange={(event) => {
setModelSearchKeyword(event.target.value);
setModelTablePage(1);
}}
className='!w-full'
prefix={<IconSearch />}
showClear
prefix={<Search size={16} />}
allowClear
/>
<Button onClick={handleCopySelected}>{t('复制已选')}</Button>
<Button type='tertiary' onClick={handleSelectSuccess}>
{t('选择成功')}
</Button>
<Button onClick={handleSelectSuccess}>{t('选择成功')}</Button>
</div>
<div className='model-test-list-header'>
<Typography.Text strong>{t('模型列表')}</Typography.Text>
<Typography.Text type='secondary'>
{t('共 {{count}} 个模型', { count: models.length })}
</Typography.Text>
<Typography.Text type='secondary' aria-live='polite'>
{t('已选择 {{count}} 个模型', {
count: selectedModelKeys.length,
})}
</Typography.Text>
</div>
<Table
size='middle'
tableLayout='fixed'
className='model-test-table'
columns={columns}
scroll={{
x: 400,
y: `clamp(80px, calc(100dvh - ${isMobile ? 500 : 440}px), 400px)`,
}}
dataSource={dataSource}
rowSelection={{
selectedRowKeys: selectedModelKeys,
onChange: (keys) => {
if (allSelectingRef.current) {
allSelectingRef.current = false;
return;
}
setSelectedModelKeys(keys);
},
onSelectAll: (checked) => {
allSelectingRef.current = true;
setSelectedModelKeys(checked ? filteredModels : []);
},
preserveSelectedRowKeys: true,
columnWidth: 40,
onChange: (keys) => setSelectedModelKeys(keys),
}}
pagination={{
currentPage: modelTablePage,
pageSize: MODEL_TABLE_PAGE_SIZE,
current: modelTablePage,
pageSize: paginationSize,
total: filteredModels.length,
showSizeChanger: false,
onPageChange: (page) => setModelTablePage(page),
showTotal: (total) => t('共 {{total}} 条', { total }),
size: 'small',
onChange: (page, size) => {
setModelTablePage(size !== paginationSize ? 1 : page);
setPaginationSize(size);
},
}}
/>
</div>
@@ -0,0 +1,76 @@
.model-test-list-header {
display: flex;
align-items: baseline;
flex-wrap: wrap;
gap: 8px;
}
.model-test-content {
display: flex;
flex-direction: column;
gap: 16px;
padding-top: 8px;
}
.model-test-endpoint,
.model-test-toolbar,
.model-test-footer {
display: flex;
align-items: center;
gap: 8px;
}
.model-test-endpoint > .ant-typography {
flex-shrink: 0;
white-space: nowrap;
}
.model-test-endpoint > .ant-select,
.model-test-toolbar > .ant-input-affix-wrapper {
flex: 1;
min-width: 0;
}
.model-test-toolbar > .ant-btn {
flex-shrink: 0;
}
.model-test-status {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
.model-test-table .ant-table-cell {
overflow-wrap: anywhere;
}
.model-test-table .ant-table-selection-column {
vertical-align: middle;
}
.model-test-table .ant-btn-link {
padding-inline: 0;
}
.model-test-table .ant-table-pagination {
margin: 16px 0 0;
row-gap: 8px;
}
.model-test-footer {
justify-content: flex-end;
flex-wrap: wrap;
padding-top: 8px;
}
@media (max-width: 600px) {
.model-test-toolbar {
flex-wrap: wrap;
}
.model-test-toolbar > .ant-input-affix-wrapper {
flex-basis: 100%;
}
}
+1 -15
View File
@@ -21,18 +21,10 @@ import React from 'react';
import { Skeleton, Typography } from '@/components/ui';
import { useMinimumLoadingTime } from '../../../hooks/common/useMinimumLoadingTime';
import { IconEyeOpened } from '@/components/ui/icons';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
const { Text } = Typography;
const MjLogsActions = ({
loading,
showBanner,
isAdminUser,
compactMode,
setCompactMode,
t,
}) => {
const MjLogsActions = ({ loading, showBanner, isAdminUser, t }) => {
const showSkeleton = useMinimumLoadingTime(loading);
const placeholder = (
@@ -56,12 +48,6 @@ const MjLogsActions = ({
</Text>
</div>
</Skeleton>
<CompactModeToggle
compactMode={compactMode}
setCompactMode={setCompactMode}
t={t}
/>
</div>
);
};
+29 -47
View File
@@ -19,7 +19,9 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Button, Form } from '@/components/ui';
import { IconSearch } from '@/components/ui/icons';
import FilterSearchButton from '../../common/table/FilterSearchButton';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
import '../../common/table/log-filters.css';
import { DATE_RANGE_PRESETS } from '../../../constants/console.constants';
@@ -27,35 +29,37 @@ const MjLogsFilters = ({
formInitValues,
setFormApi,
refresh,
setShowColumnSelector,
formApi,
loading,
isAdminUser,
t,
}) => {
const { scheduleSearch, submitSearch, cancelPendingSearch } =
useFilterSearch(refresh);
return (
<Form
initValues={formInitValues}
getFormApi={(api) => setFormApi(api)}
onSubmit={refresh}
onSubmit={submitSearch}
onValueChange={scheduleSearch}
allowEmpty={true}
autoComplete='off'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='log-filter-form'
>
<div className='flex flex-col gap-2'>
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-2'>
<div className='log-filter-content'>
<div className='log-filter-grid'>
{/* 时间选择器 */}
<div className='col-span-1 lg:col-span-2'>
<div className='log-filter-wide'>
<Form.DatePicker
field='dateRange'
label={t('时间范围')}
className='w-full'
type='dateTimeRange'
placeholder={[t('开始时间'), t('结束时间')]}
showClear
pure
size='small'
presets={DATE_RANGE_PRESETS.map((preset) => ({
text: t(preset.text),
start: preset.start(),
@@ -67,60 +71,38 @@ const MjLogsFilters = ({
{/* 任务 ID */}
<Form.Input
field='mj_id'
prefix={<IconSearch />}
label={t('任务 ID')}
placeholder={t('任务 ID')}
showClear
pure
size='small'
/>
{/* 渠道 ID - 仅管理员可见 */}
{isAdminUser && (
<Form.Input
field='channel_id'
prefix={<IconSearch />}
label={t('渠道 ID')}
placeholder={t('渠道 ID')}
showClear
pure
size='small'
/>
)}
</div>
{/* 操作按钮区域 */}
<div className='flex justify-between items-center'>
<div></div>
<div className='flex gap-2'>
<Button
type='tertiary'
htmlType='submit'
loading={loading}
size='small'
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={() => {
if (formApi) {
formApi.reset();
setTimeout(() => {
refresh();
}, 100);
}
}}
size='small'
>
{t('重置')}
</Button>
<Button
type='tertiary'
onClick={() => setShowColumnSelector(true)}
size='small'
>
{t('列设置')}
</Button>
</div>
<div className='log-filter-actions'>
<Button
onClick={() => {
if (formApi) {
formApi.reset();
cancelPendingSearch();
setTimeout(() => {
refresh();
}, 100);
}
}}
>
{t('重置')}
</Button>
<FilterSearchButton loading={loading} />
</div>
</div>
</Form>
+5 -24
View File
@@ -17,13 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo } from 'react';
import { Empty } from '@/components/ui';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getMjLogsColumns } from './MjLogsColumnDefs';
const MjLogsTable = (mjLogsData) => {
@@ -33,7 +30,6 @@ const MjLogsTable = (mjLogsData) => {
activePage,
pageSize,
logCount,
compactMode,
visibleColumns,
handlePageChange,
handlePageSizeChange,
@@ -66,31 +62,16 @@ const MjLogsTable = (mjLogsData) => {
return getVisibleColumns();
}, [visibleColumns, allColumns]);
const tableColumns = useMemo(() => {
return compactMode
? visibleColumnsList.map(({ fixed, ...rest }) => rest)
: visibleColumnsList;
}, [compactMode, visibleColumnsList]);
return (
<CardTable
columns={tableColumns}
columns={visibleColumnsList}
dataSource={logs}
rowKey='key'
loading={loading}
scroll={compactMode ? undefined : { x: 'max-content' }}
scroll={{ x: 'max-content' }}
className='rounded-xl overflow-hidden'
size='middle'
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
empty={<TableEmpty />}
pagination={{
currentPage: activePage,
pageSize: pageSize,
+8
View File
@@ -20,6 +20,7 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Layout } from '@/components/ui';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import MjLogsTable from './MjLogsTable';
import MjLogsActions from './MjLogsActions';
import MjLogsFilters from './MjLogsFilters';
@@ -41,9 +42,16 @@ const MjLogsPage = () => {
<Layout>
<CardPro
tableTitle={mjLogsData.t('调用明细')}
type='type2'
statsArea={<MjLogsActions {...mjLogsData} />}
searchArea={<MjLogsFilters {...mjLogsData} />}
tableActions={
<ColumnSettingsButton
open={mjLogsData.showColumnSelector}
onClick={() => mjLogsData.setShowColumnSelector(true)}
/>
}
paginationArea={createCardProPagination({
currentPage: mjLogsData.activePage,
pageSize: mjLogsData.pageSize,
@@ -18,16 +18,15 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Checkbox } from '@/components/ui';
import { ColumnVisibilitySettings } from '../../../common/table/ColumnSettings';
import { getMjLogsColumns } from '../MjLogsColumnDefs';
const ColumnSelectorModal = ({
showColumnSelector,
setShowColumnSelector,
visibleColumns,
handleColumnVisibilityChange,
handleSelectAll,
initDefaultColumns,
setVisibleColumns,
getDefaultColumnVisibility,
COLUMN_KEYS,
isAdminUser,
copyText,
@@ -46,63 +45,22 @@ const ColumnSelectorModal = ({
});
return (
<Modal
title={t('列设置')}
visible={showColumnSelector}
onCancel={() => setShowColumnSelector(false)}
footer={
<div className='flex justify-end'>
<Button onClick={() => initDefaultColumns()}>{t('重置')}</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('取消')}
</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('确定')}
</Button>
</div>
}
>
<div style={{ marginBottom: 20 }}>
<Checkbox
checked={Object.values(visibleColumns).every((v) => v === true)}
indeterminate={
Object.values(visibleColumns).some((v) => v === true) &&
!Object.values(visibleColumns).every((v) => v === true)
}
onChange={(e) => handleSelectAll(e.target.checked)}
>
{t('全选')}
</Checkbox>
</div>
<div
className='flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4'
style={{ border: '1px solid var(--ui-color-border)' }}
>
{allColumns.map((column) => {
// Skip admin-only columns for non-admin users
if (
<ColumnVisibilitySettings
showColumnSelector={showColumnSelector}
setShowColumnSelector={setShowColumnSelector}
columns={allColumns.filter(
(column) =>
!(
!isAdminUser &&
(column.key === COLUMN_KEYS.CHANNEL ||
column.key === COLUMN_KEYS.SUBMIT_RESULT)
) {
return null;
}
return (
<div key={column.key} className='w-1/2 mb-4 pr-2'>
<Checkbox
checked={!!visibleColumns[column.key]}
onChange={(e) =>
handleColumnVisibilityChange(column.key, e.target.checked)
}
>
{column.title}
</Checkbox>
</div>
);
})}
</div>
</Modal>
[COLUMN_KEYS.CHANNEL, COLUMN_KEYS.SUBMIT_RESULT].includes(
column.key,
)
),
)}
visibleColumns={visibleColumns}
setVisibleColumns={setVisibleColumns}
getDefaultColumnVisibility={getDefaultColumnVisibility}
/>
);
};
@@ -18,17 +18,13 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import {
Button,
Space,
Tag,
Typography,
Modal,
Tooltip,
} from '@/components/ui';
import { Button as AntButton, Tooltip as AntTooltip } from 'antd';
import { Copy } from 'lucide-react';
import { Button, Space, Tag, Modal, Tooltip } from '@/components/ui';
import {
timestamp2string,
getLobeHubIcon,
renderGroup,
stringToColor,
isRoot,
} from '../../../helpers';
@@ -37,8 +33,6 @@ import {
renderDescription,
} from '../../common/ui/RenderUtils';
const { Text } = Typography;
// Render timestamp
function renderTimestamp(timestamp) {
return <>{timestamp2string(timestamp)}</>;
@@ -48,11 +42,7 @@ function renderTimestamp(timestamp) {
const renderModelIconCol = (record, vendorMap) => {
const iconKey = record?.icon || vendorMap[record?.vendor_id]?.icon;
if (!iconKey) return '-';
return (
<div className='flex items-center justify-center'>
{getLobeHubIcon(iconKey, 20)}
</div>
);
return <div className='models-model-icon'>{getLobeHubIcon(iconKey, 20)}</div>;
};
// Render vendor column with icon
@@ -125,9 +115,7 @@ const renderGroups = (groups) => {
return renderLimitedItems({
items: groups,
renderItem: (g, idx) => (
<Tag key={idx} size='small' shape='circle' color={stringToColor(g)}>
{g}
</Tag>
<React.Fragment key={idx}>{renderGroup(g)}</React.Fragment>
),
});
};
@@ -247,14 +235,19 @@ const renderOperations = (
manageModel,
refresh,
t,
setDetailModel,
) => {
return (
<Space wrap>
<Space wrap className='console-module-row-actions'>
<Button type='link' size='small' onClick={() => setDetailModel(record)}>
{t('详情')}
</Button>
{isRoot() && (
<>
{record.status === 1 ? (
<Button
type='danger'
type='link'
danger
size='small'
onClick={() => manageModel(record.id, 'disable', record)}
>
@@ -262,6 +255,7 @@ const renderOperations = (
</Button>
) : (
<Button
type='link'
size='small'
onClick={() => manageModel(record.id, 'enable', record)}
>
@@ -270,7 +264,7 @@ const renderOperations = (
)}
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setEditingModel(record);
@@ -281,7 +275,8 @@ const renderOperations = (
</Button>
<Button
type='danger'
type='link'
danger
size='small'
onClick={() => {
Modal.confirm({
@@ -347,8 +342,10 @@ export const getModelsColumns = ({
setEditingModel,
setShowEdit,
refresh,
copyText,
vendorMap,
categoryNames = {},
setDetailModel,
}) => {
return [
{
@@ -362,9 +359,19 @@ export const getModelsColumns = ({
title: t('模型名称'),
dataIndex: 'model_name',
render: (text) => (
<Text copyable onClick={(e) => e.stopPropagation()}>
{text}
</Text>
<span className='models-name-cell' onClick={(e) => e.stopPropagation()}>
<span>{text}</span>
<AntTooltip title={t('复制模型名称')}>
<AntButton
type='text'
size='small'
className='models-name-copy'
aria-label={t('复制模型名称')}
icon={<Copy size={14} />}
onClick={() => copyText(text)}
/>
</AntTooltip>
</span>
),
},
{
@@ -436,7 +443,7 @@ export const getModelsColumns = ({
},
},
{
title: '',
title: t('操作'),
dataIndex: 'operate',
fixed: 'right',
render: (text, record, index) =>
@@ -448,6 +455,7 @@ export const getModelsColumns = ({
manageModel,
refresh,
t,
setDetailModel,
),
},
];
+27 -33
View File
@@ -18,7 +18,9 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useRef } from 'react';
import { Form, Button } from '@/components/ui';
import { Form } from '@/components/ui';
import { ConsoleFilterActions } from '../../console/ConsoleModuleFilters';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
import { IconSearch } from '@/components/ui/icons';
import { MODEL_CATEGORY_NAMES } from '../../../constants';
@@ -30,12 +32,17 @@ const ModelsFilters = ({
searching,
t,
}) => {
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
() => searchModels(),
);
// Handle form reset and immediate search
const formApiRef = useRef(null);
const handleReset = () => {
if (!formApiRef.current) return;
formApiRef.current.reset();
cancelPendingSearch();
setTimeout(() => {
searchModels();
}, 100);
@@ -43,48 +50,52 @@ const ModelsFilters = ({
return (
<Form
initValues={formInitValues}
initValues={{
...formInitValues,
searchCategory: formInitValues.searchCategory || undefined,
}}
getFormApi={(api) => {
setFormApi(api);
formApiRef.current = api;
}}
onSubmit={searchModels}
onSubmit={submitSearch}
allowEmpty={true}
autoComplete='off'
layout='horizontal'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='w-full md:w-auto order-1 md:order-2'
className='console-module-filter-form'
onValueChange={scheduleSearch}
>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto'>
<div className='relative w-full md:w-56'>
<div className='console-module-filter-grid'>
<div className='console-module-field'>
<Form.Input
label={t('模型名称')}
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('搜索模型名称')}
showClear
pure
size='small'
/>
</div>
<div className='relative w-full md:w-56'>
<div className='console-module-field'>
<Form.Input
label={t('供应商')}
field='searchVendor'
prefix={<IconSearch />}
placeholder={t('搜索供应商')}
showClear
pure
size='small'
/>
</div>
<div className='relative w-full md:w-56'>
<div className='console-module-field'>
<Form.Select
label={t('分类')}
field='searchCategory'
placeholder={t('选择分类')}
showClear
pure
size='small'
style={{ width: '100%' }}
>
@@ -96,28 +107,11 @@ const ModelsFilters = ({
))}
</Form.Select>
</div>
<div className='flex gap-2 w-full md:w-auto'>
<Button
type='tertiary'
htmlType='submit'
loading={loading || searching}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={handleReset}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('重置')}
</Button>
</div>
</div>
<ConsoleFilterActions
onReset={handleReset}
loading={loading || searching}
/>
</Form>
);
};
+62 -34
View File
@@ -17,17 +17,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useMemo } from 'react';
import { Empty } from '@/components/ui';
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import { Descriptions } from 'antd';
import { Modal } from '@/components/ui';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getModelsColumns } from './ModelsColumnDefs';
import { useModelCategories } from '../../../hooks/models/useModelCategories';
import './models-vendor-tabs.css';
const ModelsTable = (modelsData) => {
const [detailModel, setDetailModel] = useState(null);
const {
models,
loading,
@@ -44,6 +45,7 @@ const ModelsTable = (modelsData) => {
setShowEdit,
refresh,
vendorMap,
copyText,
t,
} = modelsData;
@@ -60,6 +62,8 @@ const ModelsTable = (modelsData) => {
refresh,
vendorMap,
categoryNames,
setDetailModel,
copyText,
});
}, [
t,
@@ -69,6 +73,7 @@ const ModelsTable = (modelsData) => {
refresh,
vendorMap,
categoryNames,
copyText,
]);
// Handle compact mode by removing fixed positioning
@@ -85,36 +90,59 @@ const ModelsTable = (modelsData) => {
}, [compactMode, columns]);
return (
<CardTable
columns={tableColumns}
dataSource={models}
scroll={compactMode ? undefined : { x: 'max-content' }}
pagination={{
currentPage: activePage,
pageSize: pageSize,
total: modelCount,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50, 100],
onPageSizeChange: handlePageSizeChange,
onPageChange: handlePageChange,
}}
hidePagination={true}
loading={loading}
rowSelection={rowSelection}
onRow={handleRow}
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
<>
<Modal
title={t('详情')}
visible={Boolean(detailModel)}
onCancel={() => setDetailModel(null)}
maskClosable
footer={null}
width={720}
>
<Descriptions
className='models-detail-descriptions'
bordered
column={1}
items={
detailModel
? columns
.filter((column) => column.dataIndex !== 'operate')
.map((column, key) => ({
key,
label: column.title,
children: column.render
? column.render(
detailModel[column.dataIndex],
detailModel,
)
: (detailModel[column.dataIndex] ?? '-'),
}))
: []
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
className='rounded-xl overflow-hidden'
size='middle'
/>
</Modal>
<CardTable
columns={tableColumns}
dataSource={models}
scroll={compactMode ? undefined : { x: 'max-content' }}
pagination={{
currentPage: activePage,
pageSize: pageSize,
total: modelCount,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50, 100],
onPageSizeChange: handlePageSizeChange,
onPageChange: handlePageChange,
}}
hidePagination={true}
loading={loading}
rowSelection={rowSelection}
onRow={handleRow}
empty={<TableEmpty />}
className='rounded-xl overflow-hidden'
size='middle'
/>
</>
);
};
+92 -103
View File
@@ -18,8 +18,10 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Tabs, TabPane, Tag, Button, Dropdown, Modal } from '@/components/ui';
import { IconEdit, IconDelete } from '@/components/ui/icons';
import { Modal } from '@/components/ui';
import { Button } from 'antd';
import { Plus } from 'lucide-react';
import { IconEdit, IconClose } from '@/components/ui/icons';
import {
getLobeHubIcon,
showError,
@@ -27,6 +29,7 @@ import {
isRoot,
} from '../../../helpers';
import { API } from '../../../helpers';
import './models-vendor-tabs.css';
const ModelsTabs = ({
activeVendorKey,
@@ -52,13 +55,13 @@ const ModelsTabs = ({
};
const handleEditVendor = (vendor, e) => {
e.stopPropagation(); // 阻止事件冒泡,避免触发tab切换
e.stopPropagation();
setEditingVendor(vendor);
setShowEditVendor(true);
};
const handleDeleteVendor = async (vendor, e) => {
e.stopPropagation(); // 阻止事件冒泡,避免触发tab切换
e.stopPropagation();
try {
const res = await API.delete(`/api/vendors/${vendor.id}`);
if (res.data.success) {
@@ -80,109 +83,95 @@ const ModelsTabs = ({
};
return (
<Tabs
activeKey={activeVendorKey}
type='card'
collapsible
onChange={handleTabChange}
className='mb-2'
tabBarExtraContent={
canManageVendors && (
<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='primary'
size='small'
onClick={() => setShowAddVendor(true)}
type='text'
className='models-vendor-filter'
aria-pressed={activeVendorKey === 'all'}
onClick={() => handleTabChange('all')}
>
{t('新增供应商')}
<span>{t('全部')}</span>
<span className='models-vendor-count'>{vendorCounts.all || 0}</span>
</Button>
)
}
>
<TabPane
itemKey='all'
tab={
<span className='flex items-center gap-2'>
{t('全部')}
<Tag
color={activeVendorKey === 'all' ? 'red' : 'grey'}
shape='circle'
</div>
{vendors.map((vendor) => {
const key = String(vendor.id);
return (
<div
key={key}
className={`models-vendor-group${activeVendorKey === key ? ' is-selected' : ''}`}
>
{vendorCounts['all'] || 0}
</Tag>
</span>
}
/>
{vendors.map((vendor) => {
const key = String(vendor.id);
const count = vendorCounts[vendor.id] || 0;
return (
<TabPane
key={key}
itemKey={key}
tab={
<span className='flex items-center gap-2'>
{getLobeHubIcon(vendor.icon || 'Layers', 14)}
{vendor.name}
<Tag
color={activeVendorKey === key ? 'red' : 'grey'}
shape='circle'
>
{count}
</Tag>
{canManageVendors && (
<Dropdown
trigger='click'
position='bottomRight'
render={
<Dropdown.Menu>
<Dropdown.Item
icon={<IconEdit />}
onClick={(e) => handleEditVendor(vendor, e)}
>
{t('编辑')}
</Dropdown.Item>
<Dropdown.Item
type='danger'
icon={<IconDelete />}
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',
});
}}
>
{t('删除')}
</Dropdown.Item>
</Dropdown.Menu>
}
onClickOutSide={(e) => e.stopPropagation()}
>
<Button
size='small'
type='tertiary'
theme='outline'
onClick={(e) => e.stopPropagation()}
>
{t('操作')}
</Button>
</Dropdown>
)}
</span>
}
/>
);
})}
</Tabs>
<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={<Plus size={16} />}
onClick={() => setShowAddVendor(true)}
>
{t('新增供应商')}
</Button>
)}
</div>
);
};
+12 -11
View File
@@ -98,6 +98,18 @@ const ModelsPage = () => {
<ModelsCategoryStats t={t} />
<CardPro
tableTitle={t('模型列表')}
tableActionsOffset
searchArea={
<ModelsFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchModels={searchModels}
loading={loading}
searching={searching}
t={t}
/>
}
type='type3'
tabsArea={<ModelsTabs {...modelsData} />}
actionsArea={
@@ -118,17 +130,6 @@ const ModelsPage = () => {
setCompactMode={setCompactMode}
t={t}
/>
<div className='w-full md:w-full lg:w-auto order-1 md:order-2'>
<ModelsFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchModels={searchModels}
loading={loading}
searching={searching}
t={t}
/>
</div>
</div>
}
paginationArea={createCardProPagination({
@@ -17,7 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect, useRef, useMemo } from 'react';
import '../../../console/module-alignment.css';
import React, { useState, useEffect, useRef } from 'react';
import JSONEditor from '../../../common/ui/JSONEditor';
import {
SideSheet,
@@ -27,18 +28,17 @@ import {
Spin,
Typography,
Card,
Tag,
Avatar,
Col,
Row,
} from '@/components/ui';
import { Save, X, FileText } from 'lucide-react';
import { FileText } from 'lucide-react';
import { IconLink } from '@/components/ui/icons';
import { API, showError, showSuccess } from '../../../../helpers';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
const { Text, Title } = Typography;
const { Text } = Typography;
// Example endpoint template for quick fill
const ENDPOINT_TEMPLATE = {
@@ -63,7 +63,6 @@ const EditModelModal = (props) => {
const isMobile = useIsMobile();
const formApiRef = useRef(null);
const isEdit = props.editingModel && props.editingModel.id !== undefined;
const placement = useMemo(() => (isEdit ? 'right' : 'left'), [isEdit]);
// 供应商列表
const [vendors, setVendors] = useState([]);
@@ -308,51 +307,26 @@ const EditModelModal = (props) => {
return (
<SideSheet
placement={placement}
title={
<Space>
{isEdit ? (
<Tag color='blue' shape='circle'>
{t('更新')}
</Tag>
) : (
<Tag color='green' shape='circle'>
{t('新建')}
</Tag>
)}
<Title heading={4} className='m-0'>
{isEdit ? t('更新模型信息') : t('创建新的模型')}
</Title>
</Space>
}
rootClassName='console-model-drawer'
classNames={{ header: 'console-model-editor-header' }}
placement='right'
title={isEdit ? t('更新模型信息') : t('创建新的模型')}
bodyStyle={{ padding: '0' }}
visible={props.visiable}
width={isMobile ? '100%' : 600}
footer={
<div className='flex justify-end'>
<Space>
<Button
theme='solid'
className='!rounded-lg'
onClick={() => formApiRef.current?.submitForm()}
icon={<Save size={16} />}
loading={loading}
>
{t('提交')}
</Button>
<Button
theme='light'
className='!rounded-lg'
type='primary'
onClick={handleCancel}
icon={<X size={16} />}
>
{t('取消')}
</Button>
</Space>
<div className='console-model-footer'>
<Button onClick={handleCancel}>{t('取消')}</Button>
<Button
theme='solid'
type='primary'
onClick={() => formApiRef.current?.submitForm()}
loading={loading}
>
{t('确定')}
</Button>
</div>
}
closeIcon={null}
onCancel={() => handleCancel()}
>
<Spin spinning={loading}>
@@ -366,8 +340,8 @@ const EditModelModal = (props) => {
<div className='p-2'>
{/* 基本信息 */}
<Card className='!rounded-2xl shadow-sm border-0'>
<div className='flex items-center mb-2'>
<Avatar size='small' color='green' className='mr-2 shadow-md'>
<div className='console-model-section'>
<Avatar size='small' color='green'>
<FileText size={16} />
</Avatar>
<div>
@@ -470,7 +444,7 @@ const EditModelModal = (props) => {
style={{ width: '100%' }}
{...(tagGroups.length > 0 && {
extraText: (
<Space wrap>
<Space wrap className='console-model-tag-presets'>
{tagGroups.map((group) => (
<Button
key={group.id}
@@ -602,7 +576,7 @@ const EditModelModal = (props) => {
)}
/>
</Col>
<Col span={24}>
<Col span={24} className='console-model-endpoints'>
<JSONEditor
field='endpoints'
label={t('端点映射')}
@@ -615,6 +589,7 @@ const EditModelModal = (props) => {
}
formApi={formApiRef.current}
editorType='object'
objectValueAutoSize={{ minRows: 3, maxRows: 8 }}
template={ENDPOINT_TEMPLATE}
templateLabel={t('填入模板')}
extraText={t('留空则使用默认端点;支持 {path, method}')}
@@ -17,28 +17,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import '../../../console/module-alignment.css';
import React, { useState, useRef, useEffect } from 'react';
import JSONEditor from '../../../common/ui/JSONEditor';
import {
SideSheet,
Button,
Form,
Typography,
Space,
Tag,
Row,
Col,
Card,
Avatar,
Spin,
} from '@/components/ui';
import { IconLayers, IconSave, IconClose } from '@/components/ui/icons';
import { Modal, Form, Row, Col, Spin } from '@/components/ui';
import { API, showError, showSuccess } from '../../../../helpers';
import { useTranslation } from 'react-i18next';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
const { Text, Title } = Typography;
// Example endpoint template for quick fill
const ENDPOINT_TEMPLATE = {
openai: { path: '/v1/chat/completions', method: 'POST' },
@@ -112,53 +98,13 @@ const EditPrefillGroupModal = ({
};
return (
<SideSheet
placement='left'
title={
<Space>
{isEdit ? (
<Tag color='blue' shape='circle'>
{t('更新')}
</Tag>
) : (
<Tag color='green' shape='circle'>
{t('新建')}
</Tag>
)}
<Title heading={4} className='m-0'>
{isEdit ? t('更新预填组') : t('创建新的预填组')}
</Title>
</Space>
}
<Modal
title={isEdit ? t('更新预填组') : t('创建新的预填组')}
visible={visible}
onCancel={onClose}
width={isMobile ? '100%' : 600}
bodyStyle={{ padding: '0' }}
footer={
<div className='flex justify-end'>
<Space>
<Button
theme='solid'
className='!rounded-lg'
onClick={() => formRef.current?.submitForm()}
icon={<IconSave />}
loading={loading}
>
{t('提交')}
</Button>
<Button
theme='light'
className='!rounded-lg'
type='primary'
onClick={onClose}
icon={<IconClose />}
>
{t('取消')}
</Button>
</Space>
</div>
}
closeIcon={null}
onOk={() => formRef.current?.submitForm()}
confirmLoading={loading}
size={isMobile ? 'full-width' : 'small'}
>
<Spin spinning={loading}>
<Form
@@ -185,89 +131,71 @@ const EditPrefillGroupModal = ({
}}
onSubmit={handleSubmit}
>
<div className='p-2'>
{/* 基本信息 */}
<Card className='!rounded-2xl shadow-sm border-0'>
<div className='flex items-center mb-2'>
<Avatar size='small' color='green' className='mr-2 shadow-md'>
<IconLayers size={16} />
</Avatar>
<div>
<Text className='text-lg font-medium'>{t('基本信息')}</Text>
<div className='text-xs text-gray-600'>
{t('设置预填组的基本信息')}
</div>
</div>
</div>
<Row gutter={12}>
<Col span={24}>
<Form.Input
field='name'
label={t('组名')}
placeholder={t('请输入组名')}
rules={[{ required: true, message: t('请输入组名') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Select
field='type'
label={t('类型')}
placeholder={t('选择组类型')}
optionList={typeOptions}
rules={[{ required: true, message: t('请选择组类型') }]}
style={{ width: '100%' }}
onChange={(val) => setSelectedType(val)}
/>
</Col>
<Col span={24}>
<Form.TextArea
field='description'
label={t('描述')}
placeholder={t('请输入组描述')}
rows={3}
showClear
/>
</Col>
<Col span={24}>
{selectedType === 'endpoint' ? (
<JSONEditor
field='items'
label={t('端点映射')}
value={
formRef.current?.getValue('items') ??
(typeof editingGroup?.items === 'string'
? editingGroup.items
: JSON.stringify(editingGroup.items || {}, null, 2))
}
onChange={(val) =>
formRef.current?.setValue('items', val)
}
editorType='object'
placeholder={
'{\n "openai": {"path": "/v1/chat/completions", "method": "POST"}\n}'
}
template={ENDPOINT_TEMPLATE}
templateLabel={t('填入模板')}
extraText={t('键为端点类型,值为路径和方法对象')}
/>
) : (
<Form.TagInput
field='items'
label={t('项目')}
placeholder={t('输入项目名称,按回车添加')}
addOnBlur
showClear
style={{ width: '100%' }}
/>
)}
</Col>
</Row>
</Card>
</div>
<Row gutter={12}>
<Col span={24}>
<Form.Input
field='name'
label={t('组名')}
placeholder={t('请输入组名')}
rules={[{ required: true, message: t('请输入组名') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Select
field='type'
label={t('类型')}
placeholder={t('选择组类型')}
optionList={typeOptions}
rules={[{ required: true, message: t('请选择组类型') }]}
style={{ width: '100%' }}
onChange={(val) => setSelectedType(val)}
/>
</Col>
<Col span={24}>
<Form.TextArea
field='description'
label={t('描述')}
placeholder={t('请输入组描述')}
rows={3}
showClear
/>
</Col>
<Col span={24}>
{selectedType === 'endpoint' ? (
<JSONEditor
field='items'
label={t('端点映射')}
value={
formRef.current?.getValue('items') ??
(typeof editingGroup?.items === 'string'
? editingGroup.items
: JSON.stringify(editingGroup.items || {}, null, 2))
}
onChange={(val) => formRef.current?.setValue('items', val)}
editorType='object'
placeholder={
'{\n "openai": {"path": "/v1/chat/completions", "method": "POST"}\n}'
}
template={ENDPOINT_TEMPLATE}
templateLabel={t('填入模板')}
extraText={t('键为端点类型,值为路径和方法对象')}
/>
) : (
<Form.TagInput
field='items'
label={t('项目')}
placeholder={t('输入项目名称,按回车添加')}
addOnBlur
showClear
style={{ width: '100%' }}
/>
)}
</Col>
</Row>
</Form>
</Spin>
</SideSheet>
</Modal>
);
};
@@ -37,6 +37,7 @@ import { MODEL_TABLE_PAGE_SIZE } from '../../../../constants';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
const [paginationSize, setPaginationSize] = useState(MODEL_TABLE_PAGE_SIZE);
const [loading, setLoading] = useState(false);
const [missingModels, setMissingModels] = useState([]);
const [searchKeyword, setSearchKeyword] = useState('');
@@ -74,8 +75,8 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
);
const dataSource = (() => {
const start = (currentPage - 1) * MODEL_TABLE_PAGE_SIZE;
const end = start + MODEL_TABLE_PAGE_SIZE;
const start = (currentPage - 1) * paginationSize;
const end = start + paginationSize;
return filteredModels.slice(start, end).map((model) => ({
model,
key: model,
@@ -169,10 +170,14 @@ const MissingModelsModal = ({ visible, onClose, onConfigureModel, t }) => {
dataSource={dataSource}
pagination={{
currentPage: currentPage,
pageSize: MODEL_TABLE_PAGE_SIZE,
pageSize: paginationSize,
total: filteredModels.length,
showSizeChanger: false,
onPageChange: (page) => setCurrentPage(page),
onPageSizeChange: (size) => {
setCurrentPage(1);
setPaginationSize(size);
},
}}
/>
) : (
@@ -17,7 +17,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect } from 'react';
import '../../../console/module-alignment.css';
import React, { useState, useEffect, useCallback } from 'react';
import {
SideSheet,
Button,
@@ -50,7 +51,7 @@ import {
renderDescription,
} from '../../../common/ui/RenderUtils';
const { Text, Title } = Typography;
const { Text } = Typography;
const PrefillGroupManagement = ({ visible, onClose }) => {
const { t } = useTranslation();
@@ -67,7 +68,7 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
];
// 加载组列表
const loadGroups = async () => {
const loadGroups = useCallback(async () => {
setLoading(true);
try {
const res = await API.get('/api/prefill_group');
@@ -80,7 +81,7 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
showError(t('获取组列表失败'));
}
setLoading(false);
};
}, [t]);
// 删除组
const deleteGroup = async (id) => {
@@ -193,20 +194,20 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
},
},
{
title: '',
title: t('操作'),
key: 'action',
fixed: 'right',
width: 140,
render: (_, record) => (
<Space>
<Button size='small' onClick={() => handleEdit(record)}>
<Space className='console-module-row-actions'>
<Button type='link' size='small' onClick={() => handleEdit(record)}>
{t('编辑')}
</Button>
<Popconfirm
title={t('确定删除此组?')}
onConfirm={() => deleteGroup(record.id)}
>
<Button size='small' type='danger'>
<Button size='small' type='link' danger>
{t('删除')}
</Button>
</Popconfirm>
@@ -219,33 +220,25 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
if (visible) {
loadGroups();
}
}, [visible]);
}, [visible, loadGroups]);
return (
<>
<SideSheet
placement='left'
title={
<Space>
<Tag color='blue' shape='circle'>
{t('管理')}
</Tag>
<Title heading={4} className='m-0'>
{t('预填组管理')}
</Title>
</Space>
}
rootClassName='console-model-drawer'
placement='right'
title={t('预填组管理')}
classNames={{ header: 'prefill-management-header' }}
visible={visible}
onCancel={onClose}
width={isMobile ? '100%' : 800}
bodyStyle={{ padding: '0' }}
closeIcon={null}
>
<Spin spinning={loading}>
<div className='p-2'>
<Card className='!rounded-2xl shadow-sm border-0'>
<div className='flex items-center mb-2'>
<Avatar size='small' color='blue' className='mr-2 shadow-md'>
<div className='console-model-section'>
<Avatar size='small' color='blue'>
<IconLayers size={16} />
</Avatar>
<div>
@@ -257,6 +250,7 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
</div>
<div className='flex justify-end mb-4'>
<Button
className='console-create-action'
type='primary'
theme='solid'
size='small'
@@ -41,7 +41,7 @@ const SyncWizardModal = ({ visible, onClose, onConfirm, loading, t }) => {
visible={visible}
onCancel={onClose}
footer={
<div className='flex justify-end'>
<div className='console-model-footer'>
{step === 1 && (
<Button onClick={() => setStep(0)}>{t('上一步')}</Button>
)}
@@ -49,6 +49,7 @@ const SyncWizardModal = ({ visible, onClose, onConfirm, loading, t }) => {
{step === 0 && (
<Button
type='primary'
theme='solid'
onClick={() => setStep(1)}
disabled={option !== 'official'}
>
@@ -69,7 +70,7 @@ const SyncWizardModal = ({ visible, onClose, onConfirm, loading, t }) => {
)}
</div>
}
width={isMobile ? '100%' : 'small'}
width={isMobile ? '100%' : '65%'}
>
<div className='mb-3'>
<Steps type='basic' current={step} size='small'>
@@ -54,6 +54,7 @@ const UpstreamConflictModal = ({
t,
loading = false,
}) => {
const [paginationSize, setPaginationSize] = useState(MODEL_TABLE_PAGE_SIZE);
const [selections, setSelections] = useState({});
const isMobile = useIsMobile();
const [currentPage, setCurrentPage] = useState(1);
@@ -247,10 +248,10 @@ const UpstreamConflictModal = ({
]);
const pagedDataSource = useMemo(() => {
const start = (currentPage - 1) * MODEL_TABLE_PAGE_SIZE;
const end = start + MODEL_TABLE_PAGE_SIZE;
const start = (currentPage - 1) * paginationSize;
const end = start + paginationSize;
return filteredDataSource.slice(start, end);
}, [filteredDataSource, currentPage]);
}, [filteredDataSource, currentPage, paginationSize]);
const handleOk = async () => {
const payload = Object.entries(selections)
@@ -302,10 +303,14 @@ const UpstreamConflictModal = ({
dataSource={pagedDataSource}
pagination={{
currentPage: currentPage,
pageSize: MODEL_TABLE_PAGE_SIZE,
pageSize: paginationSize,
total: filteredDataSource.length,
showSizeChanger: false,
onPageChange: (page) => setCurrentPage(page),
onPageSizeChange: (size) => {
setCurrentPage(1);
setPaginationSize(size);
},
}}
scroll={{ x: 'max-content' }}
/>
@@ -0,0 +1,124 @@
.models-vendor-toolbar {
display: flex;
align-items: flex-start;
flex-wrap: wrap;
gap: 8px 16px;
}
.models-vendor-list {
display: flex;
align-items: center;
flex-wrap: wrap;
flex: 1;
min-width: 0;
gap: 8px;
}
.models-vendor-group {
display: flex;
align-items: center;
max-width: 100%;
min-height: 34px;
padding-inline: 2px;
border: 1px solid var(--ui-color-border);
border-radius: var(--ui-border-radius-small);
background: var(--ui-color-fill-0);
}
.models-vendor-group.is-selected {
border-color: var(--ui-color-primary-light-active);
background: var(--ui-color-primary-light-default);
}
.models-vendor-group .models-vendor-filter {
display: inline-flex;
align-items: center;
min-width: 0;
gap: 8px;
border: 0;
background: transparent;
box-shadow: none;
}
.models-vendor-icon {
display: inline-flex;
align-items: center;
flex-shrink: 0;
width: 14px;
height: 14px;
justify-content: center;
}
.models-vendor-name {
overflow: hidden;
max-width: 200px;
text-overflow: ellipsis;
white-space: nowrap;
}
.models-model-icon {
display: flex;
align-items: center;
justify-content: center;
}
.models-detail-descriptions .models-model-icon {
justify-content: flex-start;
}
.models-name-cell {
display: inline-flex;
align-items: center;
gap: 4px;
}
.models-name-copy.ant-btn {
display: inline-flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
width: 24px;
min-width: 24px;
height: 24px;
padding: 0;
font-size: inherit;
color: var(--ui-color-primary);
}
.models-name-cell .models-name-copy.ant-btn .lucide {
width: 0.8em;
height: 0.8em;
}
.models-vendor-count {
flex-shrink: 0;
font-size: 12px;
opacity: 0.65;
}
/* Sticky headers need an opaque surface below the translucent header tint. */
.console-page[data-console-page='models']
.console-table
.ant-table-thead
> tr
> th.ant-table-cell-fix-right {
background-color: var(--console-surface);
background-image: linear-gradient(var(--console-fill), var(--console-fill));
}
.models-vendor-actions {
display: flex;
flex-shrink: 0;
visibility: hidden;
}
.models-vendor-group:hover .models-vendor-actions,
.models-vendor-group:focus-within .models-vendor-actions {
visibility: visible;
}
@media (hover: none) {
.models-vendor-actions {
visibility: visible;
}
}
@@ -21,10 +21,20 @@ import React from 'react';
import { Typography } from '@/components/ui';
import { Ticket } from 'lucide-react';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
import { useConsolePage } from '../../console/ConsoleContext';
const { Text } = Typography;
const RedemptionsDescription = ({ compactMode, setCompactMode, t }) => {
const consolePage = useConsolePage();
if (consolePage)
return (
<CompactModeToggle
compactMode={compactMode}
setCompactMode={setCompactMode}
t={t}
/>
);
return (
<div className='flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full'>
<div className='flex items-center text-orange-500'>
@@ -18,7 +18,8 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useRef } from 'react';
import { Form, Button } from '@/components/ui';
import { Form } from '@/components/ui';
import { ConsoleSearchActions } from '../../console/ConsolePrimitives';
import { IconSearch } from '@/components/ui/icons';
const RedemptionsFilters = ({
@@ -53,10 +54,10 @@ const RedemptionsFilters = ({
layout='horizontal'
trigger='change'
stopValidateWithError={false}
className='w-full md:w-auto order-1 md:order-2'
className='w-full'
>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto'>
<div className='relative w-full md:w-64'>
<div className='console-search-fields'>
<div className='console-search-field'>
<Form.Input
field='searchKeyword'
prefix={<IconSearch />}
@@ -66,25 +67,11 @@ const RedemptionsFilters = ({
size='small'
/>
</div>
<div className='flex gap-2 w-full md:w-auto'>
<Button
type='tertiary'
htmlType='submit'
loading={loading || searching}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={handleReset}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('重置')}
</Button>
</div>
<ConsoleSearchActions
onReset={handleReset}
loading={loading || searching}
searchLabel='查询'
/>
</div>
</Form>
);
+10 -11
View File
@@ -71,6 +71,16 @@ const RedemptionsPage = () => {
/>
<CardPro
searchArea={
<RedemptionsFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchRedemptions={searchRedemptions}
loading={loading}
searching={searching}
t={t}
/>
}
type='type1'
descriptionArea={
<RedemptionsDescription
@@ -89,17 +99,6 @@ const RedemptionsPage = () => {
batchDeleteRedemptions={batchDeleteRedemptions}
t={t}
/>
<div className='w-full md:w-full lg:w-auto order-1 md:order-2'>
<RedemptionsFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchRedemptions={searchRedemptions}
loading={loading}
searching={searching}
t={t}
/>
</div>
</div>
}
paginationArea={createCardProPagination({
@@ -28,6 +28,8 @@ import {
Loader2,
} from 'lucide-react';
import { exportToCsv, formatTimestampForCsv } from '../../../helpers/exportCsv';
import { Space, Statistic } from 'antd';
import { useConsolePage } from '../../console/ConsoleContext';
// CSV 导出:仅当前页已加载的数据,避免一次性拉取全量产生巨大请求
export const exportTaskLogsPageCsv = (logs, isAdminUser, t) => {
@@ -98,6 +100,7 @@ const TaskLogsActions = ({
isAdminUser,
usageRecordMode = false,
}) => {
const consolePage = useConsolePage();
const exportButtonClass =
'hover:!bg-gray-100 dark:hover:!bg-neutral-800 !transition-all !duration-300';
@@ -106,6 +109,28 @@ const TaskLogsActions = ({
const handleExportCsv = () => exportTaskLogsPageCsv(logs, isAdminUser, t);
if (consolePage) {
return (
<div className='console-task-stats'>
<Space wrap size={24}>
<Statistic title={t('本页成功')} value={stats.successCount} />
<Statistic title={t('本页失败')} value={stats.failureCount} />
<Statistic title={t('本页进行中')} value={stats.pendingCount} />
</Space>
<Space wrap>
{stats.pendingCount > 0 && <span>{t('实时更新中')}</span>}
<Button
icon={<Download size={16} />}
onClick={handleExportCsv}
disabled={!logs.length}
>
{t('导出本页')}
</Button>
</Space>
</div>
);
}
const StatBadge = ({ icon: Icon, label, value, gradient, iconBg }) => (
<div className='relative group'>
<div
@@ -25,13 +25,15 @@ import {
Radio,
RotateCcw,
Search,
Settings2,
Filter,
Activity,
Layers,
} from 'lucide-react';
import { DATE_RANGE_PRESETS } from '../../../constants/console.constants';
import { useConsolePage } from '../../console/ConsoleContext';
import FilterSearchButton from '../../common/table/FilterSearchButton';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
import {
TASK_ACTION_FIRST_TAIL_GENERATE,
TASK_ACTION_GENERATE,
@@ -45,7 +47,6 @@ const TaskLogsFilters = ({
formInitValues,
setFormApi,
refresh,
setShowColumnSelector,
formApi,
loading,
isAdminUser,
@@ -54,9 +55,11 @@ const TaskLogsFilters = ({
hideDateRange = false,
t,
}) => {
const consolePage = useConsolePage();
const { scheduleSearch, submitSearch, cancelPendingSearch } =
useFilterSearch(refresh);
const SearchIcon = Search;
const ResetIcon = RotateCcw;
const ColumnsIcon = Settings2;
const primaryButtonClass =
'!bg-gradient-to-r !from-cyan-500 !to-blue-600 !border-0 hover:!from-cyan-600 hover:!to-blue-700 !shadow-md hover:!shadow-lg !transition-all !duration-300';
const softButtonClass =
@@ -77,6 +80,7 @@ const TaskLogsFilters = ({
? getFreshInitValues()
: formInitValues;
formApi.setValues(fresh, { isOverride: true });
cancelPendingSearch();
setTimeout(() => {
refresh();
}, 100);
@@ -165,12 +169,13 @@ const TaskLogsFilters = ({
);
// 个人端使用记录:原型为带字段标签的五列筛选卡,重置/搜索位于右下;列设置移至表格卡片标题栏
if (usageRecordMode) {
if (usageRecordMode || consolePage) {
return (
<Form
initValues={formInitValues}
getFormApi={(api) => setFormApi(api)}
onSubmit={refresh}
onSubmit={consolePage ? submitSearch : refresh}
onValueChange={consolePage ? scheduleSearch : undefined}
allowEmpty={true}
autoComplete='off'
layout='vertical'
@@ -232,14 +237,18 @@ const TaskLogsFilters = ({
</div>
<div className='usage-record-filter-actions'>
<Button onClick={resetFilters}>{t('重置')}</Button>
<Button
type='primary'
htmlType='submit'
loading={loading}
icon={<Search size={14} />}
>
{t('搜索')}
</Button>
{consolePage ? (
<FilterSearchButton loading={loading} />
) : (
<Button
type='primary'
htmlType='submit'
loading={loading}
icon={<Search size={14} />}
>
{t('搜索')}
</Button>
)}
</div>
</Form>
);
@@ -412,17 +421,6 @@ const TaskLogsFilters = ({
>
{t('重置')}
</Button>
{/* 列设置按钮 */}
<Button
type='tertiary'
onClick={() => setShowColumnSelector(true)}
size='small'
icon={<ColumnsIcon className='w-3.5 h-3.5' />}
className={softButtonClass}
>
{t('列设置')}
</Button>
</div>
</div>
</div>
@@ -17,14 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo } from 'react';
import { Empty as AntEmpty } from 'antd';
import { Empty } from '@/components/ui';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getTaskLogsColumns } from './TaskLogsColumnDefs';
const TaskLogsTable = (taskLogsData) => {
@@ -99,42 +95,7 @@ const TaskLogsTable = (taskLogsData) => {
: 'rounded-xl overflow-hidden task-logs-table'
}
size='middle'
empty={
usageRecordMode ? (
<AntEmpty
image={AntEmpty.PRESENTED_IMAGE_SIMPLE}
description={
<>
<div>{t('搜索无结果')}</div>
<div className='usage-record-empty-hint'>
{t('暂无任务记录')}
</div>
</>
}
/>
) : (
<div className='py-12'>
<Empty
image={
<IllustrationNoResult style={{ width: 180, height: 180 }} />
}
darkModeImage={
<IllustrationNoResultDark style={{ width: 180, height: 180 }} />
}
description={
<div className='flex flex-col items-center gap-2'>
<span className='text-gray-500 dark:text-gray-400 text-sm'>
{t('搜索无结果')}
</span>
<span className='text-gray-400 dark:text-gray-500 text-xs'>
{t('暂无任务记录')}
</span>
</div>
}
/>
</div>
)
}
empty={<TableEmpty />}
pagination={{
currentPage: activePage,
pageSize: pageSize,
+20 -33
View File
@@ -19,9 +19,10 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useState } from 'react';
import { Card, Tag as AntTag } from 'antd';
import { Clock, Download, Settings } from 'lucide-react';
import { Button, Pagination, Tooltip } from '@/components/ui';
import { Clock, Download } from 'lucide-react';
import { Button, Pagination } from '@/components/ui';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import TaskLogsTable from './TaskLogsTable';
import TaskLogsActions, {
exportTaskLogsPageCsv,
@@ -56,7 +57,7 @@ const TaskLogsPage = ({
const { t, logs, isAdminUser } = taskLogsData;
return (
<>
<ColumnSelectorModal {...taskLogsData} />
<ColumnSelectorModal {...taskLogsData} usageRecordMode />
<ContentModal {...taskLogsData} isVideo={false} />
{/* 视频预览弹窗 */}
<ContentModal
@@ -107,14 +108,10 @@ const TaskLogsPage = ({
>
{t('导出本页')}
</Button>
<Tooltip content={t('列设置')}>
<Button
theme='borderless'
aria-label={t('列设置')}
icon={<Settings size={16} />}
onClick={() => taskLogsData.setShowColumnSelector(true)}
/>
</Tooltip>
<ColumnSettingsButton
open={taskLogsData.showColumnSelector}
onClick={() => taskLogsData.setShowColumnSelector(true)}
/>
</div>
</div>
<TaskLogsTable
@@ -148,16 +145,6 @@ const TaskLogsPage = ({
return (
<div className='relative'>
{/* 装饰性网格背景 */}
<div
className='absolute inset-0 opacity-[0.015] dark:opacity-[0.03] pointer-events-none'
style={{
backgroundImage: `
linear-gradient(rgba(6, 182, 212, 0.5) 1px, transparent 1px),
linear-gradient(90deg, rgba(6, 182, 212, 0.5) 1px, transparent 1px)
`,
backgroundSize: '24px 24px',
}}
/>
{/* Modals */}
<ColumnSelectorModal {...taskLogsData} />
@@ -173,6 +160,7 @@ const TaskLogsPage = ({
{/* Main Content */}
<CardPro
tableTitle={taskLogsData.t('任务明细')}
type='type2'
className='!bg-transparent !border-0 !shadow-none relative'
statsArea={
@@ -184,7 +172,14 @@ const TaskLogsPage = ({
hideDateRange={taskLogsData.usesSharedDateRange}
/>
}
tableActions={
<ColumnSettingsButton
open={taskLogsData.showColumnSelector}
onClick={() => taskLogsData.setShowColumnSelector(true)}
/>
}
paginationArea={createCardProPagination({
showRange: false,
currentPage: taskLogsData.activePage,
pageSize: taskLogsData.pageSize,
total: taskLogsData.logCount,
@@ -196,18 +191,10 @@ const TaskLogsPage = ({
t={taskLogsData.t}
>
{/* 表格容器 */}
<div className='relative mt-4'>
{/* 表格装饰光晕 —— 走冷色 cyan→blue→品牌,与任务日志图标族一致 */}
<div className='absolute -inset-0.5 bg-gradient-to-r from-cyan-500/20 via-blue-500/20 to-brand-to/20 rounded-2xl opacity-50 blur-sm' />
{/* 表格内容 —— 统一 .app-card 玻璃卡(去掉散乱的 bg-white/80 + border + rounded) */}
<div className='relative app-card overflow-hidden'>
<TaskLogsTable
{...taskLogsData}
compactMode={taskLogsData.compactMode}
/>
</div>
</div>
<TaskLogsTable
{...taskLogsData}
compactMode={taskLogsData.compactMode}
/>
</CardPro>
</div>
);
@@ -18,21 +18,22 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Checkbox } from '@/components/ui';
import { ColumnVisibilitySettings } from '../../../common/table/ColumnSettings';
import { getTaskLogsColumns } from '../TaskLogsColumnDefs';
const ColumnSelectorModal = ({
showColumnSelector,
setShowColumnSelector,
visibleColumns,
handleColumnVisibilityChange,
handleSelectAll,
initDefaultColumns,
setVisibleColumns,
getDefaultColumnVisibility,
COLUMN_KEYS,
isAdminUser,
isRootUser,
copyText,
openContentModal,
usageRecordMode = false,
columns: configuredColumns,
t,
}) => {
// Get all columns for display in selector
@@ -43,69 +44,20 @@ const ColumnSelectorModal = ({
openContentModal,
isAdminUser,
isRootUser,
usageRecordMode,
});
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
// 否则非管理员下 CHANNEL 永远为 false,导致 every 永远为 false、全选框永远半选
const isHiddenForRole = (key) => !isAdminUser && key === COLUMN_KEYS.CHANNEL;
const effectiveValues = Object.entries(visibleColumns)
.filter(([key]) => !isHiddenForRole(key))
.map(([, v]) => v);
const allChecked =
effectiveValues.length > 0 && effectiveValues.every((v) => v === true);
const someChecked = effectiveValues.some((v) => v === true);
return (
<Modal
title={t('列设置')}
visible={showColumnSelector}
onCancel={() => setShowColumnSelector(false)}
footer={
<div className='flex justify-end gap-2'>
<Button onClick={() => initDefaultColumns()}>{t('重置')}</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('取消')}
</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('确定')}
</Button>
</div>
}
>
<div style={{ marginBottom: 20 }}>
<Checkbox
checked={allChecked}
indeterminate={someChecked && !allChecked}
onChange={(e) => handleSelectAll(e.target.checked)}
>
{t('全选')}
</Checkbox>
</div>
<div
className='flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4'
style={{ border: '1px solid var(--ui-color-border)' }}
>
{allColumns.map((column) => {
// Skip admin-only columns for non-admin users
if (!isAdminUser && column.key === COLUMN_KEYS.CHANNEL) {
return null;
}
return (
<div key={column.key} className='w-1/2 mb-4 pr-2'>
<Checkbox
checked={!!visibleColumns[column.key]}
onChange={(e) =>
handleColumnVisibilityChange(column.key, e.target.checked)
}
>
{column.title}
</Checkbox>
</div>
);
})}
</div>
</Modal>
<ColumnVisibilitySettings
showColumnSelector={showColumnSelector}
setShowColumnSelector={setShowColumnSelector}
columns={(configuredColumns || allColumns).filter(
(column) => isAdminUser || column.key !== COLUMN_KEYS.CHANNEL,
)}
visibleColumns={visibleColumns}
setVisibleColumns={setVisibleColumns}
getDefaultColumnVisibility={getDefaultColumnVisibility}
/>
);
};
@@ -17,10 +17,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect } from 'react';
import { writeClipboardText } from '../../../../helpers/clipboard';
import React, { useState, useEffect, useRef } from 'react';
import { Empty, theme } from 'antd';
import { Modal, Button, Typography, Spin } from '@/components/ui';
import { IconExternalOpen, IconCopy } from '@/components/ui/icons';
import { useTranslation } from 'react-i18next';
import { showError, showSuccess } from '../../../../helpers';
import './content-modal.css';
const { Text } = Typography;
@@ -33,18 +37,31 @@ const ContentModal = ({
isVideo,
}) => {
const { t } = useTranslation();
const { token } = theme.useToken();
const [videoError, setVideoError] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const videoRef = useRef(null);
// 复制/打开操作都用上游原始 URL,代理路径可能带鉴权或外部无法访问
const shareUrl = sourceUrl || modalContent;
useEffect(() => {
if (isModalOpen && isVideo) {
if (!isVideo) return;
const video = videoRef.current;
if (isModalOpen) {
setVideoError(false);
setIsLoading(true);
// 弹窗关闭只隐藏、不卸载内容:重新打开同一视频时 <video> 不会再次触发加载事件,
// 已有可播放数据则不再显示加载指示,避免指示常驻
const loaded =
video &&
video.readyState >= 2 &&
video.getAttribute('src') === modalContent;
setIsLoading(!loaded);
} else if (video && !video.paused) {
// 关闭时暂停播放,避免隐藏后仍在后台出声(不改变弹窗的卸载语义)
video.pause();
}
}, [isModalOpen, isVideo]);
}, [isModalOpen, isVideo, modalContent]);
const handleVideoError = () => {
setVideoError(true);
@@ -56,144 +73,129 @@ const ContentModal = ({
};
const handleCopyUrl = () => {
navigator.clipboard.writeText(shareUrl);
writeClipboardText(shareUrl)
.then(() => showSuccess(t('链接已复制')))
.catch(() => showError(t('复制失败,请手动复制')));
};
const handleOpenInNewTab = () => {
window.open(shareUrl, '_blank');
};
const close = () => setIsModalOpen(false);
// 视频预览内部视图:标题栏 + 16:9 播放区(加载 / 播放)+ 空态 / 播放失败态;
// 颜色只引用 TokenBridge 注入的 --ui-* 变量(由 Ant token 生成),随浅色 / 深色 / 自定义主题色联动。
const renderVideoContent = () => {
if (!modalContent) {
return (
<div className='task-video-state'>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={t('暂无视频')}
/>
</div>
);
}
if (videoError) {
return (
<div style={{ textAlign: 'center', padding: '40px' }}>
<Text
type='tertiary'
style={{ display: 'block', marginBottom: '16px' }}
>
{t('视频无法在当前浏览器中播放,这可能是由于:')}
<div className='task-video-state is-error'>
<Empty
image={Empty.PRESENTED_IMAGE_SIMPLE}
description={
<div className='task-video-reasons'>
<p>{t('视频无法在当前浏览器中播放,这可能是由于:')}</p>
<span>{t('• 视频服务商的跨域限制')}</span>
<span>{t('• 需要特定的请求头或认证')}</span>
<span>{t('• 防盗链保护机制')}</span>
</div>
}
/>
<Text type='tertiary' className='task-video-url'>
{shareUrl}
</Text>
<Text
type='tertiary'
style={{ display: 'block', marginBottom: '8px', fontSize: '12px' }}
>
{t('• 视频服务商的跨域限制')}
</Text>
<Text
type='tertiary'
style={{ display: 'block', marginBottom: '8px', fontSize: '12px' }}
>
{t('• 需要特定的请求头或认证')}
</Text>
<Text
type='tertiary'
style={{ display: 'block', marginBottom: '16px', fontSize: '12px' }}
>
{t('• 防盗链保护机制')}
</Text>
<div style={{ marginTop: '20px' }}>
<Button
icon={<IconExternalOpen />}
onClick={handleOpenInNewTab}
style={{ marginRight: '8px' }}
>
{t('在新标签页中打开')}
</Button>
<Button icon={<IconCopy />} onClick={handleCopyUrl}>
{t('复制链接')}
</Button>
</div>
<div
style={{
marginTop: '16px',
padding: '8px',
backgroundColor: 'var(--ui-color-fill-0)',
borderRadius: '4px',
}}
>
<Text
type='tertiary'
style={{ fontSize: '10px', wordBreak: 'break-all' }}
>
{shareUrl}
</Text>
</div>
</div>
);
}
return (
<div style={{ position: 'relative' }}>
<div className='task-video-stage'>
{isLoading && (
<div
style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
zIndex: 10,
}}
>
<div className='task-video-loading'>
<Spin size='large' />
</div>
)}
<video
ref={videoRef}
className='task-video-player'
src={modalContent}
controls
style={{ width: '100%' }}
autoPlay
crossOrigin='anonymous'
onError={handleVideoError}
onLoadedData={handleVideoLoaded}
onLoadStart={() => setIsLoading(true)}
/>
{/* 播放成功时也提供复制/新标签页按钮,复制的是上游分享 URL 而非代理路径 */}
<div
style={{
marginTop: '12px',
display: 'flex',
gap: '8px',
justifyContent: 'flex-end',
}}
>
<Button size='small' icon={<IconCopy />} onClick={handleCopyUrl}>
{t('复制链接')}
</Button>
<Button
size='small'
icon={<IconExternalOpen />}
onClick={handleOpenInNewTab}
>
{t('在新标签页打开')}
</Button>
</div>
</div>
);
};
if (isVideo) {
// 复制 / 新标签页打开统一放在页脚(播放成功与失败两态都可用),复制的是上游分享 URL 而非代理路径
const footer = (
<div
className='task-video-footer'
style={{ '--task-video-button-height': `${token.controlHeight}px` }}
>
{shareUrl && (
<>
<Button icon={<IconCopy />} onClick={handleCopyUrl}>
{t('复制链接')}
</Button>
<Button icon={<IconExternalOpen />} onClick={handleOpenInNewTab}>
{videoError ? t('在新标签页中打开') : t('在新标签页打开')}
</Button>
</>
)}
<Button type='primary' onClick={close}>
{t('关闭')}
</Button>
</div>
);
return (
<Modal
className='task-content-modal task-video-modal'
title={t('视频预览')}
visible={isModalOpen}
onOk={close}
onCancel={close}
footer={footer}
width={800}
>
{renderVideoContent()}
</Modal>
);
}
return (
<Modal
className='task-content-modal'
visible={isModalOpen}
onOk={() => setIsModalOpen(false)}
onCancel={() => setIsModalOpen(false)}
onOk={close}
onCancel={close}
closable={null}
bodyStyle={{
height: isVideo ? '450px' : '400px',
height: '400px',
overflowX: 'hidden',
overflowY: 'auto',
padding: isVideo && videoError ? '0' : '24px',
padding: '24px',
}}
width={800}
>
{isVideo ? (
renderVideoContent()
) : (
<p style={{ whiteSpace: 'pre-line', overflowWrap: 'anywhere' }}>
{modalContent}
</p>
)}
<p style={{ whiteSpace: 'pre-line', overflowWrap: 'anywhere' }}>
{modalContent}
</p>
</Modal>
);
};
@@ -0,0 +1,101 @@
/*
* 任务日志内容 / 视频预览弹窗(ContentModal)内部样式。
* 原型“消耗明细 → 绘图与视频 → 点击预览视频”未定义弹框,按“未定义项”规则:
* Ant Design Modal 默认结构(标题栏、右上关闭、页脚按钮、遮罩)+ 全局 token;无装饰、阴影与动画。
* 颜色只引用 UiThemeProvider TokenBridge 注入 body 的 --ui-* 变量(由 Ant token 生成),
* Portal 内同样可继承,浅色 / 深色 / 自定义主题色自动联动。选择器以 :where() 降低优先级,不用 !important。
*/
:where(.task-video-modal) .task-video-stage {
position: relative;
width: 100%;
aspect-ratio: 16 / 9;
overflow: hidden;
border: 1px solid var(--ui-color-border-light);
border-radius: var(--ui-border-radius-medium);
background: var(--ui-color-fill-0);
}
:where(.task-video-modal) .task-video-player {
display: block;
width: 100%;
height: 100%;
object-fit: contain;
}
:where(.task-video-modal) .task-video-loading {
position: absolute;
inset: 0;
z-index: 1;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
}
/* 空态 / 播放失败态:与播放区同为 16:9 占位,内容居中 */
:where(.task-video-modal) .task-video-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 16px;
width: 100%;
min-height: 0;
aspect-ratio: 16 / 9;
padding: 24px;
border: 1px dashed var(--ui-color-border);
border-radius: var(--ui-border-radius-medium);
background: var(--ui-color-fill-0);
}
:where(.task-video-modal) .task-video-state .ant-empty {
margin: 0;
}
:where(.task-video-modal) .task-video-reasons {
display: flex;
flex-direction: column;
gap: 4px;
color: var(--ui-color-text-1);
font-size: 12px;
line-height: 20px;
}
:where(.task-video-modal) .task-video-reasons p {
margin: 0 0 4px;
color: var(--ui-color-text);
font-size: 14px;
line-height: 22px;
}
:where(.task-video-modal) .task-video-url {
display: block;
max-width: 100%;
padding: 8px 12px;
border-radius: var(--ui-border-radius-small);
background: var(--ui-color-fill-1);
font-family: var(--ui-font-family-mono);
font-size: 12px;
line-height: 18px;
word-break: break-all;
}
:where(.task-video-modal) .task-video-footer {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 8px;
}
:where(.task-video-modal) .task-video-footer .ant-btn {
height: var(--task-video-button-height);
}
@media (max-width: 767px) {
:where(.task-video-modal) .task-video-state {
aspect-ratio: auto;
min-height: 220px;
padding: 16px;
}
}
@@ -261,7 +261,7 @@ const renderQuotaUsage = (text, record, t) => {
if (record.unlimited_quota) {
const popoverContent = (
<div className='text-xs p-2'>
<Paragraph copyable={{ content: renderQuota(used) }}>
<Paragraph copyable={{ text: renderQuota(used) }}>
{t('已用额度')}: {renderQuota(used)}
</Paragraph>
</div>
@@ -277,13 +277,13 @@ const renderQuotaUsage = (text, record, t) => {
const percent = total > 0 ? (remain / total) * 100 : 0;
const popoverContent = (
<div className='text-xs p-2'>
<Paragraph copyable={{ content: renderQuota(used) }}>
<Paragraph copyable={{ text: renderQuota(used) }}>
{t('已用额度')}: {renderQuota(used)}
</Paragraph>
<Paragraph copyable={{ content: renderQuota(remain) }}>
<Paragraph copyable={{ text: renderQuota(remain) }}>
{t('剩余额度')}: {renderQuota(remain)} ({percent.toFixed(0)}%)
</Paragraph>
<Paragraph copyable={{ content: renderQuota(total) }}>
<Paragraph copyable={{ text: renderQuota(total) }}>
{t('总额度')}: {renderQuota(total)}
</Paragraph>
</div>
@@ -49,6 +49,18 @@
padding: 16px;
}
.usage-billing-detail .usage-billing-heading {
display: flex;
align-items: center;
gap: 5px;
line-height: 20px;
}
.usage-billing-heading > svg {
display: block;
flex-shrink: 0;
}
.usage-logs-date-panel {
--usage-date-accent: var(--brand-gradient-via);
--usage-date-accent-strong: var(--brand-gradient-to);
@@ -336,12 +336,56 @@ const formatRecordNumber = (value) => {
return Number.isFinite(number) ? number.toLocaleString('en-US') : value;
};
// Both reference images show the same 2097px table at opposite scroll positions.
const RECORD_COLUMN_WIDTHS = {
time: 152,
channel: 85,
username: 120,
token: 120,
group: 148,
type: 110,
model: 225,
use_time: 126,
prompt: 110,
completion: 110,
cost: 136,
ip: 110,
retry: 120,
details: 305,
};
// 仅替换展示,不改变列的显示条件、复制回调与数据来源
const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
columns.map((column) => {
const applyUsageRecordPresentation = (
columns,
{ t, COLUMN_KEYS, copyText, showUserInfoFunc, isAdminUser },
) =>
columns.map((baseColumn) => {
const column = {
...baseColumn,
width: RECORD_COLUMN_WIDTHS[baseColumn.key],
fixed: undefined,
className: `usage-record-cell-${baseColumn.key}`,
};
switch (column.key) {
case COLUMN_KEYS.TIME:
return { ...column, render: (text) => renderRecordTime(text) };
case COLUMN_KEYS.USERNAME:
return {
...column,
render: (text, record) =>
isAdminUser ? (
<button
type='button'
className='usage-record-copy-text'
onClick={(event) => {
event.stopPropagation();
showUserInfoFunc(record.user_id);
}}
>
{record.display_name || text}
</button>
) : null,
};
case COLUMN_KEYS.TOKEN:
return {
...column,
@@ -374,16 +418,21 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
case COLUMN_KEYS.MODEL:
return {
...column,
render: (text, record, index) =>
render: (text, record) =>
record.type === 0 || record.type === 2 || record.type === 5 ? (
<span className='usage-record-model'>
{column.render(text, record, index)}
</span>
<button
type='button'
className='usage-record-copy-text usage-record-model'
onClick={(event) => copyText(event, record.model_name)}
>
{record.model_name}
</button>
) : null,
};
case COLUMN_KEYS.USE_TIME:
return {
...column,
title: t('用时/首字').replace('/', ' / '),
render: (text, record) =>
record.type === 2 || record.type === 5
? renderRecordUseTime(record, t)
@@ -396,7 +445,13 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
align: 'right',
render: (text, record, index) => {
const node = column.render(text, record, index);
return node?.props?.children ? formatRecordNumber(text) : null;
const showZero =
column.key === COLUMN_KEYS.COMPLETION &&
Number(text) === 0 &&
[0, 2, 5].includes(record.type);
return node?.props?.children || showZero
? formatRecordNumber(text)
: null;
},
};
case COLUMN_KEYS.COST:
@@ -412,11 +467,50 @@ const applyUsageRecordPresentation = (columns, { t, COLUMN_KEYS, copyText }) =>
case COLUMN_KEYS.IP:
return {
...column,
title: (
<Tooltip
content={t(
'只有当用户设置开启IP记录时,才会进行请求和错误类型日志的IP记录',
)}
>
<span>{t('IP')}</span>
</Tooltip>
),
render: (text, record, index) =>
(record.type === 2 || record.type === 5) && text
? column.render(text, record, index)
: '—',
};
case COLUMN_KEYS.RETRY:
return {
...column,
render: (text, record) => {
if (!isAdminUser || (record.type !== 2 && record.type !== 5))
return null;
const other = getLogOther(record.other);
const channels = other?.admin_info?.use_channel;
return Array.isArray(channels) && channels.length
? channels.join(' → ')
: record.channel;
},
};
case COLUMN_KEYS.DETAILS:
return {
...column,
render: (text, record, index) => {
const node = column.render(text, record, index);
return React.cloneElement(
node,
{
className: 'usage-record-details',
style: { maxWidth: 'none', whiteSpace: 'nowrap' },
},
typeof node.props.children === 'string'
? node.props.children.replaceAll(' * ', ' × ')
: node.props.children,
);
},
};
default:
return column;
}
@@ -787,6 +881,12 @@ export const getLogsColumns = ({
},
];
return usageRecordMode
? applyUsageRecordPresentation(columns, { t, COLUMN_KEYS, copyText })
? applyUsageRecordPresentation(columns, {
t,
COLUMN_KEYS,
copyText,
showUserInfoFunc,
isAdminUser,
})
: columns;
};
@@ -19,20 +19,10 @@ For commercial licensing, please contact support@quantumnous.com
import React from 'react';
import { Button, Form } from '@/components/ui';
import {
Calendar,
Cpu,
Download,
Filter,
Hash,
Key,
Layers,
Radio,
RotateCcw,
Search,
Settings2,
Users,
} from 'lucide-react';
import { Search } from 'lucide-react';
import '../../common/table/log-filters.css';
import FilterSearchButton from '../../common/table/FilterSearchButton';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
import { DATE_RANGE_PRESETS } from '../../../constants/console.constants';
@@ -40,8 +30,6 @@ const LogsFilters = ({
formInitValues,
setFormApi,
refresh,
setShowColumnSelector,
setShowExportModal,
formApi,
loading,
isAdminUser,
@@ -49,18 +37,8 @@ const LogsFilters = ({
usageRecordMode = false,
t,
}) => {
const controlClass = 'w-full';
const SearchIcon = Search;
const ResetIcon = RotateCcw;
const ColumnsIcon = Settings2;
const ExportIcon = Download;
const InputPrefix = ({ icon: Icon }) => (
<Icon
className='ml-1 mr-1.5 w-3.5 h-3.5 text-gray-400 dark:text-gray-500'
strokeWidth={2}
/>
);
const { scheduleSearch, submitSearch, cancelPendingSearch } =
useFilterSearch(refresh);
// 用户 ID 仅允许数字:键入过滤与粘贴清洗(两种布局共用)
const digitsOnlyKeyDown = (e) => {
if (
@@ -104,6 +82,7 @@ const LogsFilters = ({
? getFreshInitValues()
: formInitValues;
formApi.setValues(fresh, { isOverride: true });
cancelPendingSearch();
setTimeout(() => {
refresh();
}, 100);
@@ -223,119 +202,79 @@ const LogsFilters = ({
<Form
initValues={formInitValues}
getFormApi={(api) => setFormApi(api)}
onSubmit={refresh}
onSubmit={submitSearch}
allowEmpty={true}
autoComplete='off'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='usage-logs-filter-form'
className='usage-logs-filter-form log-filter-form'
onValueChange={scheduleSearch}
>
<div className='usage-logs-filter-content'>
<header className='usage-logs-filter-title'>
<span className='usage-logs-filter-title-icon'>
<Filter className='w-3.5 h-3.5' />
</span>
<span className='text-sm font-semibold text-gray-700 dark:text-gray-200'>
{t('筛选条件')}
</span>
</header>
<div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3'>
<div className='log-filter-content'>
<div className='log-filter-grid'>
<Form.DatePicker
field='dateRange'
className={`${controlClass} lg:col-span-2`}
label={t('时间范围')}
className='log-filter-wide'
dropdownClassName='usage-logs-date-panel'
type='dateTimeRange'
placeholder={[t('开始时间'), t('结束时间')]}
showClear
pure
size='small'
prefix={<InputPrefix icon={Calendar} />}
presets={datePresets}
/>
<Form.Input
field='token_name'
className={controlClass}
prefix={<InputPrefix icon={Key} />}
label={t('密钥名称')}
placeholder={t('密钥名称')}
showClear
pure
size='small'
/>
<Form.Input
field='model_name'
className={controlClass}
prefix={<InputPrefix icon={Cpu} />}
label={t('模型名称')}
placeholder={t('模型名称')}
showClear
pure
size='small'
/>
<Form.Input
field='group'
className={controlClass}
prefix={<InputPrefix icon={Layers} />}
label={t('分组')}
placeholder={t('分组')}
showClear
pure
size='small'
/>
{isAdminUser && (
<>
<Form.Input
field='channel'
className={controlClass}
prefix={<InputPrefix icon={Radio} />}
label={t('渠道 ID')}
placeholder={t('渠道 ID')}
showClear
pure
size='small'
/>
<Form.Input
field='username'
className={controlClass}
prefix={<InputPrefix icon={Users} />}
label={t('用户名称')}
placeholder={t('用户名称')}
showClear
pure
size='small'
/>
<Form.Input
field='user_id'
className={controlClass}
prefix={<InputPrefix icon={Hash} />}
label={t('用户 ID')}
placeholder={t('用户 ID')}
showClear
pure
size='small'
inputMode='numeric'
onKeyDown={digitsOnlyKeyDown}
onPaste={digitsOnlyPaste}
/>
</>
)}
</div>
<div className='flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3'>
<Form.Select
field='logType'
label={t('类型')}
placeholder={t('日志类型')}
className='w-full sm:w-auto min-w-[140px]'
showClear
pure
onChange={() => {
setTimeout(() => {
refresh();
}, 0);
}}
size='small'
>
<Form.Select.Option value='0'>{t('全部')}</Form.Select.Option>
<Form.Select.Option value='1'>{t('充值')}</Form.Select.Option>
@@ -347,45 +286,10 @@ const LogsFilters = ({
<Form.Select.Option value='5'>{t('错误')}</Form.Select.Option>
)}
</Form.Select>
<div className='flex flex-wrap gap-2 w-full sm:w-auto sm:justify-end'>
<Button
type='primary'
htmlType='submit'
loading={loading}
size='small'
icon={<SearchIcon className='w-3.5 h-3.5' />}
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={resetFilters}
size='small'
icon={<ResetIcon className='w-3.5 h-3.5' />}
>
{t('重置')}
</Button>
<Button
type='tertiary'
onClick={() => setShowColumnSelector(true)}
size='small'
icon={<ColumnsIcon className='w-3.5 h-3.5' />}
>
{t('列设置')}
</Button>
<Button
type='tertiary'
size='small'
icon={<ExportIcon className='w-3.5 h-3.5' />}
onClick={() => setShowExportModal(true)}
>
{t('导出')}
</Button>
</div>
</div>
<div className='log-filter-actions'>
<Button onClick={resetFilters}>{t('重置')}</Button>
<FilterSearchButton loading={loading} />
</div>
</div>
</Form>
@@ -17,13 +17,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import { Empty as AntEmpty } from 'antd';
import { Button, Empty, Modal, Typography } from '@/components/ui';
import { Button as AntButton, Table as AntTable } from 'antd';
import { Modal, Typography } from '@/components/ui';
import {
Coins,
Cpu,
Eye,
Gauge,
Layers3,
ReceiptText,
@@ -31,10 +31,7 @@ import {
Sparkles,
} from 'lucide-react';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getLogOther, renderQuota } from '../../../helpers';
import { getLogsColumns } from './UsageLogsColumnDefs';
@@ -284,9 +281,9 @@ const UsageBillingDetail = ({
<div className='usage-billing-detail'>
<div className='mb-3 flex flex-wrap items-center justify-between gap-2'>
<div>
<div className='flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-white'>
<div className='usage-billing-heading flex items-center text-sm font-semibold text-gray-900 dark:text-white'>
<Sparkles size={15} className='text-brand' />
{t('计费摘要')}
<span>{t('计费摘要')}</span>
</div>
<Text type='tertiary' size='small'>
{t('保留关键成本因子,省略冗长计算公式')}
@@ -310,9 +307,9 @@ const UsageBillingDetail = ({
: 'mt-3 rounded-2xl border border-white/55 bg-white/[0.35] p-3 backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04]'
}
>
<div className='mb-2 flex items-center gap-2 text-xs font-medium uppercase tracking-[0.18em] text-gray-400'>
<div className='usage-billing-heading mb-2 flex items-center text-xs font-medium uppercase tracking-[0.18em] text-gray-400'>
<Layers3 size={13} />
{t('成本因子')}
<span>{t('成本因子')}</span>
</div>
<div className='flex flex-wrap gap-2'>
{details.map((item) => (
@@ -356,6 +353,7 @@ const LogsTable = (logsData) => {
usageRecordMode = false,
} = logsData;
const [detailRecord, setDetailRecord] = useState(null);
const TableComponent = usageRecordMode ? AntTable : CardTable;
// Get all columns
const allColumns = useMemo(() => {
@@ -378,14 +376,10 @@ const LogsTable = (logsData) => {
usageRecordMode,
]);
// Filter columns based on visibility settings
const getVisibleColumns = () => {
return allColumns.filter((column) => visibleColumns[column.key]);
};
const visibleColumnsList = useMemo(() => {
return getVisibleColumns();
}, [visibleColumns, allColumns]);
const visibleColumnsList = useMemo(
() => allColumns.filter((column) => visibleColumns[column.key]),
[visibleColumns, allColumns],
);
const tableColumns = useMemo(() => {
const baseColumns = compactMode
@@ -395,32 +389,41 @@ const LogsTable = (logsData) => {
return [
...baseColumns,
{
title: t('计费详情'),
title: usageRecordMode ? t('操作') : t('计费详情'),
key: 'billingDetailAction',
fixed: compactMode ? undefined : 'right',
fixed: compactMode || usageRecordMode ? undefined : 'right',
width: 120,
render: (_, record) => {
const canView =
expandData[record.key] && expandData[record.key].length > 0;
if (usageRecordMode) {
return (
<AntButton
type='link'
size='small'
className='usage-record-view'
disabled={!canView}
onClick={(event) => {
event.stopPropagation();
if (canView) setDetailRecord(record);
}}
>
{t('查看')}
</AntButton>
);
}
return (
<Button
<AntButton
size='small'
theme='light'
type='primary'
type='link'
disabled={!canView}
icon={<Eye size={14} />}
onClick={(e) => {
e?.stopPropagation?.();
if (canView) setDetailRecord(record);
}}
className={
usageRecordMode
? undefined
: 'usage-record-action-button usage-record-action-button-soft !rounded-full'
}
>
{t('查看')}
</Button>
</AntButton>
);
},
},
@@ -436,7 +439,7 @@ const LogsTable = (logsData) => {
return (
<>
<CardTable
<TableComponent
columns={tableColumns}
dataSource={logs}
rowKey='key'
@@ -448,56 +451,32 @@ const LogsTable = (logsData) => {
: 'rounded-xl overflow-hidden usage-logs-table'
}
size='middle'
empty={
usageRecordMode ? (
<AntEmpty
image={AntEmpty.PRESENTED_IMAGE_SIMPLE}
description={
<>
<div>{t('搜索无结果')}</div>
<div className='usage-record-empty-hint'>
{t('尝试调整筛选条件')}
</div>
</>
{...(usageRecordMode
? {
tableLayout: 'fixed',
locale: {
emptyText: <TableEmpty />,
},
}
: {
empty: <TableEmpty />,
})}
pagination={
usageRecordMode
? false
: {
currentPage: activePage,
pageSize: pageSize,
total: logCount,
pageSizeOptions: [10, 20, 50, 100],
showSizeChanger: true,
onPageSizeChange: (size) => {
handlePageSizeChange(size);
},
onPageChange: handlePageChange,
}
/>
) : (
<div className='py-12'>
<Empty
image={
<IllustrationNoResult style={{ width: 180, height: 180 }} />
}
darkModeImage={
<IllustrationNoResultDark
style={{ width: 180, height: 180 }}
/>
}
description={
<div className='flex flex-col items-center gap-2'>
<span className='text-gray-500 dark:text-gray-400 text-sm'>
{t('搜索无结果')}
</span>
<span className='text-gray-400 dark:text-gray-500 text-xs'>
{t('尝试调整筛选条件')}
</span>
</div>
}
/>
</div>
)
}
pagination={{
currentPage: activePage,
pageSize: pageSize,
total: logCount,
pageSizeOptions: [10, 20, 50, 100],
showSizeChanger: true,
onPageSizeChange: (size) => {
handlePageSizeChange(size);
},
onPageChange: handlePageChange,
}}
hidePagination={true}
{...(!usageRecordMode && { hidePagination: true })}
/>
<Modal
visible={!!detailRecord}
+29 -18
View File
@@ -19,9 +19,11 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useState } from 'react';
import { Card } from 'antd';
import { Download, Settings } from 'lucide-react';
import { Button, Pagination, Tooltip } from '@/components/ui';
import { Download } from 'lucide-react';
import { Button, Pagination } from '@/components/ui';
import CardPro from '../../common/ui/CardPro';
import { TableTitle } from '../../common/table/TableToolbar';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import LogsTable from './UsageLogsTable';
import LogsFilters from './UsageLogsFilters';
import ColumnSelectorModal from './modals/ColumnSelectorModal';
@@ -62,9 +64,9 @@ const LogsPage = ({ usageRecordMode = false }) => {
</div>
</Card>
<Card className='usage-record-card usage-record-table-card'>
<Card className='usage-record-card usage-record-table-card usage-record-consume-card'>
<div className='usage-record-table-head'>
<h3>{t('调用明细')}</h3>
<TableTitle>{t('调用明细')}</TableTitle>
<div className='usage-record-table-actions'>
<Button
icon={<Download size={14} />}
@@ -72,14 +74,10 @@ const LogsPage = ({ usageRecordMode = false }) => {
>
{t('导出')}
</Button>
<Tooltip content={t('列设置')}>
<Button
theme='borderless'
aria-label={t('列设置')}
icon={<Settings size={16} />}
onClick={() => logsData.setShowColumnSelector(true)}
/>
</Tooltip>
<ColumnSettingsButton
open={logsData.showColumnSelector}
onClick={() => logsData.setShowColumnSelector(true)}
/>
</div>
</div>
<LogsTable {...logsData} compactMode={false} usageRecordMode />
@@ -115,11 +113,26 @@ const LogsPage = ({ usageRecordMode = false }) => {
{/* Main Content */}
<CardPro
tableTitle={logsData.t('使用明细')}
type='type2'
className='usage-logs-page usage-logs-panel'
searchArea={
<LogsFilters {...logsData} usageRecordMode={usageRecordMode} />
}
tableActions={
<>
<Button
icon={<Download size={14} />}
onClick={() => logsData.setShowExportModal(true)}
>
{logsData.t('导出')}
</Button>
<ColumnSettingsButton
open={logsData.showColumnSelector}
onClick={() => logsData.setShowColumnSelector(true)}
/>
</>
}
paginationArea={createCardProPagination({
currentPage: logsData.activePage,
pageSize: logsData.pageSize,
@@ -131,12 +144,10 @@ const LogsPage = ({ usageRecordMode = false }) => {
})}
t={logsData.t}
>
<div className='app-card usage-logs-table-shell usage-logs-glass-table mt-4 overflow-hidden'>
<LogsTable
{...logsData}
compactMode={usageRecordMode ? false : logsData.compactMode}
/>
</div>
<LogsTable
{...logsData}
compactMode={usageRecordMode ? false : logsData.compactMode}
/>
</CardPro>
</>
);
@@ -18,16 +18,15 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Modal, Button, Checkbox } from '@/components/ui';
import { ColumnVisibilitySettings } from '../../../common/table/ColumnSettings';
import { getLogsColumns } from '../UsageLogsColumnDefs';
const ColumnSelectorModal = ({
showColumnSelector,
setShowColumnSelector,
visibleColumns,
handleColumnVisibilityChange,
handleSelectAll,
initDefaultColumns,
setVisibleColumns,
getDefaultColumnVisibility,
COLUMN_KEYS,
isAdminUser,
isRootUser,
@@ -47,76 +46,25 @@ const ColumnSelectorModal = ({
usageRecordMode,
});
// 计算"全选"状态时应忽略的 key:当前角色下不可见的管理员专属列
// 否则非管理员下 CHANNEL/USERNAME/RETRY 永远为 false,全选框永远半选
const isHiddenForRole = (key) =>
!isAdminUser &&
(key === COLUMN_KEYS.CHANNEL ||
key === COLUMN_KEYS.USERNAME ||
key === COLUMN_KEYS.RETRY);
const effectiveValues = Object.entries(visibleColumns)
.filter(([key]) => !isHiddenForRole(key))
.map(([, v]) => v);
const allChecked =
effectiveValues.length > 0 && effectiveValues.every((v) => v === true);
const someChecked = effectiveValues.some((v) => v === true);
return (
<Modal
title={t('列设置')}
visible={showColumnSelector}
onCancel={() => setShowColumnSelector(false)}
footer={
<div className='flex justify-end gap-2'>
<Button onClick={() => initDefaultColumns()}>{t('重置')}</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('取消')}
</Button>
<Button onClick={() => setShowColumnSelector(false)}>
{t('确定')}
</Button>
</div>
}
>
<div style={{ marginBottom: 20 }}>
<Checkbox
checked={allChecked}
indeterminate={someChecked && !allChecked}
onChange={(e) => handleSelectAll(e.target.checked)}
>
{t('全选')}
</Checkbox>
</div>
<div
className='flex flex-wrap max-h-96 overflow-y-auto rounded-lg p-4'
style={{ border: '1px solid var(--ui-color-border)' }}
>
{allColumns.map((column) => {
// Skip admin-only columns for non-admin users
if (
<ColumnVisibilitySettings
showColumnSelector={showColumnSelector}
setShowColumnSelector={setShowColumnSelector}
columns={allColumns.filter(
(column) =>
!(
!isAdminUser &&
(column.key === COLUMN_KEYS.CHANNEL ||
column.key === COLUMN_KEYS.USERNAME ||
column.key === COLUMN_KEYS.RETRY)
) {
return null;
}
return (
<div key={column.key} className='w-1/2 mb-4 pr-2'>
<Checkbox
checked={!!visibleColumns[column.key]}
onChange={(e) =>
handleColumnVisibilityChange(column.key, e.target.checked)
}
>
{column.title}
</Checkbox>
</div>
);
})}
</div>
</Modal>
[
COLUMN_KEYS.CHANNEL,
COLUMN_KEYS.USERNAME,
COLUMN_KEYS.RETRY,
].includes(column.key)
),
)}
visibleColumns={visibleColumns}
setVisibleColumns={setVisibleColumns}
getDefaultColumnVisibility={getDefaultColumnVisibility}
/>
);
};
+7 -4
View File
@@ -18,7 +18,8 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React from 'react';
import { Button } from '@/components/ui';
import { Button } from 'antd';
import { Plus } from 'lucide-react';
import { isAdmin } from '../../../helpers';
const UsersActions = ({ setShowAddUser, t }) => {
@@ -28,12 +29,14 @@ const UsersActions = ({ setShowAddUser, t }) => {
};
return (
<div className='flex gap-2 w-full md:w-auto order-2 md:order-1'>
<div className='flex justify-end gap-2'>
{isAdmin() && (
<Button
className='w-full md:w-auto'
className='console-create-action'
type='primary'
icon={<Plus size={16} />}
onClick={handleAddUser}
size='small'
size='middle'
>
{t('添加用户')}
</Button>
+25 -40
View File
@@ -28,6 +28,7 @@ import {
Typography,
Dropdown,
} from '@/components/ui';
import { Switch } from 'antd';
import { IconMore } from '@/components/ui/icons';
import {
renderGroup,
@@ -119,24 +120,24 @@ const renderUsername = (text, record) => {
const renderStatistics = (text, record, showEnableDisableModal, t) => {
const isDeleted = record.DeletedAt !== null;
// Determine tag text & color like original status column
let tagColor = 'grey';
let tagText = t('未知状态');
if (isDeleted) {
tagColor = 'red';
tagText = t('已注销');
} else if (record.status === 1) {
tagColor = 'green';
tagText = t('已启用');
} else if (record.status === 2) {
tagColor = 'red';
tagText = t('已禁用');
}
const content = (
<Tag color={tagColor} shape='circle' size='small'>
{tagText}
</Tag>
const currentRole = Number(getUserData()?.role || 0);
const canManage =
isAdmin() && (currentRole >= 100 || Number(record.role || 0) < 100);
const content = isDeleted ? (
<Tag color='red'>{t('已注销')}</Tag>
) : (
<Switch
size='small'
checked={record.status === 1}
checkedChildren={t('启用')}
unCheckedChildren={t('禁用')}
aria-label={t('状态')}
disabled={!canManage}
onChange={(checked, event) => {
event.stopPropagation();
showEnableDisableModal(record, checked ? 'enable' : 'disable');
}}
/>
);
const tooltipContent = (
@@ -163,13 +164,13 @@ const renderQuotaUsage = (text, record, t) => {
const percent = total > 0 ? (remain / total) * 100 : 0;
const popoverContent = (
<div className='text-xs p-2'>
<Paragraph copyable={{ content: renderQuota(used) }}>
<Paragraph copyable={{ text: renderQuota(used) }}>
{t('已用额度')}: {renderQuota(used)}
</Paragraph>
<Paragraph copyable={{ content: renderQuota(remain) }}>
<Paragraph copyable={{ text: renderQuota(remain) }}>
{t('剩余额度')}: {renderQuota(remain)} ({percent.toFixed(0)}%)
</Paragraph>
<Paragraph copyable={{ content: renderQuota(total) }}>
<Paragraph copyable={{ text: renderQuota(total) }}>
{t('总额度')}: {renderQuota(total)}
</Paragraph>
</div>
@@ -296,11 +297,11 @@ const renderOperations = (
return (
// wrap 保留:移动端 CardTable 把按钮放进 ~280px 的卡片行里,Semi Space 默认
// wrap:false 时溢出会被 .ant-card{overflow:hidden} 裁掉(不是滚动,是永久看不到)
<Space wrap>
<Space wrap className='console-module-row-actions'>
{canManage && (
<>
<Button
type='tertiary'
type='link'
size='small'
onClick={() => {
setEditingUser(record);
@@ -309,22 +310,6 @@ const renderOperations = (
>
{t('编辑')}
</Button>
{record.status === 1 ? (
<Button
type='danger'
size='small'
onClick={() => showEnableDisableModal(record, 'disable')}
>
{t('禁用')}
</Button>
) : (
<Button
size='small'
onClick={() => showEnableDisableModal(record, 'enable')}
>
{t('启用')}
</Button>
)}
</>
)}
<Dropdown menu={moreMenu} trigger='click' position='bottomRight'>
@@ -409,7 +394,7 @@ export const getUsersColumns = ({
fixed: 'right',
// 200 而不是更窄:en 下「Edit + Disable + 更多」三控件 ≈ 190px,
// 再窄会触发 Space wrap 折行,重新撑高行高(本次改版要消灭的问题)
width: 200,
width: 120,
render: (text, record, index) =>
renderOperations(text, record, {
setEditingUser,
@@ -21,10 +21,20 @@ import React from 'react';
import { Typography } from '@/components/ui';
import { IconUserAdd } from '@/components/ui/icons';
import CompactModeToggle from '../../common/ui/CompactModeToggle';
import { useConsolePage } from '../../console/ConsoleContext';
const { Text } = Typography;
const UsersDescription = ({ compactMode, setCompactMode, t }) => {
const consolePage = useConsolePage();
if (consolePage)
return (
<CompactModeToggle
compactMode={compactMode}
setCompactMode={setCompactMode}
t={t}
/>
);
return (
<div className='flex flex-col md:flex-row justify-between items-start md:items-center gap-2 w-full'>
<div className='flex items-center text-blue-500'>
+25 -37
View File
@@ -18,7 +18,9 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useRef } from 'react';
import { Form, Button } from '@/components/ui';
import { Form } from '@/components/ui';
import { ConsoleFilterActions } from '../../console/ConsoleModuleFilters';
import { useFilterSearch } from '../../../hooks/common/useFilterSearch';
import { IconSearch } from '@/components/ui/icons';
const UsersFilters = ({
@@ -33,11 +35,16 @@ const UsersFilters = ({
searching,
t,
}) => {
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
() => searchUsers(1, pageSize),
);
const formApiRef = useRef(null);
const handleReset = () => {
if (!formApiRef.current) return;
formApiRef.current.reset();
cancelPendingSearch();
setTimeout(() => {
loadUsers(1, pageSize);
}, 100);
@@ -45,69 +52,50 @@ const UsersFilters = ({
return (
<Form
initValues={formInitValues}
initValues={{
...formInitValues,
searchGroup: formInitValues.searchGroup || undefined,
}}
getFormApi={(api) => {
setFormApi(api);
formApiRef.current = api;
}}
onSubmit={() => {
searchUsers(1, pageSize);
}}
onSubmit={submitSearch}
allowEmpty={true}
autoComplete='off'
layout='horizontal'
layout='vertical'
trigger='change'
stopValidateWithError={false}
className='w-full md:w-auto order-1 md:order-2'
className='console-module-filter-form'
onValueChange={scheduleSearch}
>
<div className='flex flex-col md:flex-row items-center gap-2 w-full md:w-auto'>
<div className='relative w-full md:w-64'>
<div className='console-module-filter-grid'>
<div className='console-module-field'>
<Form.Input
label={t('用户名')}
field='searchKeyword'
prefix={<IconSearch />}
placeholder={t('支持搜索用户的 ID、用户名、显示名称和邮箱地址')}
showClear
pure
size='small'
/>
</div>
<div className='w-full md:w-48'>
<div className='console-module-field'>
<Form.Select
label={t('分组')}
field='searchGroup'
placeholder={t('选择分组')}
optionList={groupOptions}
onChange={(value) => {
// Group change triggers automatic search
setTimeout(() => {
searchUsers(1, pageSize);
}, 100);
}}
className='w-full'
showClear
pure
size='small'
/>
</div>
<div className='flex gap-2 w-full md:w-auto'>
<Button
type='tertiary'
htmlType='submit'
loading={loading || searching}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('查询')}
</Button>
<Button
type='tertiary'
onClick={handleReset}
className='flex-1 md:flex-initial md:w-auto'
size='small'
>
{t('重置')}
</Button>
</div>
</div>
<ConsoleFilterActions
onReset={handleReset}
loading={loading || searching}
/>
</Form>
);
};
+3 -15
View File
@@ -17,13 +17,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
import TableEmpty from '../../common/table/TableEmpty';
import React, { useMemo, useState } from 'react';
import { Empty } from '@/components/ui';
import CardTable from '../../common/ui/CardTable';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../common/illustrations';
import { getUsersColumns } from './UsersColumnDefs';
import PromoteUserModal from './modals/PromoteUserModal';
import DemoteUserModal from './modals/DemoteUserModal';
@@ -185,16 +182,7 @@ const UsersTable = (usersData) => {
hidePagination={true}
loading={loading}
onRow={handleRow}
empty={
<Empty
image={<IllustrationNoResult style={{ width: 150, height: 150 }} />}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('搜索无结果')}
style={{ padding: 30 }}
/>
}
empty={<TableEmpty />}
className='overflow-hidden'
size='middle'
/>
+17 -18
View File
@@ -78,6 +78,21 @@ const UsersPage = () => {
/>
<CardPro
tableTitle={t('用户列表')}
searchArea={
<UsersFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchUsers={searchUsers}
loadUsers={loadUsers}
activePage={activePage}
pageSize={pageSize}
groupOptions={groupOptions}
loading={loading}
searching={searching}
t={t}
/>
}
type='type1'
descriptionArea={
<UsersDescription
@@ -86,25 +101,9 @@ const UsersPage = () => {
t={t}
/>
}
actionsArea={
<div className='flex flex-col md:flex-row justify-between items-center gap-2 w-full'>
<UsersActions setShowAddUser={setShowAddUser} t={t} />
<UsersFilters
formInitValues={formInitValues}
setFormApi={setFormApi}
searchUsers={searchUsers}
loadUsers={loadUsers}
activePage={activePage}
pageSize={pageSize}
groupOptions={groupOptions}
loading={loading}
searching={searching}
t={t}
/>
</div>
}
tableActions={<UsersActions setShowAddUser={setShowAddUser} t={t} />}
paginationArea={createCardProPagination({
showRange: false,
currentPage: usersData.activePage,
pageSize: usersData.pageSize,
total: usersData.userCount,
@@ -20,24 +20,9 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useState, useRef } from 'react';
import { API, showError, showSuccess } from '../../../../helpers';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
import {
Button,
SideSheet,
Space,
Spin,
Typography,
Card,
Tag,
Avatar,
Form,
Row,
Col,
} from '@/components/ui';
import { IconSave, IconClose, IconUserAdd } from '@/components/ui/icons';
import { Button, SideSheet, Spin, Form, Row, Col } from '@/components/ui';
import { useTranslation } from 'react-i18next';
const { Text, Title } = Typography;
const AddUserModal = (props) => {
const { t } = useTranslation();
const formApiRef = useRef(null);
@@ -73,43 +58,23 @@ const AddUserModal = (props) => {
return (
<>
<SideSheet
placement={'left'}
title={
<Space>
<Tag color='green' shape='circle'>
{t('新建')}
</Tag>
<Title heading={4} className='m-0'>
{t('添加用户')}
</Title>
</Space>
}
bodyStyle={{ padding: '0' }}
placement='right'
classNames={{ header: 'console-detail-header' }}
title={t('添加用户')}
visible={props.visible}
width={isMobile ? '100%' : 600}
width={isMobile ? '100%' : 560}
footer={
<div className='flex justify-end'>
<Space>
<Button
theme='solid'
onClick={() => formApiRef.current?.submitForm()}
icon={<IconSave />}
loading={loading}
>
{t('提交')}
</Button>
<Button
theme='light'
type='primary'
onClick={handleCancel}
icon={<IconClose />}
>
{t('取消')}
</Button>
</Space>
<div className='console-dialog-actions'>
<Button onClick={handleCancel}>{t('取消')}</Button>
<Button
theme='solid'
onClick={() => formApiRef.current?.submitForm()}
loading={loading}
>
{t('确定')}
</Button>
</div>
}
closeIcon={null}
onCancel={() => handleCancel()}
>
<Spin spinning={loading}>
@@ -123,59 +88,43 @@ const AddUserModal = (props) => {
formApiRef.current?.scrollToError();
}}
>
<div className='p-2'>
<Card className='!rounded-2xl shadow-sm border-0'>
<div className='flex items-center mb-2'>
<Avatar size='small' color='blue' className='mr-2 shadow-md'>
<IconUserAdd size={16} />
</Avatar>
<div>
<Text className='text-lg font-medium'>{t('用户信息')}</Text>
<div className='text-xs text-gray-600'>
{t('创建新用户账户')}
</div>
</div>
</div>
<Row gutter={12}>
<Col span={24}>
<Form.Input
field='username'
label={t('用户名')}
placeholder={t('请输入用户名')}
rules={[{ required: true, message: t('请输入用户名') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='display_name'
label={t('显示名称')}
placeholder={t('请输入显示名称')}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='password'
label={t('密码')}
type='password'
placeholder={t('请输入密码')}
rules={[{ required: true, message: t('请输入密码') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='remark'
label={t('备注')}
placeholder={t('请输入备注(仅管理员可见)')}
showClear
/>
</Col>
</Row>
</Card>
</div>
<Row gutter={12}>
<Col span={24}>
<Form.Input
field='username'
label={t('用户名')}
placeholder={t('请输入用户名')}
rules={[{ required: true, message: t('请输入用户名') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='display_name'
label={t('显示名称')}
placeholder={t('请输入显示名称')}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='password'
label={t('密码')}
type='password'
placeholder={t('请输入密码')}
rules={[{ required: true, message: t('请输入密码') }]}
showClear
/>
</Col>
<Col span={24}>
<Form.Input
field='remark'
label={t('备注')}
placeholder={t('请输入备注(仅管理员可见)')}
showClear
/>
</Col>
</Row>
</Form>
</Spin>
</SideSheet>
@@ -19,12 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
import React, { useEffect, useState, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import {
API,
showError,
showSuccess,
renderQuota,
} from '../../../../helpers';
import { API, showError, showSuccess, renderQuota } from '../../../../helpers';
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
import {
Button,
@@ -34,25 +29,20 @@ import {
Spin,
Typography,
Card,
Tag,
Form,
Avatar,
Row,
Col,
} from '@/components/ui';
import QuotaInput, {
FormQuotaInput,
} from '../../../common/ui/QuotaInput';
import QuotaInput, { FormQuotaInput } from '../../../common/ui/QuotaInput';
import {
IconUser,
IconSave,
IconClose,
IconLink,
IconUserGroup,
IconPlus,
} from '@/components/ui/icons';
const { Text, Title } = Typography;
const { Text } = Typography;
const EditUserModal = (props) => {
const { t } = useTranslation();
@@ -176,42 +166,25 @@ const EditUserModal = (props) => {
<>
<SideSheet
placement='right'
title={
<Space>
<Tag color='blue' shape='circle'>
{t(isEdit ? '编辑' : '新建')}
</Tag>
<Title heading={4} className='m-0'>
{isEdit ? t('编辑用户') : t('创建用户')}
</Title>
</Space>
}
classNames={{ header: 'console-detail-header' }}
title={isEdit ? t('编辑用户') : t('创建用户')}
bodyStyle={{ padding: 0 }}
visible={props.visible}
width={isMobile ? '100%' : 600}
footer={
<div className='flex justify-end'>
<Space>
<Button onClick={handleCancel}>{t('取消')}</Button>
<Button
theme='solid'
onClick={() => formApiRef.current?.submitForm()}
icon={<IconSave />}
loading={loading}
>
{t('提交')}
</Button>
<Button
theme='light'
type='primary'
onClick={handleCancel}
icon={<IconClose />}
>
{t('取消')}
{t('确定')}
</Button>
</Space>
</div>
}
closeIcon={null}
onCancel={handleCancel}
>
<Spin spinning={loading}>
@@ -18,12 +18,9 @@ For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useEffect } from 'react';
import { Modal, Table, Tag, Empty, Spin } from '@/components/ui';
import { Modal, Table, Tag, Spin } from '@/components/ui';
import { API, renderQuota, renderNumber, showError } from '../../../../helpers';
import {
IllustrationNoResult,
IllustrationNoResultDark,
} from '../../../common/illustrations';
import TableEmpty from '../../../common/table/TableEmpty';
const InvitedUsersModal = ({ visible, onCancel, user, t }) => {
const [invitedUsers, setInvitedUsers] = useState([]);
@@ -162,18 +159,7 @@ const InvitedUsersModal = ({ visible, onCancel, user, t }) => {
dataSource={invitedUsers}
pagination={false}
size='small'
empty={
<Empty
image={
<IllustrationNoResult style={{ width: 150, height: 150 }} />
}
darkModeImage={
<IllustrationNoResultDark style={{ width: 150, height: 150 }} />
}
description={t('该用户暂未邀请任何用户')}
style={{ padding: 30 }}
/>
}
empty={<TableEmpty />}
style={{ maxHeight: '500px', overflowY: 'auto' }}
/>
</Spin>