Commit e18b4890 authored by 田翔's avatar 田翔

fix: 自动计算形态默认值设置,支持传值渲染

parent 5be43907
{
"name": "panda-xform",
"version": "2.1.0",
"description": "2.1.0: 关联表单计算树形",
"version": "2.1.1",
"description": "2.1.1: 自动计算形态默认值设置,支持传值渲染",
"keywords": [
"panda-xform"
],
......
......@@ -2877,7 +2877,7 @@ const advancedWidgets = [
name: '自动计算',
schema: {
title: '自动计算',
type: 'string',
type: 'number',
widget: 'AutoCalculate',
},
setting: {
......@@ -2902,13 +2902,12 @@ const advancedWidgets = [
displayType: 'row',
labelWidth: 80,
},
placeholder: {
title: '提示语',
type: 'string',
displayType: 'row',
labelWidth: 80,
// default: '该组件用于自动计算'
},
// placeholder: {
// title: '提示语',
// type: 'string',
// displayType: 'row',
// labelWidth: 80,
// },
presetValue: {
title: '默认值',
type: 'number',
......
......@@ -220,7 +220,7 @@ const FormDesigner = (props, ref) => {
</div>
}
>
<FormRender ref={formRenderRef} schema={schema} />
<FormRender ref={formRenderRef} schemaValues={{ schema }} />
</Drag>
</div>
</div>
......
......@@ -15,16 +15,46 @@ const XRender = (props, ref) => {
}
))
const { schema } = props
const { schemaValues } = props
const { schema, values } = schemaValues
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext)
const prefixCls = getPrefixCls('pandaXform')
const pandaXform = getPrefixCls()
const [startTime, setStartTime] = useState(new Date().getTime())
const form = useForm()
const schemaForm = useMemo(() => {
if (Array.isArray(values)) {
let parent = schema?.properties
let parentObj = {}
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
let childObj = {}
if (isObject(child)) {
for (let s in child) {
let value = ''
values.forEach(v => {
if (v.fieldName === s) {
value = v.fieldValue
}
})
childObj[s] = { ...child[s], presetValue: value || child[s].presetValue }
}
}
if (JSON.stringify(childObj) !== '{}') {
parentObj[v] = { ...parent[v], properties: childObj }
}
}
}
return { ...schema, properties: parentObj }
}
return schema
}, [schema, values])
const watch = useMemo(() => {
return getWatch(schema, form, startTime)
}, [schema, form, startTime])
}, [schemaForm, form, startTime])
const getValues = async () => {
let { data, errors } = await form.submit()
......@@ -48,7 +78,7 @@ const XRender = (props, ref) => {
<FormRender
configProvider={{ prefixCls: pandaXform }}
form={form}
schema={schema}
schema={schemaForm}
mapping={{
object: 'Header',
}}
......
import React from 'react'
import React, { useEffect } from 'react'
import { InputNumber } from 'antd'
const AutoCalculate = (props) => {
const { value, onChange, schema, addons } = props
const { disabled } = schema
const { disabled, presetValue } = schema
useEffect(() => {
onChange(presetValue)
}, [presetValue])
return (
<InputNumber
value={value}
value={Number(value)}
style={{ width: '100%' }}
disabled={disabled}
>
......
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