Commit 7f20709b authored by 田翔's avatar 田翔

fix: 监听所有关联表单

parent bc8b1051
{ {
"name": "panda-xform", "name": "panda-xform",
"version": "2.3.1", "version": "2.3.2",
"description": "2.3.1: bug修复", "description": "2.3.2: 监听所有关联表单",
"keywords": [ "keywords": [
"panda-xform" "panda-xform"
], ],
......
...@@ -69,6 +69,24 @@ const getRules = (json) => { ...@@ -69,6 +69,24 @@ const getRules = (json) => {
return AutoCalculate return AutoCalculate
} }
const getRelationFormPath = (json) => {
let RelationFormPath = []
let parent = json?.properties
if (isObject(parent)) {
for (let v in parent) {
let child = parent[v]?.properties
if (isObject(child)) {
for (let s in child) {
if (child[s].widget === 'RelationForm') {
RelationFormPath.push(`${v}.${s}`)
}
}
}
}
}
return RelationFormPath
}
const getPath = (json, filed) => { const getPath = (json, filed) => {
let parent = json?.properties let parent = json?.properties
if (isObject(parent)) { if (isObject(parent)) {
...@@ -97,7 +115,6 @@ const getFieldName = (configs, tableName) => { ...@@ -97,7 +115,6 @@ 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,
...@@ -125,20 +142,21 @@ const setValue = debounce(automaticComputation) ...@@ -125,20 +142,21 @@ const setValue = debounce(automaticComputation)
export const getWatch = (schema, form, startTime) => { export const getWatch = (schema, form, startTime) => {
let watch = {} let watch = {}
let { relationForm } = form?.getValues() let { relationForm } = form?.getValues()
const configs = relationForm?.configs || []
const AutoCalculate = getRules(schema) const AutoCalculate = getRules(schema)
const RelationFormPath = getRelationFormPath(schema)
if (Array.isArray(AutoCalculate)) { if (Array.isArray(AutoCalculate)) {
AutoCalculate.forEach(item => { AutoCalculate.forEach(item => {
const { filedName, rules, calculateRule } = item const { filedName, rules, calculateRule } = item
let paths = [] let paths = RelationFormPath
if (Array.isArray(rules)) { if (Array.isArray(rules)) {
rules.forEach(s => { rules.forEach(s => {
let item = { tableName: null, fields: [] } let item = { tableName: null, fields: [] }
if (schema.tableName === s.tableName) { if (schema.tableName === s.tableName) {
item = s item = s
} else { } else {
item = { fields: getFieldName(configs, s.tableName) } // item = { fields: getFieldName(configs, s.tableName) }
} }
console.log('item', item)
if (item) { if (item) {
if (Array.isArray(item.fields)) { if (Array.isArray(item.fields)) {
item.fields.forEach(v => { item.fields.forEach(v => {
...@@ -169,6 +187,7 @@ export const getWatch = (schema, form, startTime) => { ...@@ -169,6 +187,7 @@ export const getWatch = (schema, form, startTime) => {
} }
}) })
} }
console.log('watch', watch)
return watch return watch
} }
......
...@@ -308,11 +308,16 @@ const RelationForm = (props) => { ...@@ -308,11 +308,16 @@ const RelationForm = (props) => {
} }
}) })
setDataSource(array) setDataSource(array)
onChange(`${array.length}`) setTimeout(() => {
onChange(`${array.length}`)
}, 0)
} else if (formStateStr === '添加') { } else if (formStateStr === '添加') {
let array = [getItem(formValue), ...dataSource] let array = [getItem(formValue), ...dataSource]
setDataSource(array) setDataSource(array)
onChange(`${array.length}`) setTimeout(() => {
onChange(`${array.length}`)
}, 0)
} }
let relationForm = addons.getValue('relationForm') || { configs: [], data: [] } let relationForm = addons.getValue('relationForm') || { configs: [], data: [] }
let listArray = relationForm.data.filter(v => v.id !== itemData.id) let listArray = relationForm.data.filter(v => v.id !== itemData.id)
......
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