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