feat: 1.升级 Ant Design Ui 至 v6 2. 修复企业充值金额输入限制
This commit is contained in:
@@ -716,7 +716,7 @@ const OrgMembers = ({
|
||||
className='oc-block-gap'
|
||||
type='info'
|
||||
showIcon
|
||||
message={t(
|
||||
title={t(
|
||||
'当前企业仅有您一位成员。为员工创建成员账号后,即可在此管理成员角色、额度上限和访问权限。',
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -363,7 +363,7 @@ const OrgPersonalSettings = ({ orgId }) => {
|
||||
</>
|
||||
) : (
|
||||
<div className='oc-ps-unlimited'>
|
||||
<AntTag color='gold' bordered={false}>
|
||||
<AntTag color='gold' variant='filled'>
|
||||
{t('不限额')}
|
||||
</AntTag>
|
||||
<span>{t('企业未对你设置配额上限')}</span>
|
||||
@@ -450,7 +450,7 @@ const OrgPersonalSettings = ({ orgId }) => {
|
||||
<div className='ui-profile-meta'>
|
||||
<div className='ui-profile-name'>
|
||||
<strong>{displayName || t('未设置')}</strong>
|
||||
<AntTag color='gold' bordered={false}>
|
||||
<AntTag color='gold' variant='filled'>
|
||||
{roleLabel(t, member.role)}
|
||||
</AntTag>
|
||||
</div>
|
||||
|
||||
@@ -20,17 +20,14 @@ import { Check as ActionCheck } from '@/components/common/icons/ActionIcons';
|
||||
import React, { useEffect, useState, useCallback, useMemo } from 'react';
|
||||
import { timestamp2string } from '../../helpers/utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Typography,
|
||||
Button,
|
||||
Spin,
|
||||
Table,
|
||||
Tag,
|
||||
InputNumber,
|
||||
Select,
|
||||
} from '@/components/ui';
|
||||
import { useThrottledCallback } from 'use-debounce';
|
||||
import { Typography, Button, Spin, Table, Tag, Select } from '@/components/ui';
|
||||
import { CheckCircle, Clock, XCircle } from 'lucide-react';
|
||||
import { Button as AntButton } from 'antd';
|
||||
import { Button as AntButton, Input as AntInput } from 'antd';
|
||||
import {
|
||||
MAX_CUSTOM_AMOUNT,
|
||||
normalizeCustomAmount,
|
||||
} from './customRechargeAmount';
|
||||
import {
|
||||
API,
|
||||
showError,
|
||||
@@ -82,6 +79,17 @@ const OrgRecharge = ({ orgId }) => {
|
||||
// 自定义充值(与预设档位互斥;自定义金额无折扣,原价到账)
|
||||
const [isCustomMode, setIsCustomMode] = useState(false);
|
||||
const [customAmount, setCustomAmount] = useState(null);
|
||||
const [customAmountExceeded, setCustomAmountExceeded] = useState(false);
|
||||
// Clamp the amount immediately; throttle feedback so payment state never lags.
|
||||
const reportCustomAmountExceeded = useThrottledCallback(
|
||||
() => setCustomAmountExceeded(true),
|
||||
200,
|
||||
{ leading: false, trailing: true },
|
||||
);
|
||||
const clearCustomAmountError = () => {
|
||||
reportCustomAmountExceeded.cancel();
|
||||
setCustomAmountExceeded(false);
|
||||
};
|
||||
const [customUnit, setCustomUnit] = useState(1000); // 1000=千 / 10000=万
|
||||
|
||||
const customEffectiveAmount = useMemo(() => {
|
||||
@@ -89,7 +97,11 @@ const OrgRecharge = ({ orgId }) => {
|
||||
return Math.floor(Number(customAmount)) * customUnit;
|
||||
}, [customAmount, customUnit]);
|
||||
|
||||
const customValid = customEffectiveAmount >= 1000;
|
||||
const customValid =
|
||||
Number.isInteger(customAmount) &&
|
||||
customAmount >= 1 &&
|
||||
customAmount <= MAX_CUSTOM_AMOUNT &&
|
||||
customEffectiveAmount >= 1000;
|
||||
|
||||
// 当前生效的金额/折扣/赠送(自定义优先)
|
||||
const effectiveAmountYuan = isCustomMode
|
||||
@@ -239,6 +251,7 @@ const OrgRecharge = ({ orgId }) => {
|
||||
}, []);
|
||||
|
||||
const selectPreset = (preset) => {
|
||||
clearCustomAmountError();
|
||||
setSelectedPreset(preset.id);
|
||||
setSelectedPresetObj(preset);
|
||||
setIsCustomMode(false);
|
||||
@@ -246,8 +259,15 @@ const OrgRecharge = ({ orgId }) => {
|
||||
};
|
||||
|
||||
const handleCustomAmountChange = (v) => {
|
||||
setCustomAmount(v);
|
||||
if (v && Number(v) > 0) {
|
||||
const result = normalizeCustomAmount(v);
|
||||
if (!result) return;
|
||||
if (result.exceeded) {
|
||||
reportCustomAmountExceeded();
|
||||
} else {
|
||||
clearCustomAmountError();
|
||||
}
|
||||
setCustomAmount(result.value);
|
||||
if (result.value) {
|
||||
setIsCustomMode(true);
|
||||
setSelectedPreset(null);
|
||||
setSelectedPresetObj(null);
|
||||
@@ -275,6 +295,7 @@ const OrgRecharge = ({ orgId }) => {
|
||||
];
|
||||
|
||||
const applyCustomQuickPick = (amount, unit) => {
|
||||
clearCustomAmountError();
|
||||
setCustomAmount(amount);
|
||||
setCustomUnit(unit);
|
||||
setIsCustomMode(true);
|
||||
@@ -616,16 +637,38 @@ const OrgRecharge = ({ orgId }) => {
|
||||
)}
|
||||
</h3>
|
||||
<div className='oc-rc-custom-input'>
|
||||
<InputNumber
|
||||
value={customAmount}
|
||||
onChange={handleCustomAmountChange}
|
||||
min={1}
|
||||
precision={0}
|
||||
hideButtons
|
||||
placeholder={t('请输入整数,如 1、5、10')}
|
||||
status={customInvalid ? 'error' : undefined}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
<div className='oc-rc-custom-field'>
|
||||
<AntInput
|
||||
value={customAmount ?? ''}
|
||||
onChange={(event) =>
|
||||
handleCustomAmountChange(event.target.value)
|
||||
}
|
||||
inputMode='numeric'
|
||||
pattern='[0-9]*'
|
||||
placeholder={t('请输入整数,如 1、5、10')}
|
||||
status={
|
||||
customAmountExceeded || customInvalid
|
||||
? 'error'
|
||||
: undefined
|
||||
}
|
||||
aria-invalid={customAmountExceeded || customInvalid}
|
||||
aria-describedby='org-recharge-custom-amount-error'
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
<div className='oc-rc-custom-feedback' aria-live='polite'>
|
||||
<span
|
||||
id='org-recharge-custom-amount-error'
|
||||
className={
|
||||
customAmountExceeded ? undefined : 'is-hidden'
|
||||
}
|
||||
aria-hidden={!customAmountExceeded}
|
||||
>
|
||||
<Text type='danger'>
|
||||
{t('输入数量不能超过 10000,已自动调整为 10000')}
|
||||
</Text>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<Select
|
||||
value={customUnit}
|
||||
onChange={handleCustomUnitChange}
|
||||
|
||||
@@ -782,7 +782,7 @@ const OrgSettings = ({ orgId, orgRole }) => {
|
||||
className='oc-cs-alert'
|
||||
type='error'
|
||||
showIcon
|
||||
message={t('配置加载失败,为防止误覆盖已有配置,编辑已禁用。')}
|
||||
title={t('配置加载失败,为防止误覆盖已有配置,编辑已禁用。')}
|
||||
action={
|
||||
<Button size='small' type='danger' onClick={fetchPromptCfg}>
|
||||
{t('重试')}
|
||||
|
||||
@@ -406,7 +406,7 @@ const OrgTokens = ({ orgId, orgRole }) => {
|
||||
className='oc-block-gap'
|
||||
type='info'
|
||||
showIcon
|
||||
message={t(
|
||||
title={t(
|
||||
'作为普通成员,您只能管理自己创建的密钥。管理员可管理所有密钥。',
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -637,7 +637,7 @@ const OrgAnalyticsPanel = ({
|
||||
<h2>{t('{{dim}}消费分布', { dim: dimLabel })}</h2>
|
||||
<span>{t('Top 10')}</span>
|
||||
</div>
|
||||
<AntTag bordered={false}>{t('按消费排序')}</AntTag>
|
||||
<AntTag variant='filled'>{t('按消费排序')}</AntTag>
|
||||
</div>
|
||||
{loading ? (
|
||||
<div className='oc-ea-loading'>
|
||||
|
||||
@@ -221,7 +221,7 @@ const OrgTaskRecords = () => {
|
||||
{/* 只有真实存在进行中任务时才显示,避免误导 */}
|
||||
{pageStats.pendingCount > 0 && (
|
||||
<Tag
|
||||
bordered={false}
|
||||
variant='filled'
|
||||
color='processing'
|
||||
icon={<Clock size={12} />}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
export const MAX_CUSTOM_AMOUNT = 10000;
|
||||
|
||||
export function normalizeCustomAmount(input) {
|
||||
if (input === '') return { value: null, exceeded: false };
|
||||
// Reject the whole edit so pasted decimals or signs cannot change its meaning.
|
||||
if (!/^[0-9]+$/.test(input)) return null;
|
||||
const value = Number(input);
|
||||
if (value === 0) return null;
|
||||
return {
|
||||
value: Math.min(value, MAX_CUSTOM_AMOUNT),
|
||||
exceeded: value > MAX_CUSTOM_AMOUNT,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user