mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 07:25:15 +00:00
fix(inputNumber): loss of accuracy in inputNumber (#3902)
* fix: inputNumber loss of accuracy * fix: bug * test: fix test * fix: test * fix: test
This commit is contained in:
parent
0544b8df45
commit
986dc85392
@ -12,8 +12,7 @@ type ComposedInputNumber = React.ForwardRefExoticComponent<
|
||||
export const InputNumber: ComposedInputNumber = connect((props) => {
|
||||
const { onChange, ...others } = props;
|
||||
const handleChange = (v) => {
|
||||
const result = parseFloat(v);
|
||||
onChange(Number.isNaN(result) ? null : result);
|
||||
onChange(Number.isNaN(v) ? null : v);
|
||||
};
|
||||
return <AntdNumber onChange={handleChange} {...others} />;
|
||||
}, mapReadPretty(ReadPretty));
|
||||
|
@ -38,7 +38,6 @@ export function formatNumberWithSeparator(number, format = '0.00', step = 1) {
|
||||
} else {
|
||||
formattedNumber = number.toString();
|
||||
}
|
||||
|
||||
return formattedNumber;
|
||||
}
|
||||
|
||||
@ -91,14 +90,13 @@ export function formatNumber(props) {
|
||||
if (!isValid(value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//单位换算
|
||||
const unitData = formatUnitConversion(value, unitConversionType, unitConversion);
|
||||
//精度换算
|
||||
const preciationData = toFixedByStep(unitData, step);
|
||||
let result;
|
||||
//分隔符换算
|
||||
result = formatNumberWithSeparator(Number(preciationData), separator, countDecimalPlaces(step));
|
||||
result = formatNumberWithSeparator(preciationData, separator, countDecimalPlaces(step));
|
||||
if (formatStyle === 'scientifix') {
|
||||
//科学计数显示
|
||||
result = scientificNotation(Number(unitData), countDecimalPlaces(step), separators?.[separator]?.['decimal']);
|
||||
@ -108,7 +106,6 @@ export function formatNumber(props) {
|
||||
|
||||
export const ReadPretty: React.FC<InputProps & InputNumberProps> = (props: any) => {
|
||||
const { step, formatStyle, value, addonBefore, addonAfter, unitConversion, unitConversionType, separator } = props;
|
||||
|
||||
const result = useMemo(() => {
|
||||
return formatNumber({ step, formatStyle, value, unitConversion, unitConversionType, separator });
|
||||
}, [step, formatStyle, value, unitConversion, unitConversionType, separator]);
|
||||
|
@ -703,7 +703,7 @@ test.describe('field data entry', () => {
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasPhone = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { staffnum: number }).staffnum === manualNodeRecord,
|
||||
(value) => (value as { staffnum: number }).staffnum == manualNodeRecord,
|
||||
);
|
||||
expect(hasPhone).toBe(true);
|
||||
|
||||
@ -842,7 +842,7 @@ test.describe('field data entry', () => {
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasRegcapital = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { regcapital: number }).regcapital === manualNodeRecord,
|
||||
(value) => (value as { regcapital: number }).regcapital == manualNodeRecord,
|
||||
);
|
||||
expect(hasRegcapital).toBe(true);
|
||||
|
||||
|
@ -719,13 +719,13 @@ test.describe('field data entry', () => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
const jobs = getWorkflowNodeExecutionsObj[0].jobs;
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() === manualNodeId);
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() == manualNodeId);
|
||||
const manualNodeJobStatus = manualNodeJob.status;
|
||||
expect(manualNodeJobStatus).toBe(1);
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasStaffnum = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { staffnum: number }).staffnum === manualNodeRecord,
|
||||
(value) => (value as { staffnum: number }).staffnum == manualNodeRecord,
|
||||
);
|
||||
expect(hasStaffnum).toBe(true);
|
||||
|
||||
@ -862,13 +862,13 @@ test.describe('field data entry', () => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
const jobs = getWorkflowNodeExecutionsObj[0].jobs;
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() === manualNodeId);
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() == manualNodeId);
|
||||
const manualNodeJobStatus = manualNodeJob.status;
|
||||
expect(manualNodeJobStatus).toBe(1);
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasRegcapital = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { regcapital: number }).regcapital === manualNodeRecord,
|
||||
(value) => (value as { regcapital: number }).regcapital == manualNodeRecord,
|
||||
);
|
||||
expect(hasRegcapital).toBe(true);
|
||||
|
||||
|
@ -836,13 +836,13 @@ test.describe('field data update', () => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
const jobs = getWorkflowNodeExecutionsObj[0].jobs;
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() === manualNodeId);
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() == manualNodeId);
|
||||
const manualNodeJobStatus = manualNodeJob.status;
|
||||
expect(manualNodeJobStatus).toBe(1);
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasStaffnum = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { staffnum: number }).staffnum === manualNodeRecord,
|
||||
(value) => (value as { staffnum: number }).staffnum == manualNodeRecord,
|
||||
);
|
||||
expect(hasStaffnum).toBe(true);
|
||||
|
||||
@ -1003,13 +1003,13 @@ test.describe('field data update', () => {
|
||||
return b.id - a.id;
|
||||
});
|
||||
const jobs = getWorkflowNodeExecutionsObj[0].jobs;
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() === manualNodeId);
|
||||
const manualNodeJob = jobs.find((job) => job.nodeId.toString() == manualNodeId);
|
||||
const manualNodeJobStatus = manualNodeJob.status;
|
||||
expect(manualNodeJobStatus).toBe(1);
|
||||
|
||||
const manualNodeJobResult = manualNodeJob.result;
|
||||
const hasRegcapital = Object.values(manualNodeJobResult).some(
|
||||
(value) => (value as { regcapital: number }).regcapital === manualNodeRecord,
|
||||
(value) => (value as { regcapital: number }).regcapital == manualNodeRecord,
|
||||
);
|
||||
expect(hasRegcapital).toBe(true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user