Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -8,6 +8,8 @@ function CountUp({ value, prefix = '', suffix = '', decimals = 2, className = ''
|
|||||||
const [displayValue, setDisplayValue] = useState(value);
|
const [displayValue, setDisplayValue] = useState(value);
|
||||||
const previousValue = useRef(value);
|
const previousValue = useRef(value);
|
||||||
const isFirstChange = useRef(true);
|
const isFirstChange = useRef(true);
|
||||||
|
const rafIdRef = useRef(null);
|
||||||
|
const displayValueRef = useRef(value);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (previousValue.current === value) return;
|
if (previousValue.current === value) return;
|
||||||
@@ -15,13 +17,14 @@ function CountUp({ value, prefix = '', suffix = '', decimals = 2, className = ''
|
|||||||
if (isFirstChange.current) {
|
if (isFirstChange.current) {
|
||||||
isFirstChange.current = false;
|
isFirstChange.current = false;
|
||||||
previousValue.current = value;
|
previousValue.current = value;
|
||||||
|
displayValueRef.current = value;
|
||||||
setDisplayValue(value);
|
setDisplayValue(value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const start = previousValue.current;
|
const start = displayValueRef.current;
|
||||||
const end = value;
|
const end = value;
|
||||||
const duration = 400;
|
const duration = 300;
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
|
|
||||||
const animate = (currentTime) => {
|
const animate = (currentTime) => {
|
||||||
@@ -29,16 +32,25 @@ function CountUp({ value, prefix = '', suffix = '', decimals = 2, className = ''
|
|||||||
const progress = Math.min(elapsed / duration, 1);
|
const progress = Math.min(elapsed / duration, 1);
|
||||||
const ease = 1 - Math.pow(1 - progress, 4);
|
const ease = 1 - Math.pow(1 - progress, 4);
|
||||||
const current = start + (end - start) * ease;
|
const current = start + (end - start) * ease;
|
||||||
|
displayValueRef.current = current;
|
||||||
setDisplayValue(current);
|
setDisplayValue(current);
|
||||||
|
|
||||||
if (progress < 1) {
|
if (progress < 1) {
|
||||||
requestAnimationFrame(animate);
|
rafIdRef.current = requestAnimationFrame(animate);
|
||||||
} else {
|
} else {
|
||||||
previousValue.current = value;
|
previousValue.current = value;
|
||||||
|
rafIdRef.current = null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
requestAnimationFrame(animate);
|
rafIdRef.current = requestAnimationFrame(animate);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (rafIdRef.current != null) {
|
||||||
|
cancelAnimationFrame(rafIdRef.current);
|
||||||
|
rafIdRef.current = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ export default function TradeModal({ type, fund, holding, onClose, onConfirm, pe
|
|||||||
};
|
};
|
||||||
|
|
||||||
const isValid = isBuy
|
const isValid = isBuy
|
||||||
? (!!amount && !!feeRate && !!date && calcShare !== null && !loadingBuyMeta && (parseFloat(amount) || 0) >= (Number(minBuyAmount) || 0))
|
? (!!amount && !!feeRate && !!date && calcShare !== null && !loadingBuyMeta)
|
||||||
: (!!share && !!date);
|
: (!!share && !!date);
|
||||||
|
|
||||||
const handleSetShareFraction = (fraction) => {
|
const handleSetShareFraction = (fraction) => {
|
||||||
@@ -434,9 +434,7 @@ export default function TradeModal({ type, fund, holding, onClose, onConfirm, pe
|
|||||||
</label>
|
</label>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
border: (!amount || (Number(minBuyAmount) > 0 && (parseFloat(amount) || 0) < Number(minBuyAmount)))
|
border: !amount ? '1px solid var(--danger)' : '1px solid var(--border)',
|
||||||
? '1px solid var(--danger)'
|
|
||||||
: '1px solid var(--border)',
|
|
||||||
borderRadius: 12
|
borderRadius: 12
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
@@ -444,15 +442,10 @@ export default function TradeModal({ type, fund, holding, onClose, onConfirm, pe
|
|||||||
value={amount}
|
value={amount}
|
||||||
onChange={setAmount}
|
onChange={setAmount}
|
||||||
step={100}
|
step={100}
|
||||||
min={Number(minBuyAmount) || 0}
|
min={0}
|
||||||
placeholder={(Number(minBuyAmount) || 0) > 0 ? `最少 ¥${Number(minBuyAmount)},请输入加仓金额` : '请输入加仓金额'}
|
placeholder="请输入加仓金额"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{(Number(minBuyAmount) || 0) > 0 && (
|
|
||||||
<div className="muted" style={{ fontSize: '12px', marginTop: 6 }}>
|
|
||||||
最小加仓金额:¥{Number(minBuyAmount)}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="row" style={{ gap: 12, marginBottom: 16 }}>
|
<div className="row" style={{ gap: 12, marginBottom: 16 }}>
|
||||||
|
|||||||
Reference in New Issue
Block a user