Commit c1620eb0 authored by 田翔's avatar 田翔

fix: 数值形态优化

parent e112ed28
{
"name": "panda-xform",
"version": "5.9.20",
"description": "5.9.20 只读修改",
"version": "5.9.21",
"description": "5.9.21 数值形态优化",
"keywords": [
"panda-xform"
],
......
......@@ -8,7 +8,7 @@ import React, { useMemo, useContext, forwardRef, useImperativeHandle, useState,
import FormRender, { useForm } from 'form-render'
import { ConfigProvider, Spin } from 'antd'
import widgets from '../widgets'
import { isObject } from '../../utils'
import { isObject, getFieldInfo } from '../../utils'
import { getWatch } from './watch'
import styles from '../../main.less'
......@@ -108,12 +108,20 @@ const XRender = (props, ref) => {
}, [schemaForm, form, startTime, initField])
const getValues = async () => {
const info = getFieldInfo(schemaForm)
let { data, errors } = await form.submit()
let formValue = []
Object.keys(data).map((k) => {
if (isObject(data[k]) && !['relationForm'].includes(k)) {
Object.keys(data[k]).map((key) => {
formValue.push({ fieldName: key, fieldValue: data[k][key] + '' })
let value = data[k][key] + ''
if (info?.[key]) {
const { widget, formatter, decimalDigits } = info?.[key]
if (widget === 'NumberInput' && formatter === '${小数}' && value) {
value = Number(value).toFixed(Number(decimalDigits))
}
}
formValue.push({ fieldName: key, fieldValue: value })
})
}
})
......
......@@ -6,8 +6,8 @@
* @FilePath: \xform\src\core\widgets\text\NumberInput\index.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import React, { useEffect, useMemo, useState } from 'react'
import { InputNumber } from 'antd'
import React, { useEffect, useMemo, useState, useCallback } from 'react'
import { InputNumber, Input } from 'antd'
import styles from './index.less'
function formatMoney(number, places, symbol, thousand, decimal) {
......@@ -36,7 +36,7 @@ const NumberInput = (props) => {
}
}, [presetValue])
const inputChange = (value) => {
const numberChange = (value) => {
if (addons) {
if (value !== null) {
onChange(`${value}`)
......@@ -46,6 +46,12 @@ const NumberInput = (props) => {
}
}
const inputChange = (e) => {
let inputValue = e.target.value
inputValue.replace(/[^\d.]/g, '')
onChange(inputValue)
}
const formatterFn = (value) => {
if (value) {
if (formatter === '${百分比}') {
......@@ -56,17 +62,30 @@ const NumberInput = (props) => {
return `${parseInt(value)}`
} else if (formatter === '${小数}') {
return Number(value).toFixed(Number(decimalDigits))
}
else if(formatter === '${科学计数法}'){
} else if (formatter === '${科学计数法}') {
return Number(value).toExponential()
}
else if (formatter) {
} else if (formatter) {
return `${value}${formatter}`
}
}
return value
}
if (formatter === '${小数}') {
return (
<div className={styles.textInput} isdisabled={JSON.stringify(disabled)}>
<Input
disabled={disabled}
value={value ? `${value}` : ''}
placeholder={disabled ? (placeholder || '') : (placeholder || '请输入内容')}
onChange={inputChange}
addonBefore={addonBefore}
addonAfter={addonAfter}
/>
</div>
)
}
return (
<div className={styles.inputNumber} isdisabled={JSON.stringify(disabled)}>
<InputNumber
......@@ -80,7 +99,7 @@ const NumberInput = (props) => {
disabled={disabled}
value={value === '' ? null : Number(value)}
formatter={formatterFn}
onChange={inputChange}
onChange={numberChange}
style={{ width: '100%' }}
/>
</div>
......
......@@ -5,4 +5,11 @@
border: 1px solid #e9e9e9;
}
}
}
.textInput {
&[isdisabled='true'] {
.@{ant-prefix}-input-group-addon {
border: 1px solid #e9e9e9;
}
}
}
\ No newline at end of file
......@@ -150,7 +150,7 @@ export const isObject = (obj) => typeof obj === 'object'
export const isArray = (array) => Array.isArray(array) && array.length
//防抖
export const debounce = (fn) => {
export const debounce = (fn, wait = 300) => {
let t = null
return function (e) {
const context = this
......@@ -162,7 +162,7 @@ export const debounce = (fn) => {
if (typeof fn === 'function') {
fn.call(context, ...args)
}
}, 300)
}, wait)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment