Commit 16a4f1b2 authored by 田翔's avatar 田翔

fix: 关联表单自动计算偶发性参数缺失问题

parent 2bb0f57a
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "5.1.6", "version": "5.1.7",
"description": "5.1.6 关联表单优化", "description": "5.1.7 关联表单自动计算偶发性参数缺失问题",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -390,6 +390,10 @@ const FormDesigner = (props, ref) => { ...@@ -390,6 +390,10 @@ const FormDesigner = (props, ref) => {
<FormRender <FormRender
ref={formRenderRef} ref={formRenderRef}
schemaValues={{ formJson: schema }} schemaValues={{ formJson: schema }}
// codes={{
// 工单编号: '12421413431',
// 事件编号: 'PO230000013',
// }}
/> />
</Drag> </Drag>
</div> </div>
......
...@@ -12,8 +12,6 @@ import { isObject } from '../../utils' ...@@ -12,8 +12,6 @@ import { isObject } from '../../utils'
import { getWatch } from './watch' import { getWatch } from './watch'
import styles from '../../main.less' import styles from '../../main.less'
let watchFns = {}
const XRender = (props, ref) => { const XRender = (props, ref) => {
useImperativeHandle(ref, () => ( useImperativeHandle(ref, () => (
...@@ -91,8 +89,7 @@ const XRender = (props, ref) => { ...@@ -91,8 +89,7 @@ const XRender = (props, ref) => {
}, [formJson, values, disabledFields, disabled]) }, [formJson, values, disabledFields, disabled])
const watch = useMemo(() => { const watch = useMemo(() => {
watchFns = getWatch({ schema: schemaForm, form, startTime, initField }) return getWatch({ schema: schemaForm, form, startTime, initField })
return watchFns
}, [schemaForm, form, startTime, initField]) }, [schemaForm, form, startTime, initField])
const getValues = async () => { const getValues = async () => {
...@@ -113,15 +110,7 @@ const XRender = (props, ref) => { ...@@ -113,15 +110,7 @@ const XRender = (props, ref) => {
} }
//初始化时存储外部传的额外数据 //初始化时存储外部传的额外数据
const onMount = () => { const onMount = () => { }
setTimeout(() => {
if (isObject(watchFns)) {
for (let key in watchFns) {
watchFns?.[key]()
}
}
}, 1500)
}
return ( return (
<div className={styles.pandaXform}> <div className={styles.pandaXform}>
......
...@@ -155,37 +155,28 @@ const RelationForm = (props) => { ...@@ -155,37 +155,28 @@ const RelationForm = (props) => {
let { code, data, msg } = await GetAccountConfigInfo(accountName) let { code, data, msg } = await GetAccountConfigInfo(accountName)
if (code === 0) { if (code === 0) {
setConfig({ ...data, formJson: isJson(data.formJson) ? JSON.parse(data.formJson) : {} }) setConfig({ ...data, formJson: isJson(data.formJson) ? JSON.parse(data.formJson) : {} })
getTableData(data.addFieldGroup ? data.addFieldGroup.split(',') : []) const queryWheres = getQueryWheres()
getTableData(queryWheres)
} else { } else {
message.error(msg) message.error(msg)
} }
} }
const getQueryWheres = (addFieldGroup) => { const getQueryWheres = () => {
let queryWheres = [] let queryWheres = []
let formDataObj = getFormDataObj(addons?.formData)
addFieldGroup.forEach(v => {
if (Array.isArray(mappedField)) { if (Array.isArray(mappedField)) {
mappedField.forEach(s => { let formDataObj = getFormDataObj(addons?.formData)
if (s.toField === v) { mappedField.forEach(v => {
queryWheres.push({ field: s.toField, type: '等于', value: codes ? (codes[s.fromField] || formDataObj[s.fromField]) : formDataObj[s.fromField] }) queryWheres.push({ field: v.toField, type: '等于', value: codes[v.fromField] || formDataObj[v.fromField] })
}
}) })
} }
})
let relationForm = addons.getValue('relationForm') || { configs: [], data: [] } let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
relationForm?.configs.forEach(v => { addons.setValueByPath('relationForm', { ...relationForm, configs: [...relationForm.configs, { ...schema, queryWheres }] })
v.queryWheres = queryWheres.map(v => { return { fieldName: v.field, fieldValue: v.value } })
})
return queryWheres return queryWheres
} }
const getTableData = async (addFieldGroup) => { const getTableData = async (queryWheres) => {
if (!addons) return if (!addons) return
let queryWheres = getQueryWheres(addFieldGroup)
if (!queryWheres.length) {
message.info('映射字段配置错误!')
}
let params = { let params = {
user: userID, user: userID,
accountName: accountName, accountName: accountName,
...@@ -430,16 +421,22 @@ const RelationForm = (props) => { ...@@ -430,16 +421,22 @@ const RelationForm = (props) => {
} }
useEffect(() => { useEffect(() => {
if (accountName) {
getData()
}
}, [accountName])
useLayoutEffect(() => {
//初始化关联表单配置信息,初始显示隐藏 //初始化关联表单配置信息,初始显示隐藏
if (addons) { if (addons) {
let relationForm = addons.getValue('relationForm') || { configs: [], data: [] } getData()
addons.setValue('relationForm', { ...relationForm, configs: [...relationForm.configs, schema] }) // console.log('addons', addons)
// setTimeout(() => {
// let queryWheres = []
// if (Array.isArray(mappedField)) {
// let formDataObj = getFormDataObj(addons?.formData)
// mappedField.forEach(v => {
// queryWheres.push({ field: v.toField, type: '等于', value: codes[v.fromField] || formDataObj[v.fromField] })
// })
// }
// let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
// addons.setValueByPath('relationForm', { ...relationForm, configs: [...relationForm.configs, { ...schema, queryWheres }] })
// }, 0)
} }
}, []) }, [])
......
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