fix(ui): 统一三中心表格交互并优化企业及配套页面

- 公共表格:统一分组标签、状态开关和危险操作确认,支持防重复提交和失败重试,修复浮层触发组件的 ref 转发。
- 控制台:统一用户和渠道编辑抽屉,修正分组回填与提交格式,对齐系统设置操作区和预约列表。
- 企业中心:调整技能中心页签和窄屏布局,优化质量监控提示栏、效能分析及成本对账,统一消耗明细和审计日志筛选。
- 用户中心及公共页面:优化密钥和消费记录展示,对齐模型超市筛选,统一公开与内嵌客户端下载页。
- 同步多语言文案、组件规范与移动端视口要求。
This commit is contained in:
zhanjunhao
2026-11-24 13:26:07 +08:00
parent bf708039a3
commit 34e318454d
124 changed files with 2682 additions and 1810 deletions
@@ -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>
}