mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:58:07 +08:00
fix: InputNumber输入值带单位时渲染错误问题 (#5268)
This commit is contained in:
parent
8bd11effcd
commit
cdb8211f90
@ -26,11 +26,12 @@ order: 32
|
||||
|
||||
## 设置精度
|
||||
|
||||
`precision` 设置数字的显示精度,一般需要配合`step`属性使用,以实现细粒度调整。
|
||||
`precision` 设置数字的显示精度,一般需要配合`step`属性使用,以实现细粒度调整。注意带有单位的输入不支持配置精度属性。
|
||||
|
||||
```schema: scope="body"
|
||||
{
|
||||
"type": "form",
|
||||
"debug": true,
|
||||
"api": "/api/mock2/form/saveForm",
|
||||
"data": {
|
||||
"number2": 3.1234
|
||||
|
@ -146,15 +146,23 @@ export default class NumberControl extends React.Component<
|
||||
const {formItem, setPrinstineValue, precision, value} = props;
|
||||
const normalizedPrecision = this.filterNum(precision);
|
||||
|
||||
/** 如果设置了precision需要处理入参value的精度 */
|
||||
if (formItem && value != null && normalizedPrecision != null) {
|
||||
const normalizedValue = toFixed(
|
||||
value.toString(),
|
||||
'.',
|
||||
normalizedPrecision
|
||||
/**
|
||||
* 如果设置了precision需要处理入参value的精度
|
||||
* 如果是带有单位的输入,则不支持精度处理
|
||||
*/
|
||||
if (
|
||||
formItem &&
|
||||
value != null &&
|
||||
normalizedPrecision != null &&
|
||||
(!unit || unitOptions.length === 0)
|
||||
) {
|
||||
const normalizedValue = parseFloat(
|
||||
toFixed(value.toString(), '.', normalizedPrecision)
|
||||
);
|
||||
|
||||
setPrinstineValue(parseFloat(normalizedValue));
|
||||
if (!isNaN(normalizedValue)) {
|
||||
setPrinstineValue(normalizedValue);
|
||||
}
|
||||
}
|
||||
|
||||
this.state = {unit, unitOptions};
|
||||
@ -265,10 +273,15 @@ export default class NumberControl extends React.Component<
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: NumberProps) {
|
||||
if (this.props.value !== prevProps.value) {
|
||||
if (
|
||||
!isNaN(this.props.value) &&
|
||||
!isNaN(prevProps.value) &&
|
||||
this.props.value !== prevProps.value
|
||||
) {
|
||||
const unit = this.getUnit();
|
||||
this.setState({unit: unit});
|
||||
}
|
||||
|
||||
if (this.props.unitOptions !== prevProps.unitOptions) {
|
||||
this.setState({unitOptions: normalizeOptions(this.props.unitOptions)});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user