fix(ui): 完善控制台列表并优化企业中心与个人操作
This commit is contained in:
@@ -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,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'
|
||||
|
||||
@@ -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());
|
||||
};
|
||||
|
||||
// 自定义标签组件
|
||||
|
||||
Reference in New Issue
Block a user