fix(ui): 完善控制台列表并优化企业中心与个人操作

This commit is contained in:
zhanjunhao
2026-11-25 10:05:30 +08:00
parent dd4da99f1d
commit a532b860c8
51 changed files with 1736 additions and 1306 deletions
@@ -24,43 +24,24 @@ const { Text, Title, Paragraph } = Typography;
// 默认海报模板配置
const DEFAULT_TEMPLATES = [
{
id: 'blue',
name: '科技蓝',
bgGradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
textColor: '#ffffff',
},
{
id: 'orange',
name: '活力橙',
bgGradient: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)',
textColor: '#ffffff',
},
{
id: 'green',
name: '清新绿',
bgGradient: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)',
textColor: '#ffffff',
},
{
id: 'dark',
name: '暗夜黑',
bgGradient: 'linear-gradient(135deg, #232526 0%, #414345 100%)',
textColor: '#ffffff',
},
{ id: 'blue', name: '科技蓝' },
{ id: 'orange', name: '活力橙' },
{ id: 'green', name: '清新绿' },
{ id: 'dark', name: '暗夜黑' },
];
const PromotionPosterModal = ({ visible, onClose }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const canvasRef = useRef(null);
const previewRef = useRef(null);
const [loading, setLoading] = useState(true);
const [affCode, setAffCode] = useState('');
const [affLink, setAffLink] = useState('');
const [systemName, setSystemName] = useState('');
const [selectedTemplate, setSelectedTemplate] = useState(
DEFAULT_TEMPLATES[0],
DEFAULT_TEMPLATES[0].id,
);
const [downloading, setDownloading] = useState(false);
const [posterConfig, setPosterConfig] = useState(null);
@@ -123,9 +104,7 @@ const PromotionPosterModal = ({ visible, onClose }) => {
// 绘制海报内容
const drawContent = useCallback(
(ctx, width, height) => {
const textColor = selectedTemplate.textColor;
(ctx, width, height, textColor) => {
ctx.fillStyle = textColor;
ctx.font =
'bold 28px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';
@@ -187,15 +166,17 @@ const PromotionPosterModal = ({ visible, onClose }) => {
height - 45,
);
},
[selectedTemplate, posterConfig, systemName, affCode, t],
[posterConfig, systemName, affCode, t],
);
// 绘制海报到 Canvas
const drawPoster = useCallback(() => {
const canvas = canvasRef.current;
if (!canvas || !affLink) return null;
const preview = previewRef.current;
if (!canvas || !preview || !affLink) return null;
const ctx = canvas.getContext('2d');
const { backgroundColor, color } = getComputedStyle(preview);
const width = 375;
const height = 667;
@@ -203,26 +184,12 @@ const PromotionPosterModal = ({ visible, onClose }) => {
canvas.height = height * 2;
ctx.scale(2, 2);
const gradient = ctx.createLinearGradient(0, 0, width, height);
if (selectedTemplate.id === 'blue') {
gradient.addColorStop(0, '#667eea');
gradient.addColorStop(1, '#764ba2');
} else if (selectedTemplate.id === 'orange') {
gradient.addColorStop(0, '#f093fb');
gradient.addColorStop(1, '#f5576c');
} else if (selectedTemplate.id === 'green') {
gradient.addColorStop(0, '#4facfe');
gradient.addColorStop(1, '#00f2fe');
} else {
gradient.addColorStop(0, '#232526');
gradient.addColorStop(1, '#414345');
}
ctx.fillStyle = gradient;
ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, width, height);
drawContent(ctx, width, height);
drawContent(ctx, width, height, color);
return canvas;
}, [affLink, selectedTemplate, drawContent]);
}, [affLink, drawContent]);
// 下载海报
const handleDownload = async () => {
@@ -354,14 +321,12 @@ const PromotionPosterModal = ({ visible, onClose }) => {
const renderPosterMode = () => (
<div className='pm-poster-layout'>
<div className='pm-preview-stage'>
<div
className='pm-poster'
style={{
'--pm-poster-background': selectedTemplate.bgGradient,
'--pm-poster-ink': selectedTemplate.textColor,
}}
>
<div
className='pm-preview-stage'
data-poster-template={selectedTemplate}
ref={previewRef}
>
<div className='pm-poster'>
<h2>{posterConfig?.slogan || t('邀请好友,共享AI')}</h2>
<p className='pm-poster-subtitle'>
{posterConfig?.sub_slogan || t('注册即可获得免费额度')}
@@ -393,21 +358,15 @@ const PromotionPosterModal = ({ visible, onClose }) => {
<Radio.Group
className='pm-template-list'
aria-labelledby='promotion-template-label'
value={selectedTemplate.id}
onChange={(event) =>
setSelectedTemplate(
DEFAULT_TEMPLATES.find(
(item) => item.id === event.target.value,
),
)
}
value={selectedTemplate}
onChange={(event) => setSelectedTemplate(event.target.value)}
>
{DEFAULT_TEMPLATES.map((template) => (
<Radio key={template.id} value={template.id}>
<span className='pm-template-label'>
<span
className='pm-template-swatch'
style={{ '--pm-template-background': template.bgGradient }}
data-poster-template={template.id}
/>
{t(template.name)}
</span>
@@ -447,7 +406,7 @@ const PromotionPosterModal = ({ visible, onClose }) => {
footer={null}
width={800}
centered
className='promotion-modal'
className={`promotion-modal${activeTab === 'poster' ? ' promotion-modal--poster' : ''}`}
>
{loading ? (
<div className='pm-loading' aria-label={t('加载中...')}>
+26 -11
View File
@@ -9,6 +9,7 @@
--pm-accent: var(--brand-primary);
--pm-soft: var(--brand-primary-soft);
--pm-qr-surface: #fff;
--pm-poster-ink: #fff;
max-width: calc(100vw - 32px);
padding-block: 24px;
}
@@ -162,6 +163,9 @@
border-color: var(--pm-accent);
background: var(--pm-soft);
}
.promotion-modal--poster .pm-rewards {
display: none;
}
.pm-rewards-icon {
display: flex;
align-items: center;
@@ -197,27 +201,37 @@
gap: 32px;
align-items: center;
}
.promotion-modal [data-poster-template='blue'] {
--pm-template-background: #2455b8;
}
.promotion-modal [data-poster-template='orange'] {
--pm-template-background: #a94913;
}
.promotion-modal [data-poster-template='green'] {
--pm-template-background: #226b50;
}
.promotion-modal [data-poster-template='dark'] {
--pm-template-background: #272b33;
}
.pm-preview-stage {
display: flex;
justify-content: center;
padding: 20px;
border: 1px solid var(--pm-border);
padding-inline: 16px;
border-radius: 12px;
background: var(--pm-muted);
background: var(--pm-template-background);
color: var(--pm-poster-ink);
min-width: 0;
}
.pm-poster {
display: flex;
flex-direction: column;
align-items: center;
width: 240px;
width: min(100%, 280px);
min-width: 0;
aspect-ratio: 375 / 667;
padding: 28px 16px 20px;
background: var(--pm-poster-background);
color: var(--pm-poster-ink);
border-radius: 8px;
min-height: 448px;
padding: 32px 8px 24px;
text-align: center;
overflow-wrap: anywhere;
}
.pm-poster h2 {
margin: 0 0 8px;
@@ -329,8 +343,9 @@
.pm-field > .ant-btn {
width: 100%;
}
.pm-preview-stage {
padding: 16px;
.pm-poster {
min-height: 408px;
padding-block: 24px 20px;
}
.pm-template-list {
grid-template-columns: repeat(2, minmax(0, 1fr));
+3 -2
View File
@@ -223,8 +223,9 @@
.quality-breakdown-org-body .quality-notice {
align-items: center;
justify-content: center;
text-align: center;
justify-content: flex-start;
gap: 6px;
text-align: left;
}
.quality-breakdown-org-body .quality-notice > svg {
@@ -360,11 +360,16 @@ export const getChannelsColumns = ({
key: COLUMN_KEYS.ID,
title: t('ID'),
dataIndex: 'id',
fixed: 'left',
width: 64,
},
{
key: COLUMN_KEYS.NAME,
title: t('名称'),
dataIndex: 'name',
fixed: 'left',
width: 112,
ellipsis: { showTitle: false },
render: (text, record, index) => {
if (record.remark && record.remark.trim() !== '') {
return (
@@ -394,11 +399,11 @@ export const getChannelsColumns = ({
trigger={hoverOrClickTrigger()}
position='topLeft'
>
<span>{text}</span>
<span title={text}>{text}</span>
</Tooltip>
);
}
return text;
return <span title={text}>{text}</span>;
},
},
{
@@ -709,7 +714,6 @@ export const getChannelsColumns = ({
key: COLUMN_KEYS.OPERATE,
title: t('操作'),
dataIndex: 'operate',
fixed: 'right',
render: (text, record, index) => {
if (record.children === undefined) {
const moreMenuItems = [
@@ -5,6 +5,8 @@ import CardTable from '../../common/ui/CardTable';
import { isRoot } from '../../../helpers';
import { getChannelsColumns } from './ChannelsColumnDefs';
const SELECTION_COLUMN_WIDTH = 34;
const ChannelsTable = (channelsData) => {
const {
channels,
@@ -51,6 +53,7 @@ const ChannelsTable = (channelsData) => {
} = channelsData;
const [idSortOrder, setIdSortOrder] = useState('descend');
const canSelect = isRoot();
const handleTableChange = ({ sorter, extra, action }) => {
if ((action ?? extra?.action) !== 'sort') return;
@@ -166,7 +169,7 @@ const ChannelsTable = (channelsData) => {
const visibleColumnsList = getVisibleColumns();
const tableColumns = useMemo(() => {
const sortableColumns = visibleColumnsList.map((column) =>
return visibleColumnsList.map((column) =>
column.key === COLUMN_KEYS.ID
? {
...column,
@@ -179,14 +182,12 @@ const ChannelsTable = (channelsData) => {
}
: column,
);
return compactMode
? sortableColumns.map(({ fixed, ...rest }) => rest)
: sortableColumns;
}, [compactMode, visibleColumnsList, COLUMN_KEYS.ID, idSort, idSortOrder]);
}, [visibleColumnsList, COLUMN_KEYS.ID, idSort, idSortOrder]);
return (
<CardTable
columns={tableColumns}
minScrollableWidth={72 + (canSelect ? SELECTION_COLUMN_WIDTH : 0)}
onChange={handleTableChange}
dataSource={filteredChannels}
scroll={compactMode ? undefined : { x: 'max-content' }}
@@ -203,8 +204,10 @@ const ChannelsTable = (channelsData) => {
expandAllRows={false}
onRow={handleRow}
rowSelection={
isRoot()
canSelect
? {
fixed: true,
columnWidth: SELECTION_COLUMN_WIDTH,
selectedRowKeys: selectedChannels.map(
(channel) => channel.key ?? String(channel.id),
),
+1 -28
View File
@@ -1,9 +1,7 @@
import { Plus as ActionPlus } from '@/components/common/icons/ActionIcons';
import React from 'react';
import { Tabs, TabPane, Tag } from '@/components/ui';
import { Button } from 'antd';
import { CHANNEL_OPTIONS } from '../../../constants';
import { getChannelIcon, isRoot } from '../../../helpers';
import { getChannelIcon } from '../../../helpers';
import './channels-tabs.css';
const ChannelsTabs = ({
@@ -13,35 +11,11 @@ const ChannelsTabs = ({
channelTypeCounts,
availableTypeKeys,
loadChannels,
activePage,
pageSize,
idSort,
setActivePage,
setEditingChannel,
setShowEdit,
t,
}) => {
const createButton = isRoot() ? (
<Button
className='console-create-action'
type='primary'
size='middle'
icon={<ActionPlus 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);
setActivePage(1);
@@ -54,7 +28,6 @@ const ChannelsTabs = ({
type='line'
onChange={handleTabChange}
className='channels-tabs mb-2'
tabBarExtraContent={createButton}
>
<TabPane
itemKey='all'
+26 -5
View File
@@ -1,4 +1,6 @@
import React from 'react';
import { Button } from 'antd';
import { Plus as ActionPlus } from '@/components/common/icons/ActionIcons';
import CardPro from '../../common/ui/CardPro';
import { ColumnSettingsButton } from '../../common/table/ColumnSettings';
import ChannelsTable from './ChannelsTable';
@@ -14,6 +16,7 @@ import EditChannelModal from './modals/EditChannelModal';
import EditTagModal from './modals/EditTagModal';
import MultiKeyManageModal from './modals/MultiKeyManageModal';
import { createCardProPagination } from '../../../helpers/utils';
import { isRoot } from '../../../helpers';
const ChannelsPage = () => {
const channelsData = useChannelsData();
@@ -49,14 +52,32 @@ const ChannelsPage = () => {
tableTitle={channelsData.t('渠道列表')}
tableActionsOffset
type='type3'
tabsArea={<ChannelsTabs {...channelsData} />}
tabsArea={
channelsData.enableTagMode ? null : <ChannelsTabs {...channelsData} />
}
actionsArea={<ChannelsActions {...channelsData} />}
searchArea={<ChannelsFilters {...channelsData} />}
tableActions={
<ColumnSettingsButton
open={channelsData.showColumnSelector}
onClick={() => channelsData.setShowColumnSelector(true)}
/>
<>
{isRoot() && (
<Button
className='console-create-action'
type='primary'
size='middle'
icon={<ActionPlus size={16} />}
onClick={() => {
channelsData.setEditingChannel({ id: undefined });
channelsData.setShowEdit(true);
}}
>
{channelsData.t('创建渠道')}
</Button>
)}
<ColumnSettingsButton
open={channelsData.showColumnSelector}
onClick={() => channelsData.setShowColumnSelector(true)}
/>
</>
}
paginationArea={createCardProPagination({
preservePage: true,
@@ -133,7 +133,7 @@ const originInputs = {
model_mapping: '',
status_code_mapping: '',
models: [],
auto_ban: 1,
auto_ban: true,
test_model: '',
groups: ['default'],
priority: 0,
@@ -195,7 +195,6 @@ const EditChannelModal = (props) => {
const [batch, setBatch] = useState(false);
const [multiToSingle, setMultiToSingle] = useState(false);
const [multiKeyMode, setMultiKeyMode] = useState('random');
const [autoBan, setAutoBan] = useState(true);
const [inputs, setInputs] = useState(originInputs);
const [originModelOptions, setOriginModelOptions] = useState([]);
const [modelOptions, setModelOptions] = useState([]);
@@ -552,7 +551,6 @@ const EditChannelModal = (props) => {
// 重置手动输入模式状态
setUseManualInput(false);
}
//setAutoBan
};
const loadChannel = async () => {
@@ -757,6 +755,7 @@ const EditChannelModal = (props) => {
if (!data.fallback_primary_attempts) data.fallback_primary_attempts = 1;
if (!data.fallback_hop_attempts) data.fallback_hop_attempts = 1;
data.auto_ban = Boolean(data.auto_ban ?? originInputs.auto_ban);
setInputs(data);
if (formApiRef.current) {
formApiRef.current.setValues(data);
@@ -768,11 +767,6 @@ const EditChannelModal = (props) => {
data.work_hours_timezone || 'Asia/Shanghai',
);
}
if (data.auto_ban === 0) {
setAutoBan(false);
} else {
setAutoBan(true);
}
// 同步企业账户状态
setIsEnterpriseAccount(data.is_enterprise_account || false);
setBasicModels(getChannelModels(data.type));
@@ -3192,11 +3186,9 @@ const EditChannelModal = (props) => {
label={t('是否自动禁用')}
checkedText={t('开')}
uncheckedText={t('关')}
onChange={(value) => setAutoBan(value)}
extraText={t(
'仅当自动禁用开启时有效,关闭后不会自动禁用该渠道',
)}
initValue={autoBan}
/>
<Form.TextArea
@@ -637,17 +637,10 @@ const EditTagModal = (props) => {
{t('不更改')}
</Text>
</div>
<div>
<Text type='tertiary' size='small'>
{t('支持变量:')}
</Text>
<div className='text-xs text-tertiary ml-2'>
<div>
{t('渠道密钥')}:{' '}
{I18N_TECHNICAL_TEXT.API_KEY_PLACEHOLDER}
</div>
</div>
</div>
<Text type='tertiary' size='small'>
{t('支持变量:')} {t('渠道密钥')}:{' '}
{I18N_TECHNICAL_TEXT.API_KEY_PLACEHOLDER}
</Text>
</div>
}
/>
@@ -346,50 +346,54 @@ const EditTokenModal = (props) => {
? -1
: Math.ceil(expireDate.getTime() / 1000);
if (isEdit) {
const localInputs = buildTokenPayload(values, expired_time);
let res = await API.put(`/api/token/`, {
...localInputs,
id: parseInt(props.editingToken.id),
});
const { success, message } = res.data;
if (success) {
showSuccess(t('密钥更新成功!'));
props.refresh();
props.handleClose();
} else {
showError(t(message));
}
} else {
const count = parseInt(values.tokenCount, 10) || 1;
let successCount = 0;
for (let i = 0; i < count; i++) {
try {
if (isEdit) {
const localInputs = buildTokenPayload(values, expired_time);
const baseName =
values.name.trim() === '' ? 'default' : values.name.trim();
if (i !== 0 || values.name.trim() === '') {
localInputs.name = `${baseName}-${generateRandomSuffix()}`;
} else {
localInputs.name = baseName;
}
let res = await API.post(`/api/token/`, localInputs);
let res = await API.put(`/api/token/`, {
...localInputs,
id: parseInt(props.editingToken.id),
});
const { success, message } = res.data;
if (success) {
successCount++;
showSuccess(t('密钥更新成功!'));
props.refresh();
props.handleClose();
} else {
showError(t(message));
break;
}
} else {
const count = parseInt(values.tokenCount, 10) || 1;
let successCount = 0;
for (let i = 0; i < count; i++) {
const localInputs = buildTokenPayload(values, expired_time);
const baseName =
values.name.trim() === '' ? 'default' : values.name.trim();
if (i !== 0 || values.name.trim() === '') {
localInputs.name = `${baseName}-${generateRandomSuffix()}`;
} else {
localInputs.name = baseName;
}
let res = await API.post(`/api/token/`, localInputs);
const { success, message } = res.data;
if (success) {
successCount++;
} else {
showError(t(message));
break;
}
}
if (successCount > 0) {
showSuccess(t('密钥创建成功,请在列表页面点击复制获取密钥!'));
props.onCreated?.(successCount);
props.refresh();
props.handleClose();
}
}
if (successCount > 0) {
showSuccess(t('密钥创建成功,请在列表页面点击复制获取密钥!'));
props.onCreated?.(successCount);
props.refresh();
props.handleClose();
}
} catch {
// The API client reports request failures.
} finally {
setLoading(false);
}
setLoading(false);
formApiRef.current?.setValues(getInitValues());
};
// 自定义标签组件
+7 -2
View File
@@ -11,7 +11,7 @@ import { isCenterTableScope, prepareCenterColumns } from './centerTablePolicy';
import './center-table.css';
const CenterTable = forwardRef(function CenterTable(
{ columns, className, scroll, style, ...props },
{ columns, className, scroll, style, minScrollableWidth, ...props },
ref,
) {
const { token } = theme.useToken();
@@ -33,7 +33,12 @@ const CenterTable = forwardRef(function CenterTable(
);
const prepared =
scoped && columns
? prepareCenterColumns(columns, width, measuredActionWidths)
? prepareCenterColumns(
columns,
width,
measuredActionWidths,
minScrollableWidth,
)
: columns;
const enabled = prepared !== columns;
useLayoutEffect(() => {
+28 -4
View File
@@ -91,10 +91,28 @@ const markFixedRight = (
.join(' '),
});
export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
export function prepareCenterColumns(
columns,
width = 0,
measuredWidths = {},
minScrollableWidth = 0,
) {
const leaves = leafColumns(columns);
const last = leaves.at(-1);
const hasAction = last && isActionColumn(last);
const fixedWidthLimit =
width > 0 ? Math.max(56, width - minScrollableWidth) : 0;
const otherFixedWidth = leaves.reduce(
(total, column) =>
column !== last && column.fixed ? total + columnWidth(column) : total,
0,
);
const remainingActionWidth = fixedWidthLimit - otherFixedWidth;
// Keep both sides fixed when wrapped action buttons still have enough space.
const actionWidthLimit =
minScrollableWidth > 0 && remainingActionWidth >= 120
? remainingActionWidth
: fixedWidthLimit;
const pinnedWidth = hasAction
? leaves.reduce(
(total, column, index) =>
@@ -102,7 +120,7 @@ export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
(column === last
? Math.min(
actionWidth(column, measuredWidths[index]),
width || Infinity,
actionWidthLimit || Infinity,
)
: column.fixed
? columnWidth(column)
@@ -110,7 +128,7 @@ export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
0,
)
: 0;
const releaseOtherFixed = width > 0 && pinnedWidth > width;
const releaseOtherFixed = width > 0 && pinnedWidth > fixedWidthLimit;
const estimatedTotal = leaves.reduce(
(total, column) => total + columnWidth(column),
0,
@@ -126,7 +144,13 @@ export function prepareCenterColumns(columns, width = 0, measuredWidths = {}) {
return { ...column, children: column.children.map(mapColumn) };
const columnIndex = index++;
if (hasAction && column === last)
return markFixedRight(column, columnIndex, true, measuredWidths, width);
return markFixedRight(
column,
columnIndex,
true,
measuredWidths,
actionWidthLimit,
);
if (fallback.has(column)) return markFixedRight(column, columnIndex);
if (releaseOtherFixed && column.fixed) {
const { fixed: _fixed, ...scrollable } = column;