fix(ui): 统一三中心表格交互并优化企业及配套页面
- 公共表格:统一分组标签、状态开关和危险操作确认,支持防重复提交和失败重试,修复浮层触发组件的 ref 转发。 - 控制台:统一用户和渠道编辑抽屉,修正分组回填与提交格式,对齐系统设置操作区和预约列表。 - 企业中心:调整技能中心页签和窄屏布局,优化质量监控提示栏、效能分析及成本对账,统一消耗明细和审计日志筛选。 - 用户中心及公共页面:优化密钥和消费记录展示,对齐模型超市筛选,统一公开与内嵌客户端下载页。 - 同步多语言文案、组件规范与移动端视口要求。
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Modal } from '@/components/ui';
|
||||
|
||||
export default function TableActionModal({ onOk, ...props }) {
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const cancelButton = useRef(null);
|
||||
const pending = useRef(false);
|
||||
|
||||
const confirm = async () => {
|
||||
if (pending.current) return;
|
||||
pending.current = true;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
await onOk();
|
||||
} catch {
|
||||
// The request or page already reports the error.
|
||||
} finally {
|
||||
pending.current = false;
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
{...props}
|
||||
okType='danger'
|
||||
confirmLoading={submitting}
|
||||
onOk={confirm}
|
||||
onCancel={(event) => {
|
||||
if (!pending.current) props.onCancel(event);
|
||||
}}
|
||||
afterOpenChange={(visible) => {
|
||||
if (visible) cancelButton.current?.focus();
|
||||
}}
|
||||
cancelButtonProps={{ ref: cancelButton }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import { Popconfirm } from 'antd';
|
||||
|
||||
export default function TableActionPopconfirm({
|
||||
children,
|
||||
content,
|
||||
position,
|
||||
onConfirm,
|
||||
...props
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const cancelButton = useRef(null);
|
||||
const trigger = useRef(null);
|
||||
const pending = useRef(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
const confirm = (event) => {
|
||||
if (pending.current) return;
|
||||
pending.current = true;
|
||||
setSubmitting(true);
|
||||
void (async () => {
|
||||
try {
|
||||
if ((await onConfirm(event)) !== false) setOpen(false);
|
||||
} catch {
|
||||
// The request or page already reports the error.
|
||||
} finally {
|
||||
pending.current = false;
|
||||
setSubmitting(false);
|
||||
}
|
||||
})();
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
if (pending.current) return;
|
||||
setOpen(false);
|
||||
trigger.current?.focus();
|
||||
};
|
||||
|
||||
const handleKeyDown = (event) => {
|
||||
if (event.key === 'Escape') {
|
||||
event.stopPropagation();
|
||||
cancel();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Popconfirm
|
||||
{...props}
|
||||
open={open}
|
||||
description={content ?? props.description}
|
||||
placement={position ?? props.placement}
|
||||
onOpenChange={(nextOpen) => {
|
||||
if (pending.current) return;
|
||||
if (nextOpen) trigger.current = document.activeElement;
|
||||
setOpen(nextOpen);
|
||||
}}
|
||||
afterOpenChange={(visible) => {
|
||||
if (visible) cancelButton.current?.focus();
|
||||
}}
|
||||
onConfirm={confirm}
|
||||
onCancel={cancel}
|
||||
cancelButtonProps={{
|
||||
ref: cancelButton,
|
||||
disabled: submitting,
|
||||
onKeyDown: handleKeyDown,
|
||||
}}
|
||||
okButtonProps={{
|
||||
danger: true,
|
||||
loading: submitting,
|
||||
onKeyDown: handleKeyDown,
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Popconfirm>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
import React from 'react';
|
||||
import { Tag } from 'antd';
|
||||
import './table-group-tags.css';
|
||||
|
||||
export const TABLE_GROUP_COLUMN_WIDTH = 148;
|
||||
|
||||
const groupColors = new Map([
|
||||
['default', 'blue'],
|
||||
['svip', 'red'],
|
||||
['vip', 'yellow'],
|
||||
['premium', 'red'],
|
||||
['pro', 'yellow'],
|
||||
]);
|
||||
|
||||
const standardGroupNames = new Set(['default', 'vip', 'svip']);
|
||||
|
||||
function displayGroupName(group) {
|
||||
const name = group?.trim().toLowerCase();
|
||||
return standardGroupNames.has(name) ? name : group;
|
||||
}
|
||||
|
||||
export function TableGroupTag({ group, children, onClick }) {
|
||||
return (
|
||||
<Tag
|
||||
color={groupColors.get(group?.trim().toLowerCase()) ?? 'default'}
|
||||
variant='outlined'
|
||||
onClick={onClick}
|
||||
role={onClick ? 'button' : undefined}
|
||||
tabIndex={onClick ? 0 : undefined}
|
||||
onKeyDown={
|
||||
onClick
|
||||
? (event) => {
|
||||
if (event.key !== 'Enter' && event.key !== ' ') return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (!event.repeat) onClick(event);
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
className='m-0'
|
||||
>
|
||||
{children ?? displayGroupName(group)}
|
||||
</Tag>
|
||||
);
|
||||
}
|
||||
|
||||
export default function TableGroupTags({
|
||||
groups,
|
||||
empty = '-',
|
||||
renderLabel,
|
||||
onGroupClick,
|
||||
}) {
|
||||
const names = [
|
||||
...new Set(
|
||||
(Array.isArray(groups) ? groups : [groups])
|
||||
.flatMap((value) => (typeof value === 'string' ? value.split(',') : []))
|
||||
.map((name) => name.trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
];
|
||||
if (!names.length) return empty;
|
||||
|
||||
return (
|
||||
<span className='table-group-tags'>
|
||||
{names.map((name) => (
|
||||
<TableGroupTag
|
||||
key={name}
|
||||
group={name}
|
||||
onClick={
|
||||
onGroupClick ? (event) => onGroupClick(name, event) : undefined
|
||||
}
|
||||
>
|
||||
{standardGroupNames.has(name.toLowerCase())
|
||||
? displayGroupName(name)
|
||||
: renderLabel?.(name)}
|
||||
</TableGroupTag>
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import React, { forwardRef } from 'react';
|
||||
import { Switch } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export default forwardRef(function TableStatusSwitch(
|
||||
{ checkedChildren, unCheckedChildren, 'aria-label': ariaLabel, ...props },
|
||||
ref,
|
||||
) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Switch
|
||||
{...props}
|
||||
ref={ref}
|
||||
size='small'
|
||||
aria-label={ariaLabel ?? t('启用状态')}
|
||||
checkedChildren={checkedChildren ?? t('启用')}
|
||||
unCheckedChildren={unCheckedChildren ?? t('禁用')}
|
||||
/>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,44 @@
|
||||
import React, { useId, useState } from 'react';
|
||||
import { Card } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui';
|
||||
import { useIsMobile } from '../../../hooks/common/useIsMobile';
|
||||
import './usage-record-filter.css';
|
||||
|
||||
export function UsageRecordFilterContent({ children }) {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const id = useId();
|
||||
|
||||
return (
|
||||
<>
|
||||
{isMobile && (
|
||||
<Button
|
||||
block
|
||||
className='usage-record-mobile-toggle'
|
||||
aria-expanded={expanded}
|
||||
aria-controls={id}
|
||||
onClick={() => setExpanded((open) => !open)}
|
||||
>
|
||||
{expanded ? t('隐藏操作项') : t('显示操作项')}
|
||||
</Button>
|
||||
)}
|
||||
<div
|
||||
className='usage-record-filter-content'
|
||||
id={id}
|
||||
hidden={isMobile && !expanded}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function UsageRecordFilterCard({ children, className }) {
|
||||
return (
|
||||
<Card className={`usage-record-filter-card ${className}`}>
|
||||
<UsageRecordFilterContent>{children}</UsageRecordFilterContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Modal } from '@/components/ui';
|
||||
|
||||
export function confirmTableAction({ onOk, ...config }) {
|
||||
let submitting = false;
|
||||
const okButtonProps = { danger: true, ...config.okButtonProps };
|
||||
const dialog = Modal.confirm({
|
||||
...config,
|
||||
okButtonProps,
|
||||
onOk: (close) => {
|
||||
if (submitting) return;
|
||||
submitting = true;
|
||||
dialog.update({
|
||||
okButtonProps: { ...okButtonProps, loading: true },
|
||||
});
|
||||
void (async () => {
|
||||
try {
|
||||
if ((await onOk()) !== false) close();
|
||||
} catch {
|
||||
// The request or page already reports the error.
|
||||
} finally {
|
||||
submitting = false;
|
||||
dialog.update({
|
||||
okButtonProps: { ...okButtonProps, loading: false },
|
||||
});
|
||||
}
|
||||
})();
|
||||
},
|
||||
});
|
||||
return dialog;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
.table-group-tags {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
inline-size: 132px;
|
||||
max-inline-size: 100%;
|
||||
overflow-x: auto;
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.table-group-tags > * {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.table-group-tags .table-group-tags {
|
||||
inline-size: auto;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.table-group-tags > .ant-tag {
|
||||
margin-inline-end: 0;
|
||||
}
|
||||
|
||||
.table-group-tags > .ant-tag:focus-visible {
|
||||
outline-offset: -2px;
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
.usage-record-filter-card {
|
||||
--usage-record-filter-label: #6b7789;
|
||||
}
|
||||
html.dark .usage-record-filter-card {
|
||||
--usage-record-filter-label: var(--text-secondary);
|
||||
}
|
||||
.usage-record-filter-card.ant-card {
|
||||
background: var(--surface-card);
|
||||
}
|
||||
.usage-record-mobile-toggle {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
.usage-record-mobile-toggle[aria-expanded='true'] {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
/* 筛选:五列竖排标签表单,日期跨两列;重置/搜索右下 */
|
||||
:where(.usage-record-filter-card) .usage-record-filter-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr));
|
||||
column-gap: 16px;
|
||||
row-gap: 16px;
|
||||
}
|
||||
:where(.usage-record-filter-card)
|
||||
.usage-record-filter-grid
|
||||
.usage-record-filter-wide {
|
||||
grid-column: span 2;
|
||||
}
|
||||
:where(.usage-record-filter-card) .usage-record-filter-form .ant-form-item {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
:where(.usage-record-filter-card)
|
||||
.usage-record-filter-form
|
||||
.ant-form-item-label {
|
||||
padding-bottom: 8px;
|
||||
}
|
||||
:where(.usage-record-filter-card)
|
||||
.usage-record-filter-form
|
||||
.ant-form-item-label
|
||||
> label {
|
||||
height: 21px;
|
||||
color: var(--usage-record-filter-label);
|
||||
font-size: 13px;
|
||||
}
|
||||
:where(.usage-record-filter-card) .usage-record-filter-form .ant-picker,
|
||||
:where(.usage-record-filter-card) .usage-record-filter-form .ant-select {
|
||||
width: 100%;
|
||||
}
|
||||
:where(.usage-record-filter-card) .usage-record-filter-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
:where(.usage-record-filter-card) .usage-record-filter-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
:where(.usage-record-filter-card) .usage-record-filter-grid {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
:where(.usage-record-filter-card)
|
||||
.usage-record-filter-grid
|
||||
.usage-record-filter-wide {
|
||||
grid-column: auto;
|
||||
}
|
||||
:where(.usage-record-filter-card) .ant-picker-range {
|
||||
padding-inline: 8px;
|
||||
}
|
||||
:where(.usage-record-filter-card) .ant-picker-range-separator {
|
||||
padding-inline: 4px;
|
||||
}
|
||||
:where(.usage-record-filter-card)
|
||||
.ant-picker-range
|
||||
.ant-picker-input
|
||||
> input {
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,17 @@ import { Space, Tag, Typography, Popover } from '@/components/ui';
|
||||
const { Text } = Typography;
|
||||
|
||||
// 通用渲染函数:限制项目数量显示,支持popover展开
|
||||
export function renderLimitedItems({ items, renderItem, maxDisplay = 3 }) {
|
||||
export function renderLimitedItems({
|
||||
items,
|
||||
renderItem,
|
||||
maxDisplay = 3,
|
||||
wrap = true,
|
||||
}) {
|
||||
if (!items || items.length === 0) return '-';
|
||||
const displayItems = items.slice(0, maxDisplay);
|
||||
const remainingItems = items.slice(maxDisplay);
|
||||
return (
|
||||
<Space spacing={1} wrap>
|
||||
<Space spacing={wrap ? 1 : 4} wrap={wrap}>
|
||||
{displayItems.map((item, idx) => renderItem(item, idx))}
|
||||
{remainingItems.length > 0 && (
|
||||
<Popover
|
||||
|
||||
@@ -86,7 +86,8 @@
|
||||
}
|
||||
|
||||
.console-model-section,
|
||||
.console-channel-section {
|
||||
.console-channel-section,
|
||||
.console-user-section {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
@@ -94,12 +95,14 @@
|
||||
}
|
||||
|
||||
.console-model-section .ant-avatar,
|
||||
.console-channel-section .ant-avatar {
|
||||
.console-channel-section .ant-avatar,
|
||||
.console-user-section .ant-avatar {
|
||||
flex-shrink: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.console-channel-sections > div + div {
|
||||
.console-channel-sections > div + div,
|
||||
.console-user-sections > .ant-card + .ant-card {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
@@ -107,13 +110,13 @@
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.console-channel-section .ant-avatar svg {
|
||||
display: block;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
.console-user-section-description {
|
||||
color: var(--console-muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.console-channel-footer .ant-btn {
|
||||
.console-channel-footer .ant-btn,
|
||||
.console-user-footer .ant-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -133,7 +136,8 @@
|
||||
}
|
||||
|
||||
.console-overlay .console-model-footer,
|
||||
.console-overlay .console-channel-footer {
|
||||
.console-overlay .console-channel-footer,
|
||||
.console-overlay .console-user-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
@@ -153,7 +157,8 @@
|
||||
}
|
||||
}
|
||||
.console-model-drawer .console-model-editor-header .ant-drawer-title,
|
||||
.console-channel-drawer .console-channel-editor-header .ant-drawer-title {
|
||||
.console-channel-drawer .console-channel-editor-header .ant-drawer-title,
|
||||
.console-user-drawer .console-user-editor-header .ant-drawer-title {
|
||||
text-align: start;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import { Plus as ActionPlus } from '@/components/common/icons/ActionIcons';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import {
|
||||
@@ -6,7 +8,6 @@ import {
|
||||
Input,
|
||||
InputNumber,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Switch,
|
||||
Table,
|
||||
@@ -146,6 +147,7 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
load();
|
||||
} catch (e) {
|
||||
Toast.error(saveErrorText(e));
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,8 +175,7 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
dataIndex: 'enabled',
|
||||
width: 70,
|
||||
render: (v, rule) => (
|
||||
<Switch
|
||||
size='small'
|
||||
<TableStatusSwitch
|
||||
checked={v}
|
||||
onChange={(checked) => toggle(rule, checked)}
|
||||
/>
|
||||
@@ -220,14 +221,14 @@ const QualityAlerts = ({ quality, t }) => {
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确定删除该告警规则?')}
|
||||
onConfirm={() => remove(rule)}
|
||||
>
|
||||
<Button size='small' theme='borderless' type='danger'>
|
||||
<Button size='small' type='link' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -196,7 +196,7 @@ const QualityBreakdown = ({ quality, t }) => {
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
className={`quality-card-body quality-nested-tabs${isPlatform ? ' quality-breakdown-body' : ''}`}
|
||||
className={`quality-card-body quality-nested-tabs ${isPlatform ? 'quality-breakdown-body' : 'quality-breakdown-org-body'}`}
|
||||
>
|
||||
<Tabs type='button' size='small' activeKey={dim} onChange={setDim}>
|
||||
{dims.map((d) => (
|
||||
@@ -215,7 +215,7 @@ const QualityBreakdown = ({ quality, t }) => {
|
||||
className={
|
||||
isPlatform
|
||||
? 'quality-breakdown-result'
|
||||
: 'overflow-x-auto app-scrollbar mt-2'
|
||||
: 'overflow-x-auto app-scrollbar'
|
||||
}
|
||||
>
|
||||
<Table
|
||||
|
||||
@@ -70,7 +70,14 @@
|
||||
padding-block-start: 12px;
|
||||
}
|
||||
|
||||
.quality-breakdown-body .ant-tabs > .ant-tabs-nav {
|
||||
.quality-breakdown-org-body {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: var(--uc-layout-gap);
|
||||
}
|
||||
|
||||
.quality-breakdown-body .ant-tabs > .ant-tabs-nav,
|
||||
.quality-breakdown-org-body .ant-tabs > .ant-tabs-nav {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
@@ -214,6 +221,16 @@
|
||||
border-color: color-mix(in srgb, var(--ui-color-primary) 22%, transparent);
|
||||
}
|
||||
|
||||
.quality-breakdown-org-body .quality-notice {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.quality-breakdown-org-body .quality-notice > svg {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.quality-grid-2 {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import TableGroupTags, {
|
||||
TABLE_GROUP_COLUMN_WIDTH,
|
||||
} from '@/components/common/table/TableGroupTags';
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
import { formatIdReference } from '../../helpers/safeDisplay';
|
||||
import { TestTube2 as ActionTestTube2 } from '@/components/common/icons/ActionIcons';
|
||||
@@ -327,7 +330,12 @@ export default function ContentGuardSetting() {
|
||||
render: (v) => new Date(v).toLocaleString(),
|
||||
},
|
||||
{ title: t('用户'), dataIndex: 'user_id', width: 80 },
|
||||
{ title: t('分组'), dataIndex: 'using_group' },
|
||||
{
|
||||
title: t('分组'),
|
||||
dataIndex: 'using_group',
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (groups) => <TableGroupTags groups={groups} />,
|
||||
},
|
||||
{ title: t('模型'), dataIndex: 'model' },
|
||||
{ title: t('方向'), dataIndex: 'direction' },
|
||||
{ title: t('类型'), dataIndex: 'content_type' },
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import {
|
||||
RefreshCw as ActionRefreshCw,
|
||||
Plus as ActionPlus,
|
||||
@@ -13,7 +14,6 @@ import {
|
||||
Select,
|
||||
Tag,
|
||||
Avatar,
|
||||
Popconfirm,
|
||||
Typography,
|
||||
Space,
|
||||
Banner,
|
||||
@@ -178,12 +178,14 @@ const CustomerServiceSetting = () => {
|
||||
if (res.data.success) {
|
||||
showSuccess(t('删除成功'));
|
||||
fetchAgents();
|
||||
return true;
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(t('删除失败'));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 切换状态
|
||||
@@ -301,7 +303,7 @@ const CustomerServiceSetting = () => {
|
||||
<Button onClick={() => openModal(record)} type='link' size='small'>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确认删除')}
|
||||
content={t('确定要删除这个客服吗?')}
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
@@ -309,7 +311,7 @@ const CustomerServiceSetting = () => {
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import { I18N_TECHNICAL_TEXT } from '../../i18n/technicalText.js';
|
||||
import { useEffectEvent } from '../../hooks/common/useEffectEvent';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
@@ -317,9 +318,11 @@ export default function DataSecuritySetting() {
|
||||
showSuccess(res.data?.message || t('删除成功'));
|
||||
loadOrgConfigs();
|
||||
loadChangeRequests(); // 开启二级审批时会进入待审批队列
|
||||
return true;
|
||||
} else {
|
||||
showError(res.data?.message || t('删除失败'));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const toggleKillSwitch = async (action) => {
|
||||
const res = await API.post('/api/desensitize/killswitch', {
|
||||
@@ -438,9 +441,11 @@ export default function DataSecuritySetting() {
|
||||
showSuccess(res.data?.message || t('删除成功'));
|
||||
loadRules();
|
||||
loadChangeRequests();
|
||||
return true;
|
||||
} else {
|
||||
showError(res.data?.message || t('删除失败'));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// ---- 审批 ----
|
||||
@@ -496,14 +501,14 @@ export default function DataSecuritySetting() {
|
||||
<Button onClick={() => openEditRule(rule)} type='link' size='small'>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确认删除该规则?')}
|
||||
onConfirm={() => deleteRule(rule)}
|
||||
>
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@@ -859,7 +864,7 @@ export default function DataSecuritySetting() {
|
||||
{
|
||||
title: t('操作'),
|
||||
render: (_, rule) => (
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t(
|
||||
'确认紧急删除该企业私有规则?将同步记入该企业的变更留痕。',
|
||||
)}
|
||||
@@ -868,7 +873,7 @@ export default function DataSecuritySetting() {
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
),
|
||||
},
|
||||
]}
|
||||
@@ -1181,14 +1186,14 @@ export default function DataSecuritySetting() {
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确认删除该企业覆盖(回到继承全局)?')}
|
||||
onConfirm={() => deleteOrgConfig(row.org_id)}
|
||||
>
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import { TableGroupTag } from '@/components/common/table/TableGroupTags';
|
||||
import { Trans } from 'react-i18next';
|
||||
import { Eraser as ActionEraser } from '@/components/common/icons/ActionIcons';
|
||||
import {
|
||||
@@ -25,7 +28,6 @@ import {
|
||||
Tooltip,
|
||||
Divider,
|
||||
Empty,
|
||||
Switch,
|
||||
} from '@/components/ui';
|
||||
import { Search } from 'lucide-react';
|
||||
import { API, showError, showSuccess } from '../../helpers';
|
||||
@@ -745,6 +747,7 @@ const LevelPolicySetting = () => {
|
||||
showSuccess(t('删除成功'));
|
||||
}
|
||||
await fetchAll();
|
||||
return true;
|
||||
} else {
|
||||
const d = res?.data?.data || {};
|
||||
const refs = [];
|
||||
@@ -770,6 +773,7 @@ const LevelPolicySetting = () => {
|
||||
} finally {
|
||||
setDeletingCode('');
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const saveDefaults = async () => {
|
||||
@@ -859,9 +863,9 @@ const LevelPolicySetting = () => {
|
||||
const tags = (
|
||||
<Space>
|
||||
{preview.map((g) => (
|
||||
<Tag key={g} color='light-blue'>
|
||||
<TableGroupTag key={g} group={g}>
|
||||
{g} ×{d[g]}
|
||||
</Tag>
|
||||
</TableGroupTag>
|
||||
))}
|
||||
{rest > 0 && (
|
||||
<Tag color='light-blue' type='ghost'>
|
||||
@@ -953,9 +957,7 @@ const LevelPolicySetting = () => {
|
||||
>
|
||||
<Space>
|
||||
{preview.map((g) => (
|
||||
<Tag key={g} color='red' type='ghost'>
|
||||
{g}
|
||||
</Tag>
|
||||
<TableGroupTag key={g} group={g} />
|
||||
))}
|
||||
{rest > 0 && (
|
||||
<Tag color='red' type='ghost'>
|
||||
@@ -988,7 +990,7 @@ const LevelPolicySetting = () => {
|
||||
{t('复制')}
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确认删除该等级?')}
|
||||
content={t('被用户/企业/默认等级引用时会被拒绝')}
|
||||
onConfirm={() => deleteLevel(type, r.code)}
|
||||
@@ -1001,7 +1003,7 @@ const LevelPolicySetting = () => {
|
||||
>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
@@ -1419,7 +1421,7 @@ const LevelPolicySetting = () => {
|
||||
dataIndex: 'model',
|
||||
render: (v, r) => (
|
||||
<Space>
|
||||
<span>{v}</span>
|
||||
<TableGroupTag group={v} />
|
||||
{r.maybeDisabled && (
|
||||
<Tooltip
|
||||
content={t(
|
||||
@@ -1532,7 +1534,7 @@ const LevelPolicySetting = () => {
|
||||
dataIndex: 'group',
|
||||
render: (v, r) => (
|
||||
<Space>
|
||||
<span>{v}</span>
|
||||
<TableGroupTag group={v} />
|
||||
{r.stale && (
|
||||
<Tooltip
|
||||
content={t(
|
||||
@@ -1554,9 +1556,11 @@ const LevelPolicySetting = () => {
|
||||
// 已废弃分组只允许关闭存量隐藏条目:后端对新增隐藏做存在性校验必拒,
|
||||
// 放开开关会造成一次注定失败的保存。
|
||||
render: (v, r) => (
|
||||
<Switch
|
||||
size='small'
|
||||
<TableStatusSwitch
|
||||
checked={!!v}
|
||||
checkedChildren={t('是')}
|
||||
unCheckedChildren={t('否')}
|
||||
aria-label={t('对该等级隐藏')}
|
||||
disabled={r.stale && !v}
|
||||
onChange={(checked) => setGroupHidden(r.group, checked)}
|
||||
/>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import { useEffectEvent } from '../../hooks/common/useEffectEvent';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -8,8 +10,6 @@ import {
|
||||
Modal,
|
||||
Form,
|
||||
Toast,
|
||||
Popconfirm,
|
||||
Switch,
|
||||
Tag,
|
||||
Progress,
|
||||
Empty,
|
||||
@@ -154,6 +154,7 @@ const TutorialVideoSetting = () => {
|
||||
if (res.data.success) {
|
||||
Toast.success(t('删除成功'));
|
||||
loadVideos();
|
||||
return true;
|
||||
} else {
|
||||
Toast.error(res.data.message || t('删除失败'));
|
||||
}
|
||||
@@ -161,6 +162,7 @@ const TutorialVideoSetting = () => {
|
||||
console.error('Delete error:', error);
|
||||
Toast.error(t('删除失败'));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 切换状态
|
||||
@@ -231,11 +233,9 @@ const TutorialVideoSetting = () => {
|
||||
dataIndex: 'status',
|
||||
width: 80,
|
||||
render: (status, record) => (
|
||||
<Switch
|
||||
<TableStatusSwitch
|
||||
checked={status === 1}
|
||||
onChange={() => handleToggleStatus(record)}
|
||||
checkedText={t('启用')}
|
||||
uncheckedText={t('禁用')}
|
||||
/>
|
||||
),
|
||||
},
|
||||
@@ -254,7 +254,7 @@ const TutorialVideoSetting = () => {
|
||||
<Button onClick={() => handleEdit(record)} type='link' size='small'>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确定删除这个视频吗?')}
|
||||
content={t('删除后将无法恢复')}
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
@@ -262,7 +262,7 @@ const TutorialVideoSetting = () => {
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Empty, Popconfirm, Space, Tag, Typography } from 'antd';
|
||||
import { Button, Empty, Space, Tag, Typography } from 'antd';
|
||||
import { Table } from '@/components/ui';
|
||||
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
|
||||
import { Plus } from '../common/icons/ActionIcons';
|
||||
@@ -143,10 +144,9 @@ const ProfileTable = ({ mode, orgId, canWrite = true, emptyHint }) => {
|
||||
<Button type='link' size='small' onClick={() => setEditing(r)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确认删除该集合?')}
|
||||
description={t('使用该虚拟模型名的请求将返回"模型不存在"。')}
|
||||
okButtonProps={{ danger: true }}
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
await deleteProfile(mode, orgId, r.id);
|
||||
@@ -154,13 +154,14 @@ const ProfileTable = ({ mode, orgId, canWrite = true, emptyHint }) => {
|
||||
load();
|
||||
} catch (e) {
|
||||
if (e?.message) showError(e.message);
|
||||
return false;
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Button type='link' size='small' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</>
|
||||
)}
|
||||
</Space>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import React from 'react';
|
||||
import { Button, Switch, Tag as AntTag } from 'antd';
|
||||
import { Button, Tag as AntTag } from 'antd';
|
||||
import { Tag, Typography, Popover } from '@/components/ui';
|
||||
import {
|
||||
renderGroup,
|
||||
@@ -21,11 +23,8 @@ const renderStatus = (status, record, t, showEnableDisableModal) => {
|
||||
(![1, 2].includes(status) ? { color: 'error', label: '未知状态' } : null);
|
||||
return (
|
||||
<div className='admin-tokens-status'>
|
||||
<Switch
|
||||
size='small'
|
||||
<TableStatusSwitch
|
||||
checked={status === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
aria-label={status === 1 ? t('禁用') : t('启用')}
|
||||
disabled={!isAdmin() || Boolean(record.DeletedAt)}
|
||||
onChange={() =>
|
||||
@@ -194,7 +193,7 @@ export const getAdminTokensColumns = ({
|
||||
{
|
||||
title: t('分组'),
|
||||
dataIndex: 'group',
|
||||
width: 110,
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (text) => <div>{renderGroup(text)}</div>,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -82,8 +82,7 @@ const AdminTokensPage = () => {
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!modalToken) return;
|
||||
await manageToken(modalToken.id, 'delete');
|
||||
setShowDelete(false);
|
||||
if (await manageToken(modalToken.id, 'delete')) setShowDelete(false);
|
||||
};
|
||||
|
||||
const handleEditConfirm = async () => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import TableActionModal from '@/components/common/table/TableActionModal';
|
||||
import React from 'react';
|
||||
import { Modal, Typography, Banner } from '@/components/ui';
|
||||
import { Typography, Banner } from '@/components/ui';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -8,7 +9,7 @@ const AdminDeleteTokenModal = ({ visible, onCancel, onConfirm, token, t }) => {
|
||||
const isOrgToken = token.organization_id > 0;
|
||||
|
||||
return (
|
||||
<Modal
|
||||
<TableActionModal
|
||||
title={t('确定要删除此密钥吗?')}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
@@ -37,7 +38,7 @@ const AdminDeleteTokenModal = ({ visible, onCancel, onConfirm, token, t }) => {
|
||||
{token.user_id})
|
||||
</Text>
|
||||
</div>
|
||||
</Modal>
|
||||
</TableActionModal>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import { toGroupList } from '@/helpers/groupList';
|
||||
import { confirmTableAction } from '@/components/common/table/confirmTableAction';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import { writeClipboardText } from '../../../helpers/clipboard';
|
||||
import React, { useState } from 'react';
|
||||
import { Switch } from 'antd';
|
||||
import {
|
||||
Button,
|
||||
InputNumber,
|
||||
@@ -34,11 +37,8 @@ const formatDisplayPercent = (value, digits = 0) => {
|
||||
function ChannelStatusSwitch({ record, manageChannel, t }) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
return (
|
||||
<Switch
|
||||
size='small'
|
||||
<TableStatusSwitch
|
||||
checked={record.status === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
disabled={!isRoot()}
|
||||
loading={loading}
|
||||
aria-label={t('状态')}
|
||||
@@ -405,20 +405,16 @@ export const getChannelsColumns = ({
|
||||
key: COLUMN_KEYS.GROUP,
|
||||
title: t('分组'),
|
||||
dataIndex: 'group',
|
||||
render: (text, record, index) => (
|
||||
<div>
|
||||
<Space spacing={2}>
|
||||
{text
|
||||
?.split(',')
|
||||
.sort((a, b) => {
|
||||
if (a === 'default') return -1;
|
||||
if (b === 'default') return 1;
|
||||
return a.localeCompare(b);
|
||||
})
|
||||
.map((item, index) => renderGroup(item))}
|
||||
</Space>
|
||||
</div>
|
||||
),
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (groups) =>
|
||||
renderGroup(
|
||||
toGroupList(groups).sort((left, right) => {
|
||||
if (left === right) return 0;
|
||||
if (left === 'default') return -1;
|
||||
if (right === 'default') return 1;
|
||||
return left.localeCompare(right);
|
||||
}),
|
||||
),
|
||||
},
|
||||
{
|
||||
key: COLUMN_KEYS.TYPE,
|
||||
@@ -723,19 +719,20 @@ export const getChannelsColumns = ({
|
||||
type: 'danger',
|
||||
onClick: async () => {
|
||||
const content = await buildDeleteConfirmContent(record.id, t);
|
||||
Modal.confirm({
|
||||
confirmTableAction({
|
||||
title: t('确定是否要删除此渠道?'),
|
||||
content,
|
||||
onOk: () => {
|
||||
(async () => {
|
||||
await manageChannel(record.id, 'delete', record);
|
||||
await refresh();
|
||||
setTimeout(() => {
|
||||
if (channels.length === 0 && activePage > 1) {
|
||||
refresh(activePage - 1);
|
||||
}
|
||||
}, 100);
|
||||
})();
|
||||
okType: 'danger',
|
||||
focusable: { autoFocusButton: 'cancel' },
|
||||
onOk: async () => {
|
||||
if (!(await manageChannel(record.id, 'delete', record)))
|
||||
return false;
|
||||
await refresh();
|
||||
setTimeout(() => {
|
||||
if (channels.length === 0 && activePage > 1) {
|
||||
refresh(activePage - 1);
|
||||
}
|
||||
}, 100);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { toGroupList } from '@/helpers/groupList';
|
||||
import { formatIdReference } from '../../../../helpers/safeDisplay';
|
||||
|
||||
import { I18N_TECHNICAL_TEXT } from '../../../../i18n/technicalText.js';
|
||||
@@ -46,13 +47,7 @@ import SecureVerificationModal from '../../../common/modals/SecureVerificationMo
|
||||
import ChannelKeyDisplay from '../../../common/ui/ChannelKeyDisplay';
|
||||
import { useSecureVerification } from '../../../../hooks/common/useSecureVerification';
|
||||
import { createApiCalls } from '../../../../services/secureVerification';
|
||||
import {
|
||||
IconServer,
|
||||
IconSetting,
|
||||
IconCode,
|
||||
IconGlobe,
|
||||
IconBolt,
|
||||
} from '@/components/ui/icons';
|
||||
import { Code, Globe, Server, Settings, Zap } from 'lucide-react';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -573,11 +568,7 @@ const EditChannelModal = (props) => {
|
||||
} else {
|
||||
data.models = data.models.split(',');
|
||||
}
|
||||
if (data.group === '') {
|
||||
data.groups = [];
|
||||
} else {
|
||||
data.groups = data.group.split(',');
|
||||
}
|
||||
data.groups = toGroupList(data.group);
|
||||
if (data.model_mapping !== '') {
|
||||
data.model_mapping = JSON.stringify(
|
||||
JSON.parse(data.model_mapping),
|
||||
@@ -1575,7 +1566,7 @@ const EditChannelModal = (props) => {
|
||||
let res;
|
||||
localInputs.auto_ban = localInputs.auto_ban ? 1 : 0;
|
||||
localInputs.models = localInputs.models.join(',');
|
||||
localInputs.group = (localInputs.groups || []).join(',');
|
||||
localInputs.group = toGroupList(localInputs.groups).join(',');
|
||||
|
||||
// 日消耗限额统一使用 token(quota)单位,确保为整数
|
||||
if (localInputs.daily_quota_limit && localInputs.daily_quota_limit > 0) {
|
||||
@@ -1921,7 +1912,7 @@ const EditChannelModal = (props) => {
|
||||
{/* Header: Basic Info */}
|
||||
<div className='console-channel-section'>
|
||||
<Avatar size='small' color='blue'>
|
||||
<IconServer size={16} />
|
||||
<Server size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
@@ -2462,7 +2453,7 @@ const EditChannelModal = (props) => {
|
||||
onClick={handleApiConfigSecretClick}
|
||||
>
|
||||
<Avatar size='small' color='green'>
|
||||
<IconGlobe size={16} />
|
||||
<Globe size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
@@ -2683,7 +2674,7 @@ const EditChannelModal = (props) => {
|
||||
{/* Header: Model Config */}
|
||||
<div className='console-channel-section'>
|
||||
<Avatar size='small' color='purple'>
|
||||
<IconCode size={16} />
|
||||
<Code size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
@@ -2888,7 +2879,7 @@ const EditChannelModal = (props) => {
|
||||
{/* Header: Advanced Settings */}
|
||||
<div className='console-channel-section'>
|
||||
<Avatar size='small' color='orange'>
|
||||
<IconSetting size={16} />
|
||||
<Settings size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
@@ -3433,7 +3424,7 @@ const EditChannelModal = (props) => {
|
||||
{/* Header: Channel Extra Settings */}
|
||||
<div className='console-channel-section'>
|
||||
<Avatar size='small' color='violet'>
|
||||
<IconBolt size={16} />
|
||||
<Zap size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { toGroupList } from '@/helpers/groupList';
|
||||
import { I18N_TECHNICAL_TEXT } from '../../../../i18n/technicalText.js';
|
||||
import { useEffectEvent } from '../../../../hooks/common/useEffectEvent';
|
||||
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
|
||||
import '../../../console/module-alignment.css';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import {
|
||||
API,
|
||||
@@ -18,29 +21,43 @@ import {
|
||||
Spin,
|
||||
Banner,
|
||||
Card,
|
||||
Tag,
|
||||
Avatar,
|
||||
Form,
|
||||
Row,
|
||||
Col,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
IconSave,
|
||||
IconClose,
|
||||
IconBookmark,
|
||||
IconUser,
|
||||
IconCode,
|
||||
IconSetting,
|
||||
} from '@/components/ui/icons';
|
||||
import { Bookmark, Code, Settings } from 'lucide-react';
|
||||
import { getChannelModels } from '../../../../helpers';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
const { Text } = Typography;
|
||||
|
||||
const MODEL_MAPPING_EXAMPLE = {
|
||||
'gpt-3.5-turbo': 'gpt-3.5-turbo-0125',
|
||||
};
|
||||
|
||||
function TagEditorSection({ icon, color, title, description, children }) {
|
||||
return (
|
||||
<div>
|
||||
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
|
||||
<div className='console-channel-section'>
|
||||
<Avatar size='small' color={color}>
|
||||
{icon}
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>{title}</Text>
|
||||
<div className='text-xs text-gray-600'>{description}</div>
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const EditTagModal = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const { visible, tag, handleClose, refresh } = props;
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [originModelOptions, setOriginModelOptions] = useState([]);
|
||||
@@ -159,6 +176,7 @@ const EditTagModal = (props) => {
|
||||
};
|
||||
|
||||
const handleSave = async (values) => {
|
||||
if (loading) return;
|
||||
setLoading(true);
|
||||
const formVals = values || formApiRef.current?.getValues() || {};
|
||||
let data = { tag };
|
||||
@@ -170,8 +188,9 @@ const EditTagModal = (props) => {
|
||||
}
|
||||
data.model_mapping = formVals.model_mapping;
|
||||
}
|
||||
if (formVals.groups && formVals.groups.length > 0) {
|
||||
data.groups = formVals.groups.join(',');
|
||||
const groups = toGroupList(formVals.groups);
|
||||
if (groups.length > 0) {
|
||||
data.groups = groups.join(',');
|
||||
}
|
||||
if (formVals.models && formVals.models.length > 0) {
|
||||
data.models = formVals.models.join(',');
|
||||
@@ -234,6 +253,8 @@ const EditTagModal = (props) => {
|
||||
showSuccess(t('标签更新成功!'));
|
||||
refresh();
|
||||
handleClose();
|
||||
} else if (res?.data) {
|
||||
showError(res.data.message || t('操作失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -254,6 +275,10 @@ const EditTagModal = (props) => {
|
||||
}, [originModelOptions, inputs.models]);
|
||||
|
||||
const onVisibilityChange = useEffectEvent(() => {
|
||||
if (visible) {
|
||||
setCustomModel('');
|
||||
formApiRef.current?.setValue('custom_model', '');
|
||||
}
|
||||
const fetchTagModels = async () => {
|
||||
if (!tag) return;
|
||||
setLoading(true);
|
||||
@@ -319,6 +344,7 @@ const EditTagModal = (props) => {
|
||||
|
||||
setModelOptions(localModelOptions);
|
||||
setCustomModel('');
|
||||
formApiRef.current?.setValue('custom_model', '');
|
||||
handleInputChange('models', localModels);
|
||||
|
||||
if (addedModels.length > 0) {
|
||||
@@ -335,44 +361,27 @@ const EditTagModal = (props) => {
|
||||
|
||||
return (
|
||||
<SideSheet
|
||||
rootClassName='console-channel-drawer'
|
||||
classNames={{ header: 'console-channel-editor-header' }}
|
||||
placement='right'
|
||||
title={
|
||||
<Space>
|
||||
<Tag color='blue' shape='circle'>
|
||||
{t('编辑')}
|
||||
</Tag>
|
||||
<Title heading={4} className='m-0'>
|
||||
{t('编辑标签')}
|
||||
</Title>
|
||||
</Space>
|
||||
}
|
||||
title={t('编辑标签')}
|
||||
bodyStyle={{ padding: '0' }}
|
||||
visible={visible}
|
||||
width={600}
|
||||
width={isMobile ? '100%' : 600}
|
||||
onCancel={handleClose}
|
||||
footer={
|
||||
<div className='flex justify-end'>
|
||||
<Space>
|
||||
<Button
|
||||
theme='solid'
|
||||
onClick={() => formApiRef.current?.submitForm()}
|
||||
loading={loading}
|
||||
icon={<IconSave />}
|
||||
>
|
||||
{t('保存')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='light'
|
||||
type='primary'
|
||||
onClick={handleClose}
|
||||
icon={<IconClose />}
|
||||
>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
</Space>
|
||||
<div className='console-channel-footer'>
|
||||
<Button onClick={handleClose}>{t('取消')}</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
onClick={() => formApiRef.current?.submitForm()}
|
||||
loading={loading}
|
||||
>
|
||||
{t('提交')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
closeIcon={null}
|
||||
>
|
||||
<Form
|
||||
key={tag || 'edit'}
|
||||
@@ -382,110 +391,238 @@ const EditTagModal = (props) => {
|
||||
>
|
||||
{() => (
|
||||
<Spin spinning={loading}>
|
||||
<div className='p-2'>
|
||||
<Card className='!rounded-2xl shadow-sm border-0 mb-6'>
|
||||
{/* Header: Tag Info */}
|
||||
<div className='flex items-center mb-2'>
|
||||
<Avatar size='small' color='blue' className='mr-2 shadow-md'>
|
||||
<IconBookmark size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>{t('标签信息')}</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('标签的基本配置')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='console-channel-sections p-2'>
|
||||
<TagEditorSection
|
||||
icon={<Bookmark size={16} />}
|
||||
color='blue'
|
||||
title={t('标签信息')}
|
||||
description={t('标签的基本配置')}
|
||||
>
|
||||
<Banner
|
||||
type='warning'
|
||||
description={t('所有编辑均为覆盖操作,留空则不更改')}
|
||||
className='!rounded-lg mb-4'
|
||||
/>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<Form.Input
|
||||
field='new_tag'
|
||||
label={t('标签名称')}
|
||||
placeholder={t('请输入新标签,留空则解散标签')}
|
||||
onChange={(value) => handleInputChange('new_tag', value)}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
<Row gutter={12}>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Input
|
||||
field='new_tag'
|
||||
label={t('标签名称')}
|
||||
placeholder={t('请输入新标签,留空则解散标签')}
|
||||
showClear
|
||||
onChange={(value) => handleInputChange('new_tag', value)}
|
||||
/>
|
||||
</Col>
|
||||
<Col xs={24} md={12}>
|
||||
<Form.Select
|
||||
field='groups'
|
||||
label={t('分组')}
|
||||
placeholder={t(
|
||||
'请选择可以使用该渠道的分组,留空则不更改',
|
||||
)}
|
||||
multiple
|
||||
allowAdditions
|
||||
additionLabel={t(
|
||||
'请在系统设置页面编辑分组倍率以添加新的分组:',
|
||||
)}
|
||||
optionList={groupOptions}
|
||||
style={{ width: '100%' }}
|
||||
onChange={(value) => handleInputChange('groups', value)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</TagEditorSection>
|
||||
|
||||
<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'
|
||||
>
|
||||
<IconCode size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>{t('模型配置')}</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('模型选择和映射设置')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<TagEditorSection
|
||||
icon={<Code size={16} />}
|
||||
color='purple'
|
||||
title={t('模型配置')}
|
||||
description={t('模型选择和映射设置')}
|
||||
>
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。',
|
||||
)}
|
||||
className='!rounded-lg mb-4'
|
||||
/>
|
||||
<Form.Select
|
||||
field='models'
|
||||
label={t('模型')}
|
||||
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
|
||||
multiple
|
||||
filter={selectFilter}
|
||||
autoClearSearchValue={false}
|
||||
searchPosition='dropdown'
|
||||
optionList={modelOptions}
|
||||
style={{ width: '100%' }}
|
||||
onChange={(value) => handleInputChange('models', value)}
|
||||
/>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<Banner
|
||||
type='info'
|
||||
description={t(
|
||||
'当前模型列表为该标签下所有渠道模型列表最长的一个,并非所有渠道的并集,请注意可能导致某些渠道模型丢失。',
|
||||
)}
|
||||
className='!rounded-lg mb-4'
|
||||
/>
|
||||
<Form.Select
|
||||
field='models'
|
||||
label={t('模型')}
|
||||
placeholder={t('请选择该渠道所支持的模型,留空则不更改')}
|
||||
multiple
|
||||
filter={selectFilter}
|
||||
autoClearSearchValue={false}
|
||||
searchPosition='dropdown'
|
||||
optionList={modelOptions}
|
||||
style={{ width: '100%' }}
|
||||
onChange={(value) => handleInputChange('models', value)}
|
||||
/>
|
||||
<Form.Input
|
||||
field='custom_model'
|
||||
label={t('自定义模型名称')}
|
||||
placeholder={t('输入自定义模型名称')}
|
||||
onChange={(value) => setCustomModel(value.trim())}
|
||||
value={customModel}
|
||||
suffix={
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
onClick={addCustomModels}
|
||||
>
|
||||
{t('填入')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
|
||||
<Form.Input
|
||||
field='custom_model'
|
||||
label={t('自定义模型名称')}
|
||||
placeholder={t('输入自定义模型名称')}
|
||||
onChange={(value) => setCustomModel(value.trim())}
|
||||
suffix={
|
||||
<Button
|
||||
size='small'
|
||||
type='primary'
|
||||
onClick={addCustomModels}
|
||||
<Form.TextArea
|
||||
field='model_mapping'
|
||||
label={t('模型重定向')}
|
||||
placeholder={t(
|
||||
'此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,留空则不更改',
|
||||
)}
|
||||
autosize
|
||||
onChange={(value) =>
|
||||
handleInputChange('model_mapping', value)
|
||||
}
|
||||
extraText={
|
||||
<Space>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'model_mapping',
|
||||
JSON.stringify(MODEL_MAPPING_EXAMPLE, null, 2),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('填入')}
|
||||
</Button>
|
||||
}
|
||||
/>
|
||||
{t('填入模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'model_mapping',
|
||||
JSON.stringify({}, null, 2),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('清空重定向')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() => handleInputChange('model_mapping', '')}
|
||||
>
|
||||
{t('不更改')}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</TagEditorSection>
|
||||
|
||||
<Form.TextArea
|
||||
field='model_mapping'
|
||||
label={t('模型重定向')}
|
||||
placeholder={t(
|
||||
'此项可选,用于修改请求体中的模型名称,为一个 JSON 字符串,键为请求中模型名称,值为要替换的模型名称,留空则不更改',
|
||||
)}
|
||||
autosize
|
||||
onChange={(value) =>
|
||||
handleInputChange('model_mapping', value)
|
||||
}
|
||||
extraText={
|
||||
<Space>
|
||||
<TagEditorSection
|
||||
icon={<Settings size={16} />}
|
||||
color='orange'
|
||||
title={t('高级设置')}
|
||||
description={t('渠道的高级配置选项')}
|
||||
>
|
||||
<Form.TextArea
|
||||
field='param_override'
|
||||
label={t('参数覆盖')}
|
||||
placeholder={t(
|
||||
'此项可选,用于覆盖请求参数。不支持覆盖 stream 参数\n旧格式(直接覆盖):\n{\n "temperature": 0,\n "max_tokens": 1000\n}\n\n新格式(支持条件判断与json自定义):\n{\n "operations": [\n {\n "path": "temperature",\n "mode": "set",\n "value": 0.7,\n "conditions": [\n {\n "path": "model",\n "mode": "prefix",\n "value": "gpt"\n }\n ]\n }\n ]\n}',
|
||||
)}
|
||||
autosize
|
||||
showClear
|
||||
onChange={(value) =>
|
||||
handleInputChange('param_override', value)
|
||||
}
|
||||
extraText={
|
||||
<div className='flex gap-2 flex-wrap'>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'param_override',
|
||||
JSON.stringify({ temperature: 0 }, null, 2),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('旧格式模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'param_override',
|
||||
JSON.stringify(
|
||||
{
|
||||
operations: [
|
||||
{
|
||||
path: 'temperature',
|
||||
mode: 'set',
|
||||
value: 0.7,
|
||||
conditions: [
|
||||
{
|
||||
path: 'model',
|
||||
mode: 'prefix',
|
||||
value: 'gpt',
|
||||
},
|
||||
],
|
||||
logic: 'AND',
|
||||
},
|
||||
],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('新格式模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange('param_override', null)
|
||||
}
|
||||
>
|
||||
{t('不更改')}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='header_override'
|
||||
label={t('请求头覆盖')}
|
||||
placeholder={t(
|
||||
'此项可选,用于覆盖请求头参数\n格式示例:\n{\n "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0",\n "Authorization": "Bearer {api_key}"\n}',
|
||||
)}
|
||||
autosize
|
||||
showClear
|
||||
onChange={(value) =>
|
||||
handleInputChange('header_override', value)
|
||||
}
|
||||
extraText={
|
||||
<div className='flex flex-col gap-1'>
|
||||
<div className='flex gap-2 flex-wrap items-center'>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'model_mapping',
|
||||
JSON.stringify(MODEL_MAPPING_EXAMPLE, null, 2),
|
||||
'header_override',
|
||||
JSON.stringify(
|
||||
{
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0',
|
||||
Authorization: 'Bearer {api_key}',
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
@@ -494,201 +631,27 @@ const EditTagModal = (props) => {
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'model_mapping',
|
||||
JSON.stringify({}, null, 2),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('清空重定向')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() => handleInputChange('model_mapping', '')}
|
||||
>
|
||||
{t('不更改')}
|
||||
</Text>
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<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'
|
||||
>
|
||||
<IconSetting size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>{t('高级设置')}</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('渠道的高级配置选项')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<Form.TextArea
|
||||
field='param_override'
|
||||
label={t('参数覆盖')}
|
||||
placeholder={t(
|
||||
'此项可选,用于覆盖请求参数。不支持覆盖 stream 参数\n旧格式(直接覆盖):\n{\n "temperature": 0,\n "max_tokens": 1000\n}\n\n新格式(支持条件判断与json自定义):\n{\n "operations": [\n {\n "path": "temperature",\n "mode": "set",\n "value": 0.7,\n "conditions": [\n {\n "path": "model",\n "mode": "prefix",\n "value": "gpt"\n }\n ]\n }\n ]\n}',
|
||||
)}
|
||||
autosize
|
||||
showClear
|
||||
onChange={(value) =>
|
||||
handleInputChange('param_override', value)
|
||||
}
|
||||
extraText={
|
||||
<div className='flex gap-2 flex-wrap'>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'param_override',
|
||||
JSON.stringify({ temperature: 0 }, null, 2),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('旧格式模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'param_override',
|
||||
JSON.stringify(
|
||||
{
|
||||
operations: [
|
||||
{
|
||||
path: 'temperature',
|
||||
mode: 'set',
|
||||
value: 0.7,
|
||||
conditions: [
|
||||
{
|
||||
path: 'model',
|
||||
mode: 'prefix',
|
||||
value: 'gpt',
|
||||
},
|
||||
],
|
||||
logic: 'AND',
|
||||
},
|
||||
],
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('新格式模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange('param_override', null)
|
||||
handleInputChange('header_override', null)
|
||||
}
|
||||
>
|
||||
{t('不更改')}
|
||||
</Text>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
<Form.TextArea
|
||||
field='header_override'
|
||||
label={t('请求头覆盖')}
|
||||
placeholder={t(
|
||||
'此项可选,用于覆盖请求头参数\n格式示例:\n{\n "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0",\n "Authorization": "Bearer {api_key}"\n}',
|
||||
)}
|
||||
autosize
|
||||
showClear
|
||||
onChange={(value) =>
|
||||
handleInputChange('header_override', value)
|
||||
}
|
||||
extraText={
|
||||
<div className='flex flex-col gap-1'>
|
||||
<div className='flex gap-2 flex-wrap items-center'>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange(
|
||||
'header_override',
|
||||
JSON.stringify(
|
||||
{
|
||||
'User-Agent':
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36 Edg/139.0.0.0',
|
||||
Authorization: 'Bearer {api_key}',
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
)
|
||||
}
|
||||
>
|
||||
{t('填入模板')}
|
||||
</Text>
|
||||
<Text
|
||||
className='!text-ui-color-primary cursor-pointer'
|
||||
onClick={() =>
|
||||
handleInputChange('header_override', null)
|
||||
}
|
||||
>
|
||||
{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>
|
||||
<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>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card className='!rounded-2xl shadow-sm border-0'>
|
||||
{/* Header: Group Settings */}
|
||||
<div className='flex items-center mb-2'>
|
||||
<Avatar size='small' color='green' className='mr-2 shadow-md'>
|
||||
<IconUser size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>{t('分组设置')}</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
{t('用户分组配置')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='space-y-4'>
|
||||
<Form.Select
|
||||
field='groups'
|
||||
label={t('分组')}
|
||||
placeholder={t('请选择可以使用该渠道的分组,留空则不更改')}
|
||||
multiple
|
||||
allowAdditions
|
||||
additionLabel={t(
|
||||
'请在系统设置页面编辑分组倍率以添加新的分组:',
|
||||
)}
|
||||
optionList={groupOptions}
|
||||
style={{ width: '100%' }}
|
||||
onChange={(value) => handleInputChange('groups', value)}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
}
|
||||
/>
|
||||
</TagEditorSection>
|
||||
</div>
|
||||
</Spin>
|
||||
)}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import { formatIdReference } from '../../../../helpers/safeDisplay';
|
||||
|
||||
import { useEffectEvent } from '../../../../hooks/common/useEffectEvent';
|
||||
@@ -247,6 +248,7 @@ const MultiKeyManageModal = ({ visible, onCancel, channel, onRefresh }) => {
|
||||
showSuccess(t('密钥已删除'));
|
||||
await loadKeyStatus(currentPage, pageSize); // Reload current page
|
||||
onRefresh && onRefresh(); // Refresh parent component
|
||||
return true;
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
@@ -255,6 +257,7 @@ const MultiKeyManageModal = ({ visible, onCancel, channel, onRefresh }) => {
|
||||
} finally {
|
||||
setOperationLoading((prev) => ({ ...prev, [operationId]: false }));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// Handle page size change
|
||||
@@ -414,21 +417,21 @@ const MultiKeyManageModal = ({ visible, onCancel, channel, onRefresh }) => {
|
||||
{t('启用')}
|
||||
</Button>
|
||||
)}
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确定要删除此密钥吗?')}
|
||||
content={t('此操作不可撤销,将永久删除该密钥')}
|
||||
onConfirm={() => handleDeleteKey(record.index)}
|
||||
okType={'danger'}
|
||||
position={'topRight'}
|
||||
>
|
||||
<Button
|
||||
type='danger'
|
||||
type='link'
|
||||
danger
|
||||
size='small'
|
||||
loading={operationLoading[`delete_${record.index}`]}
|
||||
>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -39,7 +39,7 @@ const PricingVendors = ({
|
||||
...vendorsList.map((vendor) => ({
|
||||
value: vendor.name,
|
||||
label: vendor.name,
|
||||
icon: vendor.icon ? getLobeHubIcon(vendor.icon, 18) : null,
|
||||
icon: vendor.icon ? getLobeHubIcon(vendor.icon, 16) : null,
|
||||
})),
|
||||
];
|
||||
}, [vendorsMap, availableVendorNames, t]);
|
||||
|
||||
@@ -338,6 +338,9 @@ html.dark .mm-theme {
|
||||
}
|
||||
|
||||
.mm-filter-group .ant-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: auto;
|
||||
min-height: 28px;
|
||||
padding: 3px 9px;
|
||||
@@ -348,6 +351,7 @@ html.dark .mm-theme {
|
||||
max-width: 100%;
|
||||
box-shadow: none;
|
||||
line-height: 1.45;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.mm-filter-group .ant-btn.mm-selected {
|
||||
@@ -400,6 +404,17 @@ html.dark .mm-theme {
|
||||
padding: var(--mm-filter-logo-padding);
|
||||
}
|
||||
|
||||
.mm-filter-group .mm-logo :is(svg, img) {
|
||||
display: block;
|
||||
max-width: 16px;
|
||||
max-height: 16px;
|
||||
}
|
||||
|
||||
.mm-filter-group .mm-logo + span {
|
||||
position: relative;
|
||||
top: 1px;
|
||||
}
|
||||
|
||||
html.dark .mm-filter-group .mm-logo {
|
||||
color: var(--mm-filter-logo-ink);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React from 'react';
|
||||
import TableGroupTags from '@/components/common/table/TableGroupTags';
|
||||
import { Empty, Table, Tag, Tooltip } from 'antd';
|
||||
import { ChevronRight } from 'lucide-react';
|
||||
import {
|
||||
@@ -111,7 +112,7 @@ const ModelPricingTable = ({
|
||||
</span>
|
||||
) : (
|
||||
<span className='mm-detail-group'>
|
||||
{row.group}
|
||||
<TableGroupTags groups={row.group} />
|
||||
{row.discountText && (
|
||||
<Tooltip
|
||||
title={t(
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import { confirmTableAction } from '@/components/common/table/confirmTableAction';
|
||||
import { Copy as ActionCopy } from '@/components/common/icons/ActionIcons';
|
||||
import React from 'react';
|
||||
import { Button as AntButton, Tooltip as AntTooltip } from 'antd';
|
||||
import { Button, Space, Tag, Modal, Tooltip } from '@/components/ui';
|
||||
import { Button, Space, Tag, Tooltip } from '@/components/ui';
|
||||
import {
|
||||
timestamp2string,
|
||||
getLobeHubIcon,
|
||||
@@ -94,12 +96,17 @@ const renderCategories = (categories, t, categoryNames) => {
|
||||
// Render groups (enable_groups)
|
||||
const renderGroups = (groups) => {
|
||||
if (!groups || groups.length === 0) return '-';
|
||||
return renderLimitedItems({
|
||||
items: groups,
|
||||
renderItem: (g, idx) => (
|
||||
<React.Fragment key={idx}>{renderGroup(g)}</React.Fragment>
|
||||
),
|
||||
});
|
||||
return (
|
||||
<span className='table-group-tags'>
|
||||
{renderLimitedItems({
|
||||
items: groups,
|
||||
renderItem: (group, index) => (
|
||||
<React.Fragment key={index}>{renderGroup(group)}</React.Fragment>
|
||||
),
|
||||
wrap: false,
|
||||
})}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
// Render tags
|
||||
@@ -261,14 +268,15 @@ const renderOperations = (
|
||||
danger
|
||||
size='small'
|
||||
onClick={() => {
|
||||
Modal.confirm({
|
||||
confirmTableAction({
|
||||
title: t('确定是否要删除此模型?'),
|
||||
content: t('此修改将不可逆'),
|
||||
onOk: () => {
|
||||
(async () => {
|
||||
await manageModel(record.id, 'delete', record);
|
||||
await refresh();
|
||||
})();
|
||||
okType: 'danger',
|
||||
focusable: { autoFocusButton: 'cancel' },
|
||||
onOk: async () => {
|
||||
if (!(await manageModel(record.id, 'delete', record)))
|
||||
return false;
|
||||
await refresh();
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -407,6 +415,7 @@ export const getModelsColumns = ({
|
||||
{
|
||||
title: t('可用分组'),
|
||||
dataIndex: 'enable_groups',
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: renderGroups,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import TableActionPopconfirm from '@/components/common/table/TableActionPopconfirm';
|
||||
import '../../../console/module-alignment.css';
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
@@ -6,7 +7,6 @@ import {
|
||||
Typography,
|
||||
Space,
|
||||
Tag,
|
||||
Popconfirm,
|
||||
Card,
|
||||
Avatar,
|
||||
Spin,
|
||||
@@ -71,12 +71,14 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
|
||||
if (res.data.success) {
|
||||
showSuccess(t('删除成功'));
|
||||
loadGroups();
|
||||
return true;
|
||||
} else {
|
||||
showError(res.data.message || t('删除失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
showError(t('删除失败'));
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// 编辑组
|
||||
@@ -184,14 +186,14 @@ const PrefillGroupManagement = ({ visible, onClose }) => {
|
||||
<Button type='link' size='small' onClick={() => handleEdit(record)}>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
<TableActionPopconfirm
|
||||
title={t('确定删除此组?')}
|
||||
onConfirm={() => deleteGroup(record.id)}
|
||||
>
|
||||
<Button size='small' type='link' danger>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</TableActionPopconfirm>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import TableActionModal from '@/components/common/table/TableActionModal';
|
||||
import React from 'react';
|
||||
import { Modal } from '@/components/ui';
|
||||
import { REDEMPTION_ACTIONS } from '../../../../constants/redemption.constants';
|
||||
|
||||
const DeleteRedemptionModal = ({
|
||||
@@ -13,7 +13,8 @@ const DeleteRedemptionModal = ({
|
||||
t,
|
||||
}) => {
|
||||
const handleConfirm = async () => {
|
||||
await manageRedemption(record.id, REDEMPTION_ACTIONS.DELETE, record);
|
||||
if (!(await manageRedemption(record.id, REDEMPTION_ACTIONS.DELETE, record)))
|
||||
return;
|
||||
await refresh();
|
||||
setTimeout(() => {
|
||||
if (redemptions.length === 0 && activePage > 1) {
|
||||
@@ -24,7 +25,7 @@ const DeleteRedemptionModal = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
<TableActionModal
|
||||
title={t('确定是否要删除此兑换码?')}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
@@ -32,7 +33,7 @@ const DeleteRedemptionModal = ({
|
||||
type='warning'
|
||||
>
|
||||
{t('此修改将不可逆')}
|
||||
</Modal>
|
||||
</TableActionModal>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -132,6 +132,14 @@ const CustomTag = ({
|
||||
);
|
||||
};
|
||||
|
||||
const getTaskChannelColorKey = (value) => {
|
||||
const idNum = parseInt(value);
|
||||
const colorIndex = Number.isFinite(idNum)
|
||||
? ((idNum % colors.length) + colors.length) % colors.length
|
||||
: 0;
|
||||
return colors[colorIndex];
|
||||
};
|
||||
|
||||
// Render functions
|
||||
const renderTimestamp = (timestampInSeconds) => {
|
||||
const date = new Date(timestampInSeconds * 1000);
|
||||
@@ -417,11 +425,7 @@ export const getTaskLogsColumns = ({
|
||||
render: (text, record, index) => {
|
||||
if (!isAdminUser) return null;
|
||||
|
||||
const idNum = parseInt(text);
|
||||
const colorIndex = Number.isFinite(idNum)
|
||||
? ((idNum % colors.length) + colors.length) % colors.length
|
||||
: 0;
|
||||
const colorKey = colors[colorIndex];
|
||||
const colorKey = getTaskChannelColorKey(text);
|
||||
|
||||
// 若后端返回 channel_name 则在 Tooltip 中显示名称,便于管理员快速识别;否则回落为 ID
|
||||
const tooltipContent = record.channel_name || text;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Download as ActionDownload } from '@/components/common/icons/ActionIcons';
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import UsageRecordFilterCard from '../../common/table/UsageRecordFilterCard';
|
||||
import { Card, Tag as AntTag } from 'antd';
|
||||
import { Clock } from 'lucide-react';
|
||||
import { Button, Pagination } from '@/components/ui';
|
||||
@@ -31,8 +32,6 @@ const TaskLogsPage = ({
|
||||
sharedFilterRevision,
|
||||
});
|
||||
const isMobile = useIsMobile();
|
||||
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
|
||||
const [showMobileFilters, setShowMobileFilters] = useState(false);
|
||||
const pageStats = useTaskPageStats(taskLogsData.logs);
|
||||
|
||||
if (usageRecordMode) {
|
||||
@@ -53,20 +52,9 @@ const TaskLogsPage = ({
|
||||
<div className='usage-record-panels'>
|
||||
<TaskLogsActions {...taskLogsData} usageRecordMode />
|
||||
|
||||
<Card className='usage-record-card usage-record-filter-card'>
|
||||
{isMobile && (
|
||||
<Button
|
||||
block
|
||||
className='usage-record-mobile-toggle'
|
||||
onClick={() => setShowMobileFilters(!showMobileFilters)}
|
||||
>
|
||||
{showMobileFilters ? t('隐藏操作项') : t('显示操作项')}
|
||||
</Button>
|
||||
)}
|
||||
<div hidden={isMobile && !showMobileFilters}>
|
||||
<TaskLogsFilters {...taskLogsData} usageRecordMode />
|
||||
</div>
|
||||
</Card>
|
||||
<UsageRecordFilterCard className='usage-record-card'>
|
||||
<TaskLogsFilters {...taskLogsData} usageRecordMode />
|
||||
</UsageRecordFilterCard>
|
||||
|
||||
<Card className='usage-record-card usage-record-table-card'>
|
||||
<div className='usage-record-table-head'>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import { confirmTableAction } from '@/components/common/table/confirmTableAction';
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
@@ -12,7 +14,6 @@ import {
|
||||
Popover,
|
||||
Typography,
|
||||
Input,
|
||||
Modal,
|
||||
} from '@/components/ui';
|
||||
import {
|
||||
timestamp2string,
|
||||
@@ -387,14 +388,15 @@ const renderOperations = (
|
||||
type='danger'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
Modal.confirm({
|
||||
confirmTableAction({
|
||||
title: t('确定是否要删除此密钥?'),
|
||||
content: t('此修改将不可逆'),
|
||||
onOk: () => {
|
||||
(async () => {
|
||||
await manageToken(record.id, 'delete', record);
|
||||
await refresh();
|
||||
})();
|
||||
okType: 'danger',
|
||||
focusable: { autoFocusButton: 'cancel' },
|
||||
onOk: async () => {
|
||||
if (!(await manageToken(record.id, 'delete', record)))
|
||||
return false;
|
||||
await refresh();
|
||||
},
|
||||
});
|
||||
}}
|
||||
@@ -436,6 +438,7 @@ export const getTokensColumns = ({
|
||||
title: t('分组'),
|
||||
dataIndex: 'group',
|
||||
key: 'group',
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (text) => renderGroupColumn(text, t),
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import React from 'react';
|
||||
import { Tag as AntTag } from 'antd';
|
||||
import {
|
||||
@@ -20,24 +21,6 @@ import {
|
||||
import { IconHelpCircle } from '@/components/ui/icons';
|
||||
import { Route } from 'lucide-react';
|
||||
|
||||
const colors = [
|
||||
'amber',
|
||||
'blue',
|
||||
'cyan',
|
||||
'green',
|
||||
'grey',
|
||||
'indigo',
|
||||
'light-blue',
|
||||
'lime',
|
||||
'orange',
|
||||
'pink',
|
||||
'purple',
|
||||
'red',
|
||||
'teal',
|
||||
'violet',
|
||||
'yellow',
|
||||
];
|
||||
|
||||
// 类型配置映射
|
||||
const TYPE_CONFIG = {
|
||||
1: {
|
||||
@@ -256,7 +239,7 @@ const RECORD_COLUMN_WIDTHS = {
|
||||
channel: 85,
|
||||
username: 120,
|
||||
token: 120,
|
||||
group: 148,
|
||||
group: TABLE_GROUP_COLUMN_WIDTH,
|
||||
type: 110,
|
||||
model: 225,
|
||||
use_time: 190,
|
||||
@@ -455,20 +438,21 @@ export const getLogsColumns = ({
|
||||
return isAdminUser &&
|
||||
(record.type === 0 || record.type === 2 || record.type === 5) ? (
|
||||
<Space>
|
||||
<Tooltip content={record.channel_name || t('未知渠道')}>
|
||||
<span>
|
||||
<Tag
|
||||
color={colors[parseInt(text) % colors.length]}
|
||||
shape='circle'
|
||||
>
|
||||
<Tooltip content={record.channel_name || text}>
|
||||
<button
|
||||
type='button'
|
||||
className='usage-record-copy-text'
|
||||
onClick={(event) => copyText(event, text)}
|
||||
>
|
||||
<AntTag variant='filled' className='usage-record-channel-tag'>
|
||||
{text}
|
||||
</Tag>
|
||||
</span>
|
||||
</AntTag>
|
||||
</button>
|
||||
</Tooltip>
|
||||
{isMultiKey && (
|
||||
<Tag color='white' shape='circle'>
|
||||
<AntTag variant='filled' className='usage-record-channel-tag'>
|
||||
{multiKeyIndex}
|
||||
</Tag>
|
||||
</AntTag>
|
||||
)}
|
||||
</Space>
|
||||
) : null;
|
||||
@@ -528,6 +512,7 @@ export const getLogsColumns = ({
|
||||
key: COLUMN_KEYS.GROUP,
|
||||
title: t('分组'),
|
||||
dataIndex: 'group',
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (text, record, index) => {
|
||||
if (record.type === 0 || record.type === 2 || record.type === 5) {
|
||||
if (record.group) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Download as ActionDownload } from '@/components/common/icons/ActionIcons';
|
||||
import React, { useState } from 'react';
|
||||
import React from 'react';
|
||||
import UsageRecordFilterCard from '../../common/table/UsageRecordFilterCard';
|
||||
import { Card } from 'antd';
|
||||
import { Button, Pagination } from '@/components/ui';
|
||||
import CardPro from '../../common/ui/CardPro';
|
||||
@@ -18,8 +19,6 @@ import './UsageLogs.css';
|
||||
const LogsPage = ({ usageRecordMode = false }) => {
|
||||
const logsData = useLogsData();
|
||||
const isMobile = useIsMobile();
|
||||
// 与 CardPro 一致:移动端默认收起筛选区,仅视图状态
|
||||
const [showMobileFilters, setShowMobileFilters] = useState(false);
|
||||
|
||||
if (usageRecordMode) {
|
||||
const { t } = logsData;
|
||||
@@ -30,20 +29,9 @@ const LogsPage = ({ usageRecordMode = false }) => {
|
||||
<UsageLogsExportModal {...logsData} usageRecordMode />
|
||||
|
||||
<div className='usage-record-panels'>
|
||||
<Card className='usage-record-card usage-record-filter-card'>
|
||||
{isMobile && (
|
||||
<Button
|
||||
block
|
||||
className='usage-record-mobile-toggle'
|
||||
onClick={() => setShowMobileFilters(!showMobileFilters)}
|
||||
>
|
||||
{showMobileFilters ? t('隐藏操作项') : t('显示操作项')}
|
||||
</Button>
|
||||
)}
|
||||
<div hidden={isMobile && !showMobileFilters}>
|
||||
<LogsFilters {...logsData} usageRecordMode />
|
||||
</div>
|
||||
</Card>
|
||||
<UsageRecordFilterCard className='usage-record-card'>
|
||||
<LogsFilters {...logsData} usageRecordMode />
|
||||
</UsageRecordFilterCard>
|
||||
|
||||
<Card className='usage-record-card usage-record-table-card usage-record-consume-card'>
|
||||
<div className='usage-record-table-head'>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { TABLE_GROUP_COLUMN_WIDTH } from '@/components/common/table/TableGroupTags';
|
||||
import TableStatusSwitch from '@/components/common/table/TableStatusSwitch';
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
@@ -8,7 +10,6 @@ import {
|
||||
Popover,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import { Switch } from 'antd';
|
||||
import { TableRowActions } from '@/components/common/table/TableToolbar';
|
||||
import {
|
||||
renderGroup,
|
||||
@@ -106,11 +107,8 @@ const renderStatistics = (text, record, showEnableDisableModal, t) => {
|
||||
const content = isDeleted ? (
|
||||
<Tag color='red'>{t('已注销')}</Tag>
|
||||
) : (
|
||||
<Switch
|
||||
size='small'
|
||||
<TableStatusSwitch
|
||||
checked={record.status === 1}
|
||||
checkedChildren={t('启用')}
|
||||
unCheckedChildren={t('禁用')}
|
||||
aria-label={t('状态')}
|
||||
disabled={!canManage}
|
||||
onChange={(checked, event) => {
|
||||
@@ -344,6 +342,7 @@ export const getUsersColumns = ({
|
||||
{
|
||||
title: t('分组'),
|
||||
dataIndex: 'group',
|
||||
width: TABLE_GROUP_COLUMN_WIDTH,
|
||||
render: (text, record, index) => {
|
||||
return <div>{renderGroup(text)}</div>;
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import TableActionModal from '@/components/common/table/TableActionModal';
|
||||
import React from 'react';
|
||||
import { Modal } from '@/components/ui';
|
||||
|
||||
const DeleteUserModal = ({
|
||||
visible,
|
||||
@@ -13,7 +13,7 @@ const DeleteUserModal = ({
|
||||
t,
|
||||
}) => {
|
||||
const handleConfirm = async () => {
|
||||
await manageUser(user.id, 'delete', user);
|
||||
if (!(await manageUser(user.id, 'delete', user))) return;
|
||||
await refresh();
|
||||
setTimeout(() => {
|
||||
if (users.length === 0 && activePage > 1) {
|
||||
@@ -24,7 +24,7 @@ const DeleteUserModal = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
<TableActionModal
|
||||
title={t('确定是否要注销此用户?')}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
@@ -32,7 +32,7 @@ const DeleteUserModal = ({
|
||||
type='danger'
|
||||
>
|
||||
{t('相当于删除用户,此修改将不可逆')}
|
||||
</Modal>
|
||||
</TableActionModal>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
Button,
|
||||
Modal,
|
||||
SideSheet,
|
||||
Space,
|
||||
Spin,
|
||||
Typography,
|
||||
Card,
|
||||
@@ -18,11 +17,13 @@ import {
|
||||
} from '@/components/ui';
|
||||
import QuotaInput, { FormQuotaInput } from '../../../common/ui/QuotaInput';
|
||||
import {
|
||||
IconUser,
|
||||
IconLink,
|
||||
IconUserGroup,
|
||||
IconPlus,
|
||||
} from '@/components/ui/icons';
|
||||
User as ActionUser,
|
||||
Link as ActionLink,
|
||||
Users as ActionUsers,
|
||||
Plus as ActionPlus,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
|
||||
import { toGroupList } from '@/helpers/groupList';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
@@ -30,6 +31,9 @@ const EditUserModal = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const userId = props.editingUser.id;
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [loadedUserId, setLoadedUserId] = useState(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const pending = useRef(false);
|
||||
const [addQuotaModalOpen, setIsModalOpen] = useState(false);
|
||||
const [addQuotaLocal, setAddQuotaLocal] = useState('');
|
||||
const isMobile = useIsMobile();
|
||||
@@ -38,6 +42,7 @@ const EditUserModal = (props) => {
|
||||
const formApiRef = useRef(null);
|
||||
|
||||
const isEdit = Boolean(userId);
|
||||
const ready = loadedUserId === (userId ?? false);
|
||||
|
||||
const getInitValues = () => ({
|
||||
username: '',
|
||||
@@ -50,7 +55,7 @@ const EditUserModal = (props) => {
|
||||
telegram_id: '',
|
||||
email: '',
|
||||
quota: 0,
|
||||
group: 'default',
|
||||
group: userId ? ['default'] : 'default',
|
||||
level: '',
|
||||
remark: '',
|
||||
});
|
||||
@@ -88,53 +93,83 @@ const EditUserModal = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleCancel = () => props.handleClose();
|
||||
|
||||
const loadUser = async () => {
|
||||
setLoading(true);
|
||||
const url = userId ? `/api/user/${userId}` : `/api/user/self`;
|
||||
const res = await API.get(url);
|
||||
const { success, message, data } = res.data;
|
||||
if (success) {
|
||||
data.password = '';
|
||||
formApiRef.current?.setValues({ ...getInitValues(), ...data });
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
setLoading(false);
|
||||
const handleCancel = () => {
|
||||
if (pending.current) return;
|
||||
setIsModalOpen(false);
|
||||
setAddQuotaLocal('');
|
||||
props.handleClose();
|
||||
};
|
||||
|
||||
const onScopeChange = useEffectEvent(() => {
|
||||
loadUser();
|
||||
const onScopeChange = useEffectEvent(async (isCurrent) => {
|
||||
setLoading(true);
|
||||
setLoadedUserId(null);
|
||||
const url = userId ? `/api/user/${userId}` : '/api/user/self';
|
||||
if (userId) {
|
||||
fetchGroups();
|
||||
fetchLevels();
|
||||
}
|
||||
try {
|
||||
const { data: response } = await API.get(url);
|
||||
if (!isCurrent()) return;
|
||||
if (response.success) {
|
||||
formApiRef.current?.setValues({
|
||||
...getInitValues(),
|
||||
...response.data,
|
||||
...(userId && {
|
||||
group: toGroupList(response.data.group ?? 'default'),
|
||||
}),
|
||||
password: '',
|
||||
});
|
||||
setLoadedUserId(userId ?? false);
|
||||
} else {
|
||||
showError(response.message);
|
||||
}
|
||||
} catch {
|
||||
// The API client reports request failures.
|
||||
} finally {
|
||||
if (isCurrent()) setLoading(false);
|
||||
}
|
||||
});
|
||||
useEffect(() => onScopeChange(), [onScopeChange, props.editingUser.id]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.visible) return;
|
||||
let current = true;
|
||||
onScopeChange(() => current);
|
||||
return () => {
|
||||
current = false;
|
||||
};
|
||||
}, [onScopeChange, props.visible, userId]);
|
||||
|
||||
/* ----------------------- submit ----------------------- */
|
||||
const submit = async (values) => {
|
||||
setLoading(true);
|
||||
let payload = { ...values };
|
||||
if (typeof payload.quota === 'string')
|
||||
payload.quota = parseInt(payload.quota) || 0;
|
||||
if (typeof payload.gift_quota === 'string')
|
||||
payload.gift_quota = parseInt(payload.gift_quota) || 0;
|
||||
if (userId) {
|
||||
payload.id = parseInt(userId);
|
||||
if (!ready || pending.current) return;
|
||||
pending.current = true;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const payload = { ...values };
|
||||
if (typeof payload.quota === 'string')
|
||||
payload.quota = parseInt(payload.quota) || 0;
|
||||
if (typeof payload.gift_quota === 'string')
|
||||
payload.gift_quota = parseInt(payload.gift_quota) || 0;
|
||||
if (userId) {
|
||||
payload.id = parseInt(userId);
|
||||
payload.group = toGroupList(values.group).join(',');
|
||||
}
|
||||
const url = userId ? '/api/user/' : '/api/user/self';
|
||||
const { data } = await API.put(url, payload);
|
||||
if (data.success) {
|
||||
showSuccess(t('用户信息更新成功!'));
|
||||
props.refresh();
|
||||
props.handleClose();
|
||||
} else {
|
||||
showError(data.message);
|
||||
}
|
||||
} catch {
|
||||
// The API client reports request failures.
|
||||
} finally {
|
||||
pending.current = false;
|
||||
setSubmitting(false);
|
||||
}
|
||||
const url = userId ? `/api/user/` : `/api/user/self`;
|
||||
const res = await API.put(url, payload);
|
||||
const { success, message } = res.data;
|
||||
if (success) {
|
||||
showSuccess(t('用户信息更新成功!'));
|
||||
props.refresh();
|
||||
props.handleClose();
|
||||
} else {
|
||||
showError(message);
|
||||
}
|
||||
setLoading(false);
|
||||
};
|
||||
|
||||
/* --------------------- quota helper -------------------- */
|
||||
@@ -149,50 +184,49 @@ const EditUserModal = (props) => {
|
||||
<>
|
||||
<SideSheet
|
||||
placement='right'
|
||||
classNames={{ header: 'console-detail-header' }}
|
||||
rootClassName='console-user-drawer'
|
||||
classNames={{ header: 'console-user-editor-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()}
|
||||
loading={loading}
|
||||
>
|
||||
{t('确定')}
|
||||
</Button>
|
||||
</Space>
|
||||
<div className='console-user-footer'>
|
||||
<Button onClick={handleCancel} disabled={submitting}>
|
||||
{t('取消')}
|
||||
</Button>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
disabled={!ready || loading}
|
||||
loading={submitting}
|
||||
onClick={() => formApiRef.current?.submitForm()}
|
||||
>
|
||||
{t('提交')}
|
||||
</Button>
|
||||
</div>
|
||||
}
|
||||
onCancel={handleCancel}
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
initValues={getInitValues()}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
onSubmit={submit}
|
||||
>
|
||||
{({ values }) => (
|
||||
<div className='p-2'>
|
||||
<Form
|
||||
initValues={getInitValues()}
|
||||
getFormApi={(api) => (formApiRef.current = api)}
|
||||
onSubmit={submit}
|
||||
>
|
||||
{() => (
|
||||
<Spin spinning={loading}>
|
||||
<div className='console-user-sections 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'
|
||||
>
|
||||
<IconUser size={16} />
|
||||
<Card className='rounded-2xl shadow-sm'>
|
||||
<div className='console-user-section'>
|
||||
<Avatar size='small' color='blue'>
|
||||
<ActionUser size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
{t('基本信息')}
|
||||
</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
<div className='console-user-section-description'>
|
||||
{t('用户的基本账户信息')}
|
||||
</div>
|
||||
</div>
|
||||
@@ -241,20 +275,16 @@ const EditUserModal = (props) => {
|
||||
|
||||
{/* 权限设置 */}
|
||||
{userId && (
|
||||
<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'
|
||||
>
|
||||
<IconUserGroup size={16} />
|
||||
<Card className='rounded-2xl shadow-sm'>
|
||||
<div className='console-user-section'>
|
||||
<Avatar size='small' color='green'>
|
||||
<ActionUsers size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
{t('权限设置')}
|
||||
</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
<div className='console-user-section-description'>
|
||||
{t('用户分组和额度管理')}
|
||||
</div>
|
||||
</div>
|
||||
@@ -287,7 +317,7 @@ const EditUserModal = (props) => {
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<Col span={10}>
|
||||
<Col xs={24} sm={12}>
|
||||
<FormQuotaInput
|
||||
field='quota'
|
||||
label={t('剩余额度')}
|
||||
@@ -296,7 +326,7 @@ const EditUserModal = (props) => {
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<Col span={10}>
|
||||
<Col xs={24} sm={12}>
|
||||
<FormQuotaInput
|
||||
field='gift_quota'
|
||||
label={t('赠送余额')}
|
||||
@@ -307,10 +337,11 @@ const EditUserModal = (props) => {
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<Col span={14}>
|
||||
<Col span={24}>
|
||||
<Form.Slot label={t('添加额度')}>
|
||||
<Button
|
||||
icon={<IconPlus />}
|
||||
icon={<ActionPlus size={16} />}
|
||||
aria-label={t('添加额度')}
|
||||
onClick={() => setIsModalOpen(true)}
|
||||
/>
|
||||
</Form.Slot>
|
||||
@@ -320,20 +351,16 @@ const EditUserModal = (props) => {
|
||||
)}
|
||||
|
||||
{/* 绑定信息 */}
|
||||
<Card className='!rounded-2xl shadow-sm border-0'>
|
||||
<div className='flex items-center mb-2'>
|
||||
<Avatar
|
||||
size='small'
|
||||
color='purple'
|
||||
className='mr-2 shadow-md'
|
||||
>
|
||||
<IconLink size={16} />
|
||||
<Card className='rounded-2xl shadow-sm'>
|
||||
<div className='console-user-section'>
|
||||
<Avatar size='small' color='purple'>
|
||||
<ActionLink size={16} />
|
||||
</Avatar>
|
||||
<div>
|
||||
<Text className='text-lg font-medium'>
|
||||
{t('绑定信息')}
|
||||
</Text>
|
||||
<div className='text-xs text-gray-600'>
|
||||
<div className='console-user-section-description'>
|
||||
{t('第三方账户绑定状态(只读)')}
|
||||
</div>
|
||||
</div>
|
||||
@@ -364,9 +391,9 @@ const EditUserModal = (props) => {
|
||||
</Row>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
</Form>
|
||||
</Spin>
|
||||
</Spin>
|
||||
)}
|
||||
</Form>
|
||||
</SideSheet>
|
||||
|
||||
{/* 添加额度模态框 */}
|
||||
@@ -381,7 +408,7 @@ const EditUserModal = (props) => {
|
||||
closable={null}
|
||||
title={
|
||||
<div className='flex items-center'>
|
||||
<IconPlus className='mr-2' />
|
||||
<ActionPlus size={16} className='mr-2' />
|
||||
{t('添加额度')}
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -603,14 +603,20 @@ export const Tooltip = ({ content, position, showArrow, ...props }) => (
|
||||
export const Popover = ({ position, showArrow, ...props }) => (
|
||||
<Ant.Popover {...props} placement={placement(position)} arrow={showArrow} />
|
||||
);
|
||||
export const Popconfirm = ({ content, position, okType, ...props }) => (
|
||||
<Ant.Popconfirm
|
||||
{...props}
|
||||
description={content}
|
||||
placement={placement(position)}
|
||||
okButtonProps={{ danger: okType === 'danger' }}
|
||||
/>
|
||||
);
|
||||
export const Popconfirm = forwardRef(function Popconfirm(
|
||||
{ content, position, okType, ...props },
|
||||
ref,
|
||||
) {
|
||||
return (
|
||||
<Ant.Popconfirm
|
||||
{...props}
|
||||
ref={ref}
|
||||
description={content}
|
||||
placement={placement(position)}
|
||||
okButtonProps={{ danger: okType === 'danger' }}
|
||||
/>
|
||||
);
|
||||
});
|
||||
export const Banner = ({
|
||||
type,
|
||||
title,
|
||||
|
||||
Reference in New Issue
Block a user