fix(ui): 完善界面交互与开发配置
This commit is contained in:
@@ -166,6 +166,16 @@ const LoginForm = () => {
|
||||
const [githubButtonText, setGithubButtonText] = useState('');
|
||||
const [githubButtonDisabled, setGithubButtonDisabled] = useState(false);
|
||||
const githubTimeoutRef = useRef(null);
|
||||
// 微信验证码弹窗表单:确定前先做前端必填校验,通过后再走原提交逻辑
|
||||
const wechatFormApi = useRef(null);
|
||||
const submitWeChatCodeWithValidation = async () => {
|
||||
try {
|
||||
await wechatFormApi.current?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await onSubmitWeChatVerificationCode();
|
||||
};
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
@@ -826,14 +836,10 @@ const LoginForm = () => {
|
||||
<Form.Input
|
||||
field='username'
|
||||
className='auth-login-required-field'
|
||||
rules={[{ required: true, message: t('请输入用户名或邮箱') }]}
|
||||
rules={[{ required: true, message: t('请输入用户名/邮箱') }]}
|
||||
required
|
||||
aria-required='true'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('用户名/邮箱')}
|
||||
</span>
|
||||
}
|
||||
label={t('用户名/邮箱')}
|
||||
placeholder={t('请输入用户名或邮箱')}
|
||||
name='username'
|
||||
size='default'
|
||||
@@ -849,11 +855,7 @@ const LoginForm = () => {
|
||||
rules={[{ required: true, message: t('请输入密码') }]}
|
||||
required
|
||||
aria-required='true'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('密码')}
|
||||
placeholder={t('请输入密码')}
|
||||
name='password'
|
||||
mode='password'
|
||||
@@ -864,7 +866,7 @@ const LoginForm = () => {
|
||||
/>
|
||||
|
||||
{(hasUserAgreement || hasPrivacyPolicy) && (
|
||||
<div className='flex items-center'>
|
||||
<div className='auth-login-agree-row flex items-center'>
|
||||
<Checkbox
|
||||
checked={agreedToTerms}
|
||||
onChange={(e) => setAgreedToTerms(e.target.checked)}
|
||||
@@ -987,7 +989,7 @@ const LoginForm = () => {
|
||||
}
|
||||
visible={showWeChatLoginModal}
|
||||
maskClosable={true}
|
||||
onOk={onSubmitWeChatVerificationCode}
|
||||
onOk={submitWeChatCodeWithValidation}
|
||||
onCancel={() => setShowWeChatLoginModal(false)}
|
||||
okText={t('登录')}
|
||||
centered={true}
|
||||
@@ -1048,11 +1050,12 @@ const LoginForm = () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form>
|
||||
<Form getFormApi={(api) => (wechatFormApi.current = api)}>
|
||||
<Form.Input
|
||||
field='wechat_verification_code'
|
||||
placeholder={t('请输入验证码')}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
value={inputs.wechat_verification_code}
|
||||
onChange={(value) =>
|
||||
handleChange('wechat_verification_code', value)
|
||||
|
||||
@@ -121,10 +121,20 @@ const PasswordResetForm = () => {
|
||||
subtitle={t('密码重置')}
|
||||
/>
|
||||
|
||||
<Form className='auth-login-form'>
|
||||
{/* 前端校验(必填 + 邮箱格式)通过后才调用原 handleSubmit */}
|
||||
<Form className='auth-login-form' onSubmit={() => handleSubmit()}>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={t('邮箱')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入邮箱') },
|
||||
{
|
||||
type: 'email',
|
||||
transform: (v) => v?.trim(),
|
||||
message: t('邮箱格式不正确'),
|
||||
},
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('请输入您的邮箱地址')}
|
||||
name='email'
|
||||
value={email}
|
||||
@@ -138,7 +148,6 @@ const PasswordResetForm = () => {
|
||||
block
|
||||
className='auth-login-submit'
|
||||
htmlType='submit'
|
||||
onClick={handleSubmit}
|
||||
loading={loading}
|
||||
disabled={disableButton}
|
||||
>
|
||||
|
||||
@@ -144,6 +144,26 @@ const RegisterForm = () => {
|
||||
const [githubButtonDisabled, setGithubButtonDisabled] = useState(false);
|
||||
const [showWeChatOpenTipModal, setShowWeChatOpenTipModal] = useState(false);
|
||||
const githubTimeoutRef = useRef(null);
|
||||
// 注册表单 / 微信验证码弹窗的表单实例:用于在原逻辑执行前做前端校验
|
||||
const registerFormApi = useRef(null);
|
||||
const wechatFormApi = useRef(null);
|
||||
// 获取验证码前先校验邮箱必填与格式,通过后走原发送逻辑
|
||||
const sendVerificationCodeWithValidation = async () => {
|
||||
try {
|
||||
await registerFormApi.current?.validate(['email']);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await sendVerificationCode();
|
||||
};
|
||||
const submitWeChatCodeWithValidation = async () => {
|
||||
try {
|
||||
await wechatFormApi.current?.validate();
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
await onSubmitWeChatVerificationCode();
|
||||
};
|
||||
|
||||
const logo = getLogo();
|
||||
const systemName = getSystemName();
|
||||
@@ -665,14 +685,16 @@ const RegisterForm = () => {
|
||||
logoWrapperClassName='mb-2'
|
||||
/>
|
||||
|
||||
<Form className='auth-login-form'>
|
||||
{/* 前端校验通过后才调用原 handleSubmit;其内协议 / 长度 / 一致性判断原样保留 */}
|
||||
<Form
|
||||
className='auth-login-form'
|
||||
getFormApi={(api) => (registerFormApi.current = api)}
|
||||
onSubmit={() => handleSubmit()}
|
||||
>
|
||||
<Form.Input
|
||||
field='username'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('用户名')}
|
||||
</span>
|
||||
}
|
||||
label={t('用户名')}
|
||||
rules={[{ required: true, message: t('请输入用户名') }]}
|
||||
placeholder={t('请输入用户名')}
|
||||
name='username'
|
||||
autoComplete='username'
|
||||
@@ -680,14 +702,15 @@ const RegisterForm = () => {
|
||||
prefix={<IconUser size='small' />}
|
||||
/>
|
||||
|
||||
{/* 密码输入框 */}
|
||||
{/* 密码输入框:长度 8-20 与占位提示、后端约束一致 */}
|
||||
<Form.Input
|
||||
field='password'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('密码')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入密码') },
|
||||
{ min: 8, max: 20, message: t('密码长度需为 8-20 位') },
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('输入密码,最短 8 位,最长 20 位')}
|
||||
name='password'
|
||||
mode='password'
|
||||
@@ -699,11 +722,14 @@ const RegisterForm = () => {
|
||||
{/* 确认密码输入框 */}
|
||||
<Form.Input
|
||||
field='password2'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('确认密码')}
|
||||
</span>
|
||||
}
|
||||
label={t('确认密码')}
|
||||
required
|
||||
validate={(value, values) => {
|
||||
if (!value) return t('请输入确认密码');
|
||||
if (value !== values.password) return t('两次输入的密码不一致');
|
||||
return '';
|
||||
}}
|
||||
trigger='blur'
|
||||
placeholder={t('确认密码')}
|
||||
name='password2'
|
||||
mode='password'
|
||||
@@ -716,11 +742,16 @@ const RegisterForm = () => {
|
||||
<>
|
||||
<Form.Input
|
||||
field='email'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('邮箱')}
|
||||
</span>
|
||||
}
|
||||
label={t('邮箱')}
|
||||
rules={[
|
||||
{ required: true, message: t('请输入邮箱') },
|
||||
{
|
||||
type: 'email',
|
||||
transform: (v) => v?.trim(),
|
||||
message: t('邮箱格式不正确'),
|
||||
},
|
||||
]}
|
||||
trigger='blur'
|
||||
placeholder={t('输入邮箱地址')}
|
||||
name='email'
|
||||
type='email'
|
||||
@@ -730,7 +761,7 @@ const RegisterForm = () => {
|
||||
suffix={
|
||||
<Button
|
||||
size='small'
|
||||
onClick={sendVerificationCode}
|
||||
onClick={sendVerificationCodeWithValidation}
|
||||
loading={verificationCodeLoading}
|
||||
disabled={disableButton || verificationCodeLoading}
|
||||
className='!rounded-lg'
|
||||
@@ -743,11 +774,8 @@ const RegisterForm = () => {
|
||||
/>
|
||||
<Form.Input
|
||||
field='verification_code'
|
||||
label={
|
||||
<span className='text-xs font-medium text-gray-600 dark:text-gray-300'>
|
||||
{t('验证码')}
|
||||
</span>
|
||||
}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
placeholder={t('输入验证码')}
|
||||
name='verification_code'
|
||||
onChange={(value) => handleChange('verification_code', value)}
|
||||
@@ -757,7 +785,7 @@ const RegisterForm = () => {
|
||||
)}
|
||||
|
||||
{(hasUserAgreement || hasPrivacyPolicy) && (
|
||||
<div className='flex items-center'>
|
||||
<div className='auth-login-agree-row flex items-center'>
|
||||
<Checkbox
|
||||
checked={agreedToTerms}
|
||||
onChange={(e) => setAgreedToTerms(e.target.checked)}
|
||||
@@ -793,13 +821,12 @@ const RegisterForm = () => {
|
||||
)}
|
||||
|
||||
<div className='auth-login-actions'>
|
||||
{/* 注册按钮:与登录按钮同款实心主按钮(36px),保留原提交触发与禁用条件 */}
|
||||
{/* 注册按钮:提交经表单校验后调用原 handleSubmit,禁用条件不变 */}
|
||||
<Button
|
||||
theme='solid'
|
||||
htmlType='submit'
|
||||
block
|
||||
className='auth-login-submit'
|
||||
onClick={handleSubmit}
|
||||
loading={registerLoading}
|
||||
disabled={
|
||||
registerLoading ||
|
||||
@@ -870,7 +897,7 @@ const RegisterForm = () => {
|
||||
}
|
||||
visible={showWeChatLoginModal}
|
||||
maskClosable={true}
|
||||
onOk={onSubmitWeChatVerificationCode}
|
||||
onOk={submitWeChatCodeWithValidation}
|
||||
onCancel={() => setShowWeChatLoginModal(false)}
|
||||
okText={t('登录')}
|
||||
centered={true}
|
||||
@@ -931,11 +958,12 @@ const RegisterForm = () => {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<Form>
|
||||
<Form getFormApi={(api) => (wechatFormApi.current = api)}>
|
||||
<Form.Input
|
||||
field='wechat_verification_code'
|
||||
placeholder={t('请输入验证码')}
|
||||
label={t('验证码')}
|
||||
rules={[{ required: true, message: t('请输入验证码') }]}
|
||||
value={inputs.wechat_verification_code}
|
||||
onChange={(value) =>
|
||||
handleChange('wechat_verification_code', value)
|
||||
|
||||
@@ -71,6 +71,21 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 前端校验:与 handleSubmit 内原有判断一致,改为在输入框下方就地提示
|
||||
const codeRules = [
|
||||
{
|
||||
required: true,
|
||||
message: useBackupCode ? t('请输入备用码') : t('请输入验证码'),
|
||||
},
|
||||
{
|
||||
validator: (_, value) => {
|
||||
if (!value) return true;
|
||||
if (useBackupCode) return value.length === 8 || t('备用码必须是8位');
|
||||
return /^\d{6}$/.test(value) || t('验证码必须是6位数字');
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
if (isModal) {
|
||||
return (
|
||||
<div className='space-y-4'>
|
||||
@@ -88,6 +103,8 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
rules={codeRules}
|
||||
trigger='blur'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
@@ -177,6 +194,8 @@ const TwoFAVerification = ({ onSuccess, onBack, isModal = false }) => {
|
||||
value={verificationCode}
|
||||
onChange={setVerificationCode}
|
||||
onKeyPress={handleKeyPress}
|
||||
rules={codeRules}
|
||||
trigger='blur'
|
||||
style={{ marginBottom: 16 }}
|
||||
autoFocus
|
||||
/>
|
||||
|
||||
@@ -130,7 +130,10 @@ export const ConsoleForm = forwardRef(function ConsoleForm(
|
||||
layout={isSettings ? 'vertical' : layout}
|
||||
labelCol={isSettings ? undefined : props.labelCol}
|
||||
wrapperCol={isSettings ? undefined : props.wrapperCol}
|
||||
labelAlign={isSettings ? 'left' : props.labelAlign}
|
||||
labelAlign={isSettings ? 'start' : props.labelAlign}
|
||||
autoComplete={
|
||||
isSettings ? (props.autoComplete ?? 'off') : props.autoComplete
|
||||
}
|
||||
className={classes(
|
||||
isSettings ? 'console-form settings-system-form' : 'console-form',
|
||||
className,
|
||||
|
||||
@@ -23,7 +23,8 @@ import {
|
||||
ChevronLeft as ActionChevronLeft,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
import { consoleMenuPaths, getConsoleMenuKeys } from '../console/consoleRoutes';
|
||||
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||||
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { revealActiveSidebarItem } from '../../helpers/sidebarScroll';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getLucideIcon } from '../../helpers/render';
|
||||
@@ -97,6 +98,7 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||||
const showSkeleton = useMinimumLoadingTime(sidebarLoading, 200);
|
||||
|
||||
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
||||
const navigationRef = useRef(null);
|
||||
// 平台关闭智能路由后,仍有生效中出境同意的普通用户保留入口以便撤回(§9.5,与企业"仅授权模式"同口径)
|
||||
const [routerConsentGranted, setRouterConsentGranted] = useState(
|
||||
() => readPersonalConsentCache() === '1',
|
||||
@@ -493,6 +495,38 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||||
}
|
||||
}, [location.pathname, location.search, routerMapState]);
|
||||
|
||||
useEffect(() => {
|
||||
const navigation = navigationRef.current;
|
||||
if (!navigation || showSkeleton) return;
|
||||
let frame;
|
||||
const scheduleReveal = () => {
|
||||
cancelAnimationFrame(frame);
|
||||
frame = requestAnimationFrame(() => revealActiveSidebarItem(navigation));
|
||||
};
|
||||
scheduleReveal();
|
||||
const resizeObserver = new ResizeObserver(scheduleReveal);
|
||||
resizeObserver.observe(navigation);
|
||||
const mutationObserver = new MutationObserver(scheduleReveal);
|
||||
mutationObserver.observe(navigation, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
attributes: true,
|
||||
attributeFilter: ['hidden'],
|
||||
});
|
||||
return () => {
|
||||
cancelAnimationFrame(frame);
|
||||
resizeObserver.disconnect();
|
||||
mutationObserver.disconnect();
|
||||
};
|
||||
}, [
|
||||
showSkeleton,
|
||||
selectedKeys,
|
||||
collapsed,
|
||||
forceExpanded,
|
||||
openedKeys,
|
||||
foldedGroups,
|
||||
]);
|
||||
|
||||
// 监控折叠状态变化以更新 body class(--sidebar-current-width 由它驱动)。
|
||||
// 抽屉态下跳过:body class 是全局的,抽屉临时展开不该顺手把桌面侧栏宽度也改掉。
|
||||
useEffect(() => {
|
||||
@@ -639,7 +673,7 @@ const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||||
collapsed={collapsed}
|
||||
showAdmin={isAdmin()}
|
||||
>
|
||||
<nav className='ui-center-sidebar-nav'>
|
||||
<nav ref={navigationRef} className='ui-center-sidebar-nav'>
|
||||
{/* 聊天区域 */}
|
||||
{hasSectionVisibleModules('chat') &&
|
||||
renderGroup(
|
||||
|
||||
@@ -44,7 +44,6 @@ const ActionButtons = ({
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
sidebarModulesAdmin,
|
||||
isOrgUser,
|
||||
@@ -235,7 +234,6 @@ const ActionButtons = ({
|
||||
userState={userState}
|
||||
isLoading={isLoading}
|
||||
isMobile={isMobile}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
headerNavModules={headerNavModules}
|
||||
rightActions={headerNavModules?.rightActions}
|
||||
sidebarModulesAdmin={sidebarModulesAdmin}
|
||||
|
||||
@@ -19,11 +19,9 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import { ChevronDown as ActionChevronDown } from '@/components/common/icons/ActionIcons';
|
||||
import React, { useState } from 'react';
|
||||
import { Link, useLocation } from 'react-router-dom';
|
||||
import { Avatar, Button as AntButton, Dropdown as AntDropdown } from 'antd';
|
||||
import { Button } from '@/components/ui';
|
||||
import { UserRound, KeyRound, LogOut } from 'lucide-react';
|
||||
import { getUserAvatarUrl, isAuthPagePath } from '../../../helpers';
|
||||
import { getUserAvatarUrl } from '../../../helpers';
|
||||
import SkeletonWrapper from '../components/SkeletonWrapper';
|
||||
import { isHeaderModuleEnabled } from '../../../constants/headerNavModules';
|
||||
|
||||
@@ -46,7 +44,6 @@ const UserArea = ({
|
||||
userState,
|
||||
isLoading,
|
||||
isMobile,
|
||||
isSelfUseMode,
|
||||
headerNavModules,
|
||||
rightActions = {},
|
||||
sidebarModulesAdmin = {},
|
||||
@@ -55,7 +52,6 @@ const UserArea = ({
|
||||
navigate,
|
||||
t,
|
||||
}) => {
|
||||
const location = useLocation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const isActionVisible = (key) => rightActions?.[key] !== false;
|
||||
const hasHeaderModuleConfig =
|
||||
@@ -68,9 +64,6 @@ const UserArea = ({
|
||||
return section.enabled !== false && section[moduleKey] !== false;
|
||||
};
|
||||
|
||||
// 在登录/注册/重置密码/企业登录页面时,未登录用户不显示登录注册按钮,避免重复
|
||||
const isAuthPage = isAuthPagePath(location.pathname);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<SkeletonWrapper
|
||||
@@ -193,64 +186,9 @@ const UserArea = ({
|
||||
</AntButton>
|
||||
</AntDropdown>
|
||||
);
|
||||
} else {
|
||||
if (isAuthPage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const showRegisterButton = !isSelfUseMode;
|
||||
|
||||
const commonSizingAndLayoutClass =
|
||||
'flex items-center justify-center !py-[10px] !px-1.5';
|
||||
|
||||
const loginButtonSpecificStyling =
|
||||
'!bg-transparent hover:!bg-brand/10 dark:hover:!bg-brand/15 hover:!text-brand-deep !transition-all !duration-200';
|
||||
let loginButtonClasses = `${commonSizingAndLayoutClass} ${loginButtonSpecificStyling}`;
|
||||
|
||||
let registerButtonClasses = `${commonSizingAndLayoutClass}`;
|
||||
|
||||
const loginButtonTextSpanClass =
|
||||
'!text-xs !text-ui-color-text-1 dark:!text-gray-300 !p-1.5';
|
||||
const registerButtonTextSpanClass = '!text-xs !text-white !p-1.5';
|
||||
|
||||
if (showRegisterButton) {
|
||||
if (isMobile) {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-l-full !rounded-r-none';
|
||||
}
|
||||
registerButtonClasses += ' !rounded-r-full !rounded-l-none';
|
||||
} else {
|
||||
loginButtonClasses += ' !rounded-full';
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='flex items-center'>
|
||||
<Link to='/org/login' className='flex'>
|
||||
<Button
|
||||
theme='borderless'
|
||||
type='tertiary'
|
||||
className={loginButtonClasses}
|
||||
>
|
||||
<span className={loginButtonTextSpanClass}>{t('登录')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
{showRegisterButton && (
|
||||
<div className='hidden md:block'>
|
||||
<Link to='/register' className='flex -ml-px'>
|
||||
<Button
|
||||
theme='solid'
|
||||
type='primary'
|
||||
className={registerButtonClasses}
|
||||
>
|
||||
<span className={registerButtonTextSpanClass}>{t('注册')}</span>
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export default UserArea;
|
||||
|
||||
@@ -181,7 +181,6 @@ const HeaderBar = ({ onMobileMenuToggle, drawerOpen }) => {
|
||||
userState={userState}
|
||||
isLoading={isLoading}
|
||||
isMobile={isMobile}
|
||||
isSelfUseMode={isSelfUseMode}
|
||||
headerNavModules={headerNavModules}
|
||||
sidebarModulesAdmin={sidebarModulesAdmin}
|
||||
isOrgUser={isOrgUser}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/* 等级与模型访问(level_policy)局部布局覆盖,全部只改尺寸不改配色 */
|
||||
/* 等级与模型访问(level_policy)局部布局与图标样式 */
|
||||
|
||||
.level-policy-model-toggle.ant-btn .ant-btn-icon {
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
/* 默认访问态 pureCard 单选:两张卡等分弹窗整行宽,避免随文案长短一宽一窄 */
|
||||
|
||||
@@ -1638,8 +1638,9 @@ const LevelPolicySetting = () => {
|
||||
const button = (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
type={r.modelDiscountCount > 0 ? 'primary' : 'tertiary'}
|
||||
className='level-policy-model-toggle'
|
||||
theme={r.modelDiscountCount > 0 ? undefined : 'borderless'}
|
||||
type={r.modelDiscountCount > 0 ? 'link' : 'tertiary'}
|
||||
icon={
|
||||
expanded ? (
|
||||
<ActionChevronDown size={14} />
|
||||
|
||||
@@ -849,7 +849,7 @@ const SystemSetting = () => {
|
||||
|
||||
<Card>
|
||||
<Form.Section text={t('SSRF防护设置')}>
|
||||
<Text extraText={t('SSRF防护详细说明')}>
|
||||
<Text title={t('SSRF防护详细说明')}>
|
||||
{t('配置服务器端请求伪造(SSRF)防护,用于保护内网资源安全')}
|
||||
</Text>
|
||||
<Row
|
||||
|
||||
@@ -18,6 +18,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { theme } from 'antd';
|
||||
import { Button, Progress, Tag, Timeline, Typography } from '@/components/ui';
|
||||
import {
|
||||
IconAlertTriangle,
|
||||
@@ -35,13 +36,14 @@ import './skill-components.css';
|
||||
|
||||
const { Text, Title, Paragraph } = Typography;
|
||||
|
||||
const SemanticTag = ({ value, fallback, className = '' }) => {
|
||||
const SemanticTag = ({ value, fallback, className = '', style }) => {
|
||||
const { t } = useTranslation();
|
||||
const token = getSkillTagToken(value);
|
||||
return (
|
||||
<Tag
|
||||
color={token.color}
|
||||
className={className}
|
||||
style={style}
|
||||
aria-label={t(fallback || token.label)}
|
||||
>
|
||||
{t(fallback || token.label)}
|
||||
@@ -62,20 +64,26 @@ export const ScopeSourceBadge = ({ source, detail }) => {
|
||||
);
|
||||
};
|
||||
|
||||
export const LicenseBadge = ({ expression, decision }) => (
|
||||
<span className='skill-license-badge'>
|
||||
<SemanticTag
|
||||
value={
|
||||
decision === 'blocked'
|
||||
? 'deny'
|
||||
: decision === 'approved'
|
||||
? 'allow'
|
||||
: 'license_pending'
|
||||
}
|
||||
fallback={expression || '许可证未知'}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
export const LicenseBadge = ({ expression, decision }) => {
|
||||
const { token } = theme.useToken();
|
||||
const value =
|
||||
decision === 'blocked'
|
||||
? 'deny'
|
||||
: decision === 'approved'
|
||||
? 'allow'
|
||||
: 'license_pending';
|
||||
const { color } = getSkillTagToken(value);
|
||||
return (
|
||||
<span className='skill-license-badge'>
|
||||
<SemanticTag
|
||||
value={value}
|
||||
fallback={expression || '许可证未知'}
|
||||
// 第 9 档在浅色下更深、暗色下更亮,保证小字号许可证的对比度。
|
||||
style={{ color: token[`${color}-9`] }}
|
||||
/>
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
export const RiskBadge = ({ conclusion }) => (
|
||||
<SemanticTag
|
||||
@@ -168,6 +176,7 @@ export const GrayscaleProgress = ({ percent = 0, label }) => (
|
||||
);
|
||||
|
||||
export const SkillDetailSideSheet = ({
|
||||
className,
|
||||
visible,
|
||||
onCancel,
|
||||
title,
|
||||
@@ -175,6 +184,7 @@ export const SkillDetailSideSheet = ({
|
||||
footer,
|
||||
}) => (
|
||||
<OrgSideSheet
|
||||
className={className}
|
||||
visible={visible}
|
||||
onCancel={onCancel}
|
||||
title={title}
|
||||
|
||||
@@ -19,7 +19,7 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
export const SKILL_TAG_TOKENS = Object.freeze({
|
||||
pending_import: { color: 'grey', label: '待导入' },
|
||||
license_pending: { color: 'amber', label: '许可证待审核' },
|
||||
license_pending: { color: 'gold', label: '许可证待审核' },
|
||||
scan_pending: { color: 'orange', label: '待云端化改写' },
|
||||
review_pending: { color: 'blue', label: '待审核' },
|
||||
published: { color: 'green', label: '已发布' },
|
||||
|
||||
@@ -19,7 +19,9 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Alert, Button, Empty, Table, Tag } from 'antd';
|
||||
import { Button, Empty, Tag } from 'antd';
|
||||
import { Table } from '@/components/ui';
|
||||
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
|
||||
import { listDecisions } from './api';
|
||||
import { gateText, jevReasonText, srcText } from './labels';
|
||||
|
||||
@@ -138,14 +140,12 @@ const DecisionTable = ({ mode, orgId }) => {
|
||||
columns={columns}
|
||||
dataSource={data.items || []}
|
||||
scroll={{ x: 'max-content' }}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由请求')}
|
||||
/>
|
||||
),
|
||||
}}
|
||||
empty={
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由请求')}
|
||||
/>
|
||||
}
|
||||
pagination={{
|
||||
// 接口固定 page_size=20,不提供每页条数切换
|
||||
current: page,
|
||||
|
||||
@@ -20,7 +20,6 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
@@ -33,6 +32,7 @@ import {
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
|
||||
import { showError, showSuccess } from '../../helpers';
|
||||
import { getAdminStatus, loadOptions, saveOption, setJevKey } from './api';
|
||||
|
||||
@@ -333,7 +333,7 @@ const GlobalSettings = () => {
|
||||
case 'int':
|
||||
return (
|
||||
<InputNumber
|
||||
style={{ width: 200 }}
|
||||
className='smart-router-setting-control'
|
||||
min={f.min}
|
||||
max={f.max}
|
||||
value={Number(v) || 0}
|
||||
@@ -353,7 +353,7 @@ const GlobalSettings = () => {
|
||||
case 'select':
|
||||
return (
|
||||
<Select
|
||||
style={{ width: 200 }}
|
||||
className='smart-router-setting-control'
|
||||
value={v}
|
||||
options={f.options.map((o) => ({ label: o, value: o }))}
|
||||
onChange={set}
|
||||
@@ -371,7 +371,7 @@ const GlobalSettings = () => {
|
||||
default:
|
||||
return (
|
||||
<Input
|
||||
style={{ maxWidth: 360 }}
|
||||
className='smart-router-setting-control'
|
||||
value={v}
|
||||
onChange={(e) => set(e.target.value)}
|
||||
/>
|
||||
@@ -470,7 +470,12 @@ const GlobalSettings = () => {
|
||||
<div key={sec} className='smart-router-card'>
|
||||
<div className='smart-router-card-title'>{t(title)}</div>
|
||||
{/* 受控字段沿用 values 状态,Form 只提供竖排标签布局,不接管取值与提交 */}
|
||||
<Form layout='vertical' component='div' requiredMark={false}>
|
||||
<Form
|
||||
layout='vertical'
|
||||
component='div'
|
||||
requiredMark={false}
|
||||
className='smart-router-settings-form'
|
||||
>
|
||||
{FIELDS.filter((f) => f.section === sec).map((f) => (
|
||||
<Form.Item
|
||||
key={f.key}
|
||||
@@ -501,9 +506,9 @@ const GlobalSettings = () => {
|
||||
</span>
|
||||
}
|
||||
>
|
||||
<Space size={8} wrap>
|
||||
<Space size={8} wrap className='smart-router-key-tools'>
|
||||
<Input.Password
|
||||
style={{ width: 320 }}
|
||||
className='smart-router-key-input'
|
||||
placeholder={t('输入新密钥;留空表示不修改')}
|
||||
value={keys[p]}
|
||||
onChange={(e) =>
|
||||
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
Button,
|
||||
Checkbox,
|
||||
Collapse,
|
||||
Drawer,
|
||||
Form,
|
||||
Input,
|
||||
InputNumber,
|
||||
@@ -33,6 +32,7 @@ import {
|
||||
Switch,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { ConsoleDrawer as Drawer } from '../console/ConsolePrimitives';
|
||||
import { Plus, Trash2 } from '../common/icons/ActionIcons';
|
||||
import { showError, showSuccess } from '../../helpers';
|
||||
import { saveProfile } from './api';
|
||||
|
||||
@@ -19,16 +19,9 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Alert,
|
||||
Button,
|
||||
Empty,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'antd';
|
||||
import { Button, Empty, Popconfirm, Space, Tag, Typography } from 'antd';
|
||||
import { Table } from '@/components/ui';
|
||||
import { ConsoleAlert as Alert } from '../console/ConsolePrimitives';
|
||||
import { Plus } from '../common/icons/ActionIcons';
|
||||
import { copy, showError, showSuccess } from '../../helpers';
|
||||
import { deleteProfile, listCandidateModels, listProfiles } from './api';
|
||||
@@ -230,20 +223,18 @@ const ProfileTable = ({ mode, orgId, canWrite = true, emptyHint }) => {
|
||||
dataSource={list}
|
||||
pagination={false}
|
||||
scroll={{ x: 'max-content' }}
|
||||
locale={{
|
||||
emptyText: (
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由集合')}
|
||||
>
|
||||
{canWrite && (
|
||||
<Button type='primary' onClick={() => setEditing({})}>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</Empty>
|
||||
),
|
||||
}}
|
||||
empty={
|
||||
<Empty
|
||||
image={Empty.PRESENTED_IMAGE_SIMPLE}
|
||||
description={t('还没有智能路由集合')}
|
||||
>
|
||||
{canWrite && (
|
||||
<Button type='primary' onClick={() => setEditing({})}>
|
||||
{t('新建集合')}
|
||||
</Button>
|
||||
)}
|
||||
</Empty>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
<ProfileEditor
|
||||
|
||||
@@ -19,7 +19,11 @@ For commercial licensing, please contact support@quantumnous.com
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Alert, Button, Input, Modal, Progress, Tag, Typography } from 'antd';
|
||||
import { Button, Input, Progress, Tag, Typography } from 'antd';
|
||||
import {
|
||||
ConsoleAlert as Alert,
|
||||
ConsoleModal as Modal,
|
||||
} from '../console/ConsolePrimitives';
|
||||
import { simulateProfile } from './api';
|
||||
import { gateText, reasonText, srcText } from './labels';
|
||||
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.smart-router-page .smart-router-intro.console-alert {
|
||||
margin-block: 0;
|
||||
}
|
||||
|
||||
.smart-router-alert {
|
||||
margin-bottom: 18px;
|
||||
}
|
||||
@@ -181,7 +185,7 @@
|
||||
.smart-router-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 0 16px;
|
||||
gap: 0 24px;
|
||||
}
|
||||
|
||||
.smart-router-grid-full {
|
||||
@@ -274,3 +278,67 @@
|
||||
min-width: 0;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.smart-router-settings-form {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
column-gap: 24px;
|
||||
}
|
||||
|
||||
.smart-router-setting-control.ant-input-number,
|
||||
.smart-router-setting-control.ant-select,
|
||||
.smart-router-setting-control.ant-input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.smart-router-key-tools {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.smart-router-key-input {
|
||||
width: min(320px, 100%);
|
||||
}
|
||||
|
||||
.smart-router-sheet .ant-drawer-body {
|
||||
padding: 24px;
|
||||
scrollbar-gutter: stable;
|
||||
}
|
||||
|
||||
.smart-router-sheet .ant-modal {
|
||||
max-width: calc(100vw - 32px);
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.smart-router-card,
|
||||
.smart-router-consent-row {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.smart-router-settings-form {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.smart-router-sheet .smart-router-inline > .ant-select,
|
||||
.smart-router-sheet .smart-router-inline > .ant-input-number {
|
||||
max-width: 100%;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.smart-router-sheet .smart-router-model-select {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
|
||||
.smart-router-key-tools > .ant-space-item,
|
||||
.smart-router-key-input {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.smart-router-kv {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.smart-router-kv dd {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ function renderModelName(record, copyText, t, isRootUser) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 使用记录(个人端)呈现:原型为 Ant Design 预设无边框标签与纯文本,不含渐变点、脉冲与悬停缩放 ----
|
||||
// ---- 使用记录(个人端)呈现 ----
|
||||
const RECORD_TYPE_COLORS = {
|
||||
1: 'cyan',
|
||||
2: 'green',
|
||||
@@ -312,19 +312,39 @@ function renderRecordType(type, t) {
|
||||
}
|
||||
|
||||
function renderRecordUseTime(record, t) {
|
||||
const useTime = `${parseInt(record.use_time)}s`;
|
||||
const useTime = parseInt(record.use_time, 10);
|
||||
const validUseTime = Number.isFinite(useTime) && useTime >= 0;
|
||||
const other = getLogOther(record.other);
|
||||
const firstTime =
|
||||
record.is_stream && other?.frt
|
||||
? ` / ${(parseFloat(other.frt) / 1000.0).toFixed(1)}s`
|
||||
: '';
|
||||
const firstMilliseconds = parseFloat(other?.frt);
|
||||
const validFirstTime =
|
||||
Number.isFinite(firstMilliseconds) && firstMilliseconds >= 0;
|
||||
// 首字耗时按实际显示的一位小数判色,避免显示 3.0s / 10.0s 却仍落在上一档。
|
||||
const firstTime = validFirstTime
|
||||
? (firstMilliseconds / 1000).toFixed(1)
|
||||
: null;
|
||||
const useTimeColor = !validUseTime
|
||||
? undefined
|
||||
: useTime < 101
|
||||
? 'green'
|
||||
: useTime < 300
|
||||
? 'gold'
|
||||
: 'magenta';
|
||||
const firstTimeColor = !validFirstTime
|
||||
? undefined
|
||||
: Number(firstTime) < 3
|
||||
? 'cyan'
|
||||
: Number(firstTime) < 10
|
||||
? 'orange'
|
||||
: 'red';
|
||||
return (
|
||||
<span className='usage-record-use-time'>
|
||||
<span>
|
||||
{useTime}
|
||||
{firstTime && <em>{firstTime}</em>}
|
||||
</span>
|
||||
<AntTag variant='filled' color={record.is_stream ? 'cyan' : undefined}>
|
||||
<span className='usage-record-use-time' aria-label={t('用时/首字')}>
|
||||
<AntTag color={useTimeColor}>{validUseTime ? `${useTime}s` : '—'}</AntTag>
|
||||
{record.is_stream && (
|
||||
<AntTag color={firstTimeColor}>
|
||||
{validFirstTime ? `${firstTime}s` : '—'}
|
||||
</AntTag>
|
||||
)}
|
||||
<AntTag color={record.is_stream ? 'blue' : undefined}>
|
||||
{record.is_stream ? t('流') : t('非流')}
|
||||
</AntTag>
|
||||
</span>
|
||||
@@ -336,7 +356,7 @@ const formatRecordNumber = (value) => {
|
||||
return Number.isFinite(number) ? number.toLocaleString('en-US') : value;
|
||||
};
|
||||
|
||||
// Both reference images show the same 2097px table at opposite scroll positions.
|
||||
// 固定列宽保持横向滚动时的对齐,耗时列预留三枚标签的空间。
|
||||
const RECORD_COLUMN_WIDTHS = {
|
||||
time: 152,
|
||||
channel: 85,
|
||||
@@ -345,7 +365,7 @@ const RECORD_COLUMN_WIDTHS = {
|
||||
group: 148,
|
||||
type: 110,
|
||||
model: 225,
|
||||
use_time: 126,
|
||||
use_time: 190,
|
||||
prompt: 110,
|
||||
completion: 110,
|
||||
cost: 136,
|
||||
|
||||
@@ -17,7 +17,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { forwardRef, useLayoutEffect, useRef, useState } from 'react';
|
||||
import React, {
|
||||
forwardRef,
|
||||
useEffect,
|
||||
useLayoutEffect,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import { Table, theme } from 'antd';
|
||||
import { colord } from 'colord';
|
||||
import { isCenterTableScope, prepareCenterColumns } from './centerTablePolicy';
|
||||
@@ -56,8 +62,21 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
const scroller = root.querySelector('.ant-table-content,.ant-table-body');
|
||||
const previousTabIndex = scroller?.getAttribute('tabindex');
|
||||
if (scroller && previousTabIndex === null) scroller.tabIndex = 0;
|
||||
const update = () => setWidth(root.clientWidth);
|
||||
update();
|
||||
const observer = new ResizeObserver(([entry]) => {
|
||||
// ResizeObserver already measured the box; avoid a synchronous layout read.
|
||||
setWidth(entry.contentRect.width);
|
||||
});
|
||||
observer.observe(root);
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
if (scroller && previousTabIndex === null)
|
||||
scroller.removeAttribute('tabindex');
|
||||
};
|
||||
}, [enabled]);
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
const root = tableRef.current?.nativeElement;
|
||||
if (!root) return;
|
||||
const measureActionWidths = () => {
|
||||
const next = {};
|
||||
root.querySelectorAll('th.center-action-cell').forEach((header) => {
|
||||
@@ -69,9 +88,15 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
(element) => element.getBoundingClientRect().width > 0,
|
||||
);
|
||||
const widths = cells.map((cell) => {
|
||||
const controls = [
|
||||
const controlsWithWidths = [
|
||||
...cell.querySelectorAll('button, a, [role="button"]'),
|
||||
].filter((element) => element.getBoundingClientRect().width > 0);
|
||||
]
|
||||
.map((element) => ({
|
||||
element,
|
||||
width: element.getBoundingClientRect().width,
|
||||
}))
|
||||
.filter(({ width }) => width > 0);
|
||||
const controls = controlsWithWidths.map(({ element }) => element);
|
||||
if (!controls.length) return 0;
|
||||
let group = controls[0].parentElement;
|
||||
while (
|
||||
@@ -85,10 +110,7 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
(Number.parseFloat(cellStyle.paddingRight) || 0);
|
||||
const gap = Number.parseFloat(getComputedStyle(group).columnGap) || 8;
|
||||
return (
|
||||
controls.reduce(
|
||||
(total, element) => total + element.getBoundingClientRect().width,
|
||||
0,
|
||||
) +
|
||||
controlsWithWidths.reduce((total, { width }) => total + width, 0) +
|
||||
gap * Math.max(0, controls.length - 1) +
|
||||
padding
|
||||
);
|
||||
@@ -107,13 +129,8 @@ const CenterTable = forwardRef(function CenterTable(
|
||||
});
|
||||
};
|
||||
const frame = requestAnimationFrame(measureActionWidths);
|
||||
const observer = new ResizeObserver(update);
|
||||
observer.observe(root);
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
cancelAnimationFrame(frame);
|
||||
if (scroller && previousTabIndex === null)
|
||||
scroller.removeAttribute('tabindex');
|
||||
};
|
||||
}, [enabled, width, columns, props.dataSource]);
|
||||
return (
|
||||
|
||||
@@ -36,7 +36,10 @@ import {
|
||||
Space as AntSpace,
|
||||
} from 'antd';
|
||||
import dayjs from 'dayjs';
|
||||
import { useConsoleControlSize } from '../console/ConsoleContext';
|
||||
import {
|
||||
useConsoleControlSize,
|
||||
useConsolePage,
|
||||
} from '../console/ConsoleContext';
|
||||
|
||||
export const controlSize = (size) => (size === 'default' ? 'middle' : size);
|
||||
export const placement = (position) =>
|
||||
@@ -53,6 +56,12 @@ export const placement = (position) =>
|
||||
const statusOf = (status) =>
|
||||
['error', 'warning'].includes(status) ? status : undefined;
|
||||
|
||||
function useSettingsInputId(id) {
|
||||
const generatedId = React.useId();
|
||||
const isSettings = useConsolePage()?.page.key === 'setting';
|
||||
return id ?? (isSettings ? generatedId : undefined);
|
||||
}
|
||||
|
||||
// Existing screens consume values; DOM events stay inside this view boundary.
|
||||
export const Input = forwardRef(function Input(
|
||||
{
|
||||
@@ -69,10 +78,20 @@ export const Input = forwardRef(function Input(
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
const isSettings = useConsolePage()?.page.key === 'setting';
|
||||
const Component = mode === 'password' ? AntInput.Password : AntInput;
|
||||
return (
|
||||
<Component
|
||||
{...props}
|
||||
id={useSettingsInputId(props.id)}
|
||||
autoComplete={
|
||||
props.autoComplete ??
|
||||
(isSettings
|
||||
? mode === 'password' || props.type === 'password'
|
||||
? 'new-password'
|
||||
: 'off'
|
||||
: undefined)
|
||||
}
|
||||
ref={ref}
|
||||
size={useConsoleControlSize(size)}
|
||||
readOnly={readonly ?? props.readOnly}
|
||||
@@ -91,6 +110,7 @@ export const TextArea = forwardRef(function TextArea(
|
||||
return (
|
||||
<AntInput.TextArea
|
||||
{...props}
|
||||
id={useSettingsInputId(props.id)}
|
||||
ref={ref}
|
||||
autoSize={autosize}
|
||||
maxLength={props.maxLength ?? maxCount}
|
||||
@@ -152,6 +172,7 @@ export const InputNumber = forwardRef(function InputNumber(
|
||||
return (
|
||||
<AntInputNumber
|
||||
{...props}
|
||||
id={useSettingsInputId(props.id)}
|
||||
ref={ref}
|
||||
size={useConsoleControlSize(size)}
|
||||
controls={!hideButtons}
|
||||
|
||||
+62
-14
@@ -82,8 +82,12 @@ export const Form = forwardRef(function Form(
|
||||
const FormComponent = consolePage ? ConsoleForm : AntForm;
|
||||
const [form] = AntForm.useForm();
|
||||
const [, renderValues] = useReducer((value) => value + 1, 0);
|
||||
const callbacks = useRef({ getFormApi, onValueChange });
|
||||
callbacks.current = { getFormApi, onValueChange };
|
||||
const callbacks = useRef({});
|
||||
callbacks.current = {
|
||||
getFormApi,
|
||||
onValueChange,
|
||||
renderValues: typeof children === 'function' ? renderValues : () => {},
|
||||
};
|
||||
const api = useMemo(
|
||||
() => ({
|
||||
getValues: () => form.getFieldsValue(true),
|
||||
@@ -94,17 +98,17 @@ export const Form = forwardRef(function Form(
|
||||
callbacks.current.onValueChange?.(form.getFieldsValue(true), {
|
||||
[field]: value,
|
||||
});
|
||||
renderValues();
|
||||
callbacks.current.renderValues();
|
||||
},
|
||||
setValues: (next) => {
|
||||
form.setFieldsValue(next);
|
||||
callbacks.current.onValueChange?.(form.getFieldsValue(true), next);
|
||||
renderValues();
|
||||
callbacks.current.renderValues();
|
||||
},
|
||||
reset: (fields) => {
|
||||
form.resetFields(fields?.map?.(fieldPath));
|
||||
callbacks.current.onValueChange?.(form.getFieldsValue(true));
|
||||
renderValues();
|
||||
callbacks.current.renderValues();
|
||||
},
|
||||
validate: (fields) => form.validateFields(fields?.map?.(fieldPath)),
|
||||
submitForm: () => form.submit(),
|
||||
@@ -122,10 +126,13 @@ export const Form = forwardRef(function Form(
|
||||
useImperativeHandle(ref, () => ({ formApi: api, ...api }), [api]);
|
||||
useEffect(() => {
|
||||
callbacks.current.getFormApi?.(api);
|
||||
renderValues();
|
||||
callbacks.current.renderValues();
|
||||
}, [api]);
|
||||
useEffect(() => {
|
||||
if (values) form.setFieldsValue(values);
|
||||
if (values) {
|
||||
form.setFieldsValue(values);
|
||||
callbacks.current.renderValues();
|
||||
}
|
||||
}, [form, values]);
|
||||
return (
|
||||
<FormContext.Provider value={form}>
|
||||
@@ -151,7 +158,13 @@ export const Form = forwardRef(function Form(
|
||||
wrapperCol={
|
||||
props.wrapperCol ?? (labelWidth ? { flex: '1 1 0' } : undefined)
|
||||
}
|
||||
labelAlign={labelAlign}
|
||||
labelAlign={
|
||||
labelAlign === 'left'
|
||||
? 'start'
|
||||
: labelAlign === 'right'
|
||||
? 'end'
|
||||
: labelAlign
|
||||
}
|
||||
onFinish={onSubmit}
|
||||
onFinishFailed={
|
||||
consolePage && onSubmitFail
|
||||
@@ -168,7 +181,7 @@ export const Form = forwardRef(function Form(
|
||||
}
|
||||
onValuesChange={(_, all) => {
|
||||
callbacks.current.onValueChange?.(all);
|
||||
renderValues();
|
||||
callbacks.current.renderValues();
|
||||
}}
|
||||
>
|
||||
{typeof children === 'function' ? (
|
||||
@@ -198,15 +211,41 @@ function labelProps(label) {
|
||||
|
||||
// Legacy Form.RadioGroup reports the selected value; standalone RadioGroup reports an event.
|
||||
const FieldRadioGroup = forwardRef(function FieldRadioGroup(
|
||||
{ onChange, ...props },
|
||||
{ onChange, id, options, children, ...props },
|
||||
ref,
|
||||
) {
|
||||
// A label must target a radio input, rather than the group's non-labelable div.
|
||||
const optionIndex = options?.findIndex((option) => !option?.disabled);
|
||||
let childLabeled = false;
|
||||
return (
|
||||
<Controls.RadioGroup
|
||||
{...props}
|
||||
ref={ref}
|
||||
id={id ? `${id}-group` : undefined}
|
||||
options={options?.map((option, index) =>
|
||||
index === optionIndex && id
|
||||
? {
|
||||
...(typeof option === 'object'
|
||||
? option
|
||||
: { label: option, value: option }),
|
||||
id,
|
||||
}
|
||||
: option,
|
||||
)}
|
||||
onChange={(event) => onChange?.(event.target.value, event)}
|
||||
/>
|
||||
>
|
||||
{React.Children.map(children, (child) => {
|
||||
if (
|
||||
!id ||
|
||||
childLabeled ||
|
||||
!React.isValidElement(child) ||
|
||||
child.props.disabled
|
||||
)
|
||||
return child;
|
||||
childLabeled = true;
|
||||
return React.cloneElement(child, { id });
|
||||
})}
|
||||
</Controls.RadioGroup>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -284,6 +323,9 @@ export function withField(
|
||||
) : (
|
||||
<Component
|
||||
{...props}
|
||||
{...(Component === FieldRadioGroup && fieldLabel.label
|
||||
? { 'aria-label': props['aria-label'] ?? fieldLabel.label }
|
||||
: {})}
|
||||
id={props.id ?? fieldLabel.htmlFor}
|
||||
ref={ref}
|
||||
style={style}
|
||||
@@ -370,13 +412,19 @@ Form.Slot = function Slot({ label, error, children, ...props }) {
|
||||
</AntForm.Item>
|
||||
);
|
||||
};
|
||||
Form.Section = function Section({ text, extraText, children, ...props }) {
|
||||
Form.Section = function Section({
|
||||
text,
|
||||
extraText,
|
||||
children,
|
||||
component: Component = 'section',
|
||||
...props
|
||||
}) {
|
||||
return (
|
||||
<section {...props}>
|
||||
<Component {...props}>
|
||||
<h3 className='ui-form-section'>{text}</h3>
|
||||
{extraText && <p className='ui-field-help'>{extraText}</p>}
|
||||
{children}
|
||||
</section>
|
||||
</Component>
|
||||
);
|
||||
};
|
||||
Form.Label = function Label({ required, children, ...props }) {
|
||||
|
||||
@@ -383,12 +383,14 @@ function CenterPaginatedTable({
|
||||
{...props}
|
||||
pagination={{
|
||||
...centerPaginationOptions(config, isMobile),
|
||||
showSizeChanger: Boolean(
|
||||
local ||
|
||||
config.onPageSizeChange ||
|
||||
config.onShowSizeChange ||
|
||||
config.onChange,
|
||||
),
|
||||
showSizeChanger:
|
||||
config.showSizeChanger ??
|
||||
Boolean(
|
||||
local ||
|
||||
config.onPageSizeChange ||
|
||||
config.onShowSizeChange ||
|
||||
config.onChange,
|
||||
),
|
||||
current,
|
||||
pageSize,
|
||||
onShowSizeChange: undefined,
|
||||
|
||||
Reference in New Issue
Block a user