Commit 489c989c authored by 田翔's avatar 田翔

fix: 关联表单计算监听逻辑添加

parent ed3ea722
This diff is collapsed.
import React, { useState, useEffect, useRef } from 'react'; import React, { useState, useEffect, useRef } from 'react';
import { FormRender, FormDesigner } from '../../src/index'; import { FormRender, FormDesigner } from '../../src/index';
import { options1, options2 } from './data'; import { schemaValues } from './data';
import { Button, Tabs } from 'antd'; import { Button, Tabs } from 'antd';
window.globalConfig = { window.globalConfig = {
...@@ -3509,7 +3509,11 @@ window.globalConfig = { ...@@ -3509,7 +3509,11 @@ window.globalConfig = {
const Test = (props) => { const Test = (props) => {
return ( return (
<FormDesigner tableName='事件_测试02' /> // <FormDesigner tableName='工单_维修填报' />
// <FormDesigner tableName='事件_表单测试表' />
<FormRender
schemaValues={schemaValues}
/>
) )
} }
......
...@@ -28,7 +28,9 @@ app.use(['/admin', '/manager'], admin); ...@@ -28,7 +28,9 @@ app.use(['/admin', '/manager'], admin);
app.use(webpackHotMiddleware(compiler)); app.use(webpackHotMiddleware(compiler));
app.use(express.static(__dirname)); app.use(express.static(__dirname));
// app.use('/', createProxyMiddleware('/', { target: 'http://127.0.0.1:8880', changeOrigin: true })); // app.use('/', createProxyMiddleware('/', { target: 'http://127.0.0.1:8880', changeOrigin: true }));
app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.167:8088/', changeOrigin: true })); app.use('/', createProxyMiddleware('/', { target: 'http://192.168.12.178:8085', changeOrigin: true }));
// app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.167:8083', changeOrigin: true }));
// app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.167:8088/', changeOrigin: true }));
// app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.178:8082', changeOrigin: true })); // app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.178:8082', changeOrigin: true }));
// app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.167:8088/', changeOrigin: true })); // app.use('/', createProxyMiddleware('/', { target: 'http://192.168.10.167:8088/', changeOrigin: true }));
const port = process.env.PORT || 8888; const port = process.env.PORT || 8888;
......
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.2.9", "version": "2.3.0",
"description": "2.2.9: 各个形态组件不做数据类型校验统一使用字符串处理", "description": "2.3.0: 关联表单计算监听逻辑添加",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -220,7 +220,10 @@ const FormDesigner = (props, ref) => { ...@@ -220,7 +220,10 @@ const FormDesigner = (props, ref) => {
</div> </div>
} }
> >
<FormRender ref={formRenderRef} schemaValues={{ formJson: schema }} extraData={{ codes: { '事件编号': '123123' } }} /> <FormRender
ref={formRenderRef}
schemaValues={{ formJson: schema }}
/>
</Drag> </Drag>
</div> </div>
</div> </div>
......
...@@ -97,6 +97,7 @@ const getFieldName = (configs, tableName) => { ...@@ -97,6 +97,7 @@ const getFieldName = (configs, tableName) => {
} }
const automaticComputation = async (params) => { const automaticComputation = async (params) => {
console.log('form.getValues()', params?.form?.getValues())
if ((new Date().getTime() - params.startTime) < 1000) return if ((new Date().getTime() - params.startTime) < 1000) return
let param = { let param = {
tableName: params.tableName, tableName: params.tableName,
......
...@@ -20,10 +20,6 @@ const BaseForm = (props, ref) => { ...@@ -20,10 +20,6 @@ const BaseForm = (props, ref) => {
const form = useForm() const form = useForm()
const [startTime, setStartTime] = useState(new Date().getTime()) const [startTime, setStartTime] = useState(new Date().getTime())
const watch = useMemo(() => {
return getWatch(schemaForm, form, startTime)
}, [schemaForm, form, startTime])
//表单需要显示的字段 //表单需要显示的字段
const field = useMemo(() => { const field = useMemo(() => {
const { fieldGroup, editFieldGroup, addFieldGroup } = config const { fieldGroup, editFieldGroup, addFieldGroup } = config
...@@ -67,11 +63,15 @@ const BaseForm = (props, ref) => { ...@@ -67,11 +63,15 @@ const BaseForm = (props, ref) => {
return { ...group, properties: parentObj } return { ...group, properties: parentObj }
}, [schemaForm, field, formState]) }, [schemaForm, field, formState])
const watch = useMemo(() => {
return getWatch(schema, form, startTime)
}, [schema, form, startTime])
const getValues = async () => { const getValues = async () => {
let { data, errors } = await form.submit() let { data, errors } = await form.submit()
let formValue = [] let formValue = []
Object.keys(data).map((k) => { Object.keys(data).map((k) => {
if (isObject(data[k]) && ['relationForm'].includes(k)) { if (isObject(data[k]) && !['relationForm'].includes(k)) {
Object.keys(data[k]).map((key) => { Object.keys(data[k]).map((key) => {
formValue.push({ fieldName: key, fieldValue: data[k][key] + '' }) formValue.push({ fieldName: key, fieldValue: data[k][key] + '' })
}) })
......
...@@ -4,10 +4,11 @@ import date from '../../../date' ...@@ -4,10 +4,11 @@ import date from '../../../date'
import select from '../../../select' import select from '../../../select'
import business from '../../../business' import business from '../../../business'
import file from '../../../file' import file from '../../../file'
import Signature from '../../Signature' import coord from '../../../coord'
import AutoCalculate from '../../AutoCalculate'
const coord = { const advanced = {
Signature AutoCalculate
} }
const widgets = { const widgets = {
...@@ -18,6 +19,7 @@ const widgets = { ...@@ -18,6 +19,7 @@ const widgets = {
...business, ...business,
...file, ...file,
...coord, ...coord,
...advanced,
} }
export default widgets export default widgets
\ No newline at end of file
...@@ -91,7 +91,6 @@ const RelationForm = (props) => { ...@@ -91,7 +91,6 @@ const RelationForm = (props) => {
const getFieldValue = (s, formDataObj, codes) => { const getFieldValue = (s, formDataObj, codes) => {
return codes ? (codes[s.fromField] || formDataObj[s.fromField]) : formDataObj[s.fromField] return codes ? (codes[s.fromField] || formDataObj[s.fromField]) : formDataObj[s.fromField]
} }
console.log('field', field)
field.forEach(v => { field.forEach(v => {
mappedField.forEach(s => { mappedField.forEach(s => {
if (s.toField === v) { if (s.toField === v) {
...@@ -231,7 +230,7 @@ const RelationForm = (props) => { ...@@ -231,7 +230,7 @@ const RelationForm = (props) => {
const { code, data, msg } = await GetTableJson(accountName) const { code, data, msg } = await GetTableJson(accountName)
if (code === 0) { if (code === 0) {
if (data && typeof data === 'string') { if (data && typeof data === 'string') {
setSchemaGroup(JSON.parse(data)) setSchemaGroup(JSON.parse(aa))
} }
} else { } else {
message.error(msg) message.error(msg)
...@@ -259,7 +258,6 @@ const RelationForm = (props) => { ...@@ -259,7 +258,6 @@ const RelationForm = (props) => {
const getTableData = async (addFieldGroup) => { const getTableData = async (addFieldGroup) => {
if (!addons) return if (!addons) return
let queryWheres = getQueryWheres(addFieldGroup) let queryWheres = getQueryWheres(addFieldGroup)
console.log('queryWheres', queryWheres)
if (!queryWheres.length) { if (!queryWheres.length) {
message.info('映射字段配置错误!') message.info('映射字段配置错误!')
} }
...@@ -355,7 +353,7 @@ const RelationForm = (props) => { ...@@ -355,7 +353,7 @@ const RelationForm = (props) => {
}, []) }, [])
return ( return (
<div className={styles.relationForm} style={{ display: (!addons || show) ? 'block' : 'none' }}> <div className={styles.relationForm} style={{ display: (addons && !show) ? 'none' : 'block' }}>
<div className={styles.header}> <div className={styles.header}>
<span className='account-header-title'>{titleShow}</span> <span className='account-header-title'>{titleShow}</span>
{disabled ? null : <Button className={styles.headerBtn} type='primary' size='middle' icon={<PlusOutlined />} onClick={addClick}>添加</Button>} {disabled ? null : <Button className={styles.headerBtn} type='primary' size='middle' icon={<PlusOutlined />} onClick={addClick}>添加</Button>}
......
...@@ -9,20 +9,14 @@ const DateTime = (props) => { ...@@ -9,20 +9,14 @@ const DateTime = (props) => {
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { disabled, format, presetValue, placeholder, options, currentDate, defaultCurrent } = schema const { disabled, format, presetValue, placeholder, options, currentDate, defaultCurrent } = schema
const valueShow = useMemo(() => {
if (options === '默认为当前时间') {
return (value || new Date()) ? moment(value || new Date()) : null
}
return value ? moment(value) : null
}, [defaultCurrent, value])
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, presetValue) let value = presetValue || (options === '默认为当前时间' ? moment(new Date()).format('YYYY-MM-DD HH:ss:mm') : null)
addons.setValue(addons.dataPath, value)
} else { } else {
onChange(presetValue) onChange(presetValue)
} }
}, [presetValue]) }, [presetValue, options])
const disabledDate = (current) => { const disabledDate = (current) => {
if (options === '不超过当前时间') { if (options === '不超过当前时间') {
...@@ -46,7 +40,7 @@ const DateTime = (props) => { ...@@ -46,7 +40,7 @@ const DateTime = (props) => {
picker={format} picker={format}
disabled={disabled} disabled={disabled}
placeholder={placeholder} placeholder={placeholder}
value={valueShow} value={value ? moment(value) : null}
onChange={dateChange} onChange={dateChange}
showNow showNow
showTime={format === 'dateTime'} showTime={format === 'dateTime'}
......
...@@ -8,13 +8,6 @@ const Time = (props) => { ...@@ -8,13 +8,6 @@ const Time = (props) => {
const { value, onChange, schema, addons } = props const { value, onChange, schema, addons } = props
const { presetValue, currentDate, defaultCurrent, options } = schema const { presetValue, currentDate, defaultCurrent, options } = schema
const valueShow = useMemo(() => {
if (options === '默认为当前时间') {
return (value || new Date()) ? moment(value || new Date(), 'HH:mm:ss') : null
}
return value ? moment(value, 'HH:mm:ss') : null
}, [value, defaultCurrent])
const disabledDate = (current) => { const disabledDate = (current) => {
if (options === '不超过当前时间') { if (options === '不超过当前时间') {
return current && current.format('HH:mm:ss') > moment().format('HH:mm:ss') return current && current.format('HH:mm:ss') > moment().format('HH:mm:ss')
...@@ -29,16 +22,17 @@ const Time = (props) => { ...@@ -29,16 +22,17 @@ const Time = (props) => {
useEffect(() => { useEffect(() => {
if (addons) { if (addons) {
addons.setValue(addons.dataPath, presetValue) let value = presetValue || (options === '默认为当前时间' ? moment(new Date()).format('HH:mm:ss') : null)
addons.setValue(addons.dataPath, value)
} else { } else {
onChange(presetValue) onChange(presetValue)
} }
}, [presetValue]) }, [presetValue, options])
return ( return (
<TimePicker <TimePicker
style={{ width: '100%' }} style={{ width: '100%' }}
value={valueShow} value={value ? moment(value, 'HH:mm:ss') : null}
onChange={timeChange} onChange={timeChange}
disabledDate={disabledDate} disabledDate={disabledDate}
locale={locale} locale={locale}
......
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