feat: 1.升级 Ant Design Ui 至 v6 2. 修复企业充值金额输入限制
This commit is contained in:
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user