Skip to content

Commit

Permalink
fix: 修复带.多层级在使用editDefaultValue时赋值无效
Browse files Browse the repository at this point in the history
  • Loading branch information
kanyxmo committed Aug 2, 2024
1 parent de2c0c5 commit d721788
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/components/ma-crud/components/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,19 @@ const see = async (data) => {
await nextTick(() => maFormRef.value && maFormRef.value.updateOptions() )
}

const init = () => {
const init = async () => {
dataLoading.value = true
const layout = JSON.parse(JSON.stringify(options?.formOption?.layout ?? []))

columns.value.map(async item => {
await Promise.all(columns.value.map(async item => {
if (item.children && item.children.length > 0){
await item.children.map(async (childItem) => {
await columnItemHandle(childItem)
})
}else {
await columnItemHandle(item)
}
})
}))
// 设置表单布局
settingFormLayout(layout)
if (isArray(layout) && layout.length > 0) {
Expand All @@ -225,31 +225,29 @@ const columnItemHandle = async (item) => {
layoutColumns.value.set(item.dataIndex, item)
formColumns.value.push(item)

await Promise.all(async () => {
if (options.formOption.viewType !== 'tag') {
// 针对带点的数据处理
if (item.dataIndex && item.dataIndex.indexOf('.') > -1) {
form.value[item.dataIndex] = get(form.value, item.dataIndex)
}
if (options.formOption.viewType !== 'tag') {
// 针对带点的数据处理
if (item.dataIndex && item.dataIndex.indexOf('.') > -1) {
form.value[item.dataIndex] = get(form.value, item.dataIndex)
}

// add 默认值处理
if (currentAction.value === 'add') {
if (item.addDefaultValue && isFunction(item.addDefaultValue)) {
form.value[item.dataIndex] = await item.addDefaultValue(form.value)
} else if (typeof item.addDefaultValue != 'undefined') {
form.value[item.dataIndex] = item.addDefaultValue
}
// add 默认值处理
if (currentAction.value === 'add') {
if (item.addDefaultValue && isFunction(item.addDefaultValue)) {
form.value[item.dataIndex] = await item.addDefaultValue(form.value)
} else if (typeof item.addDefaultValue != 'undefined') {
form.value[item.dataIndex] = item.addDefaultValue
}
// edit 和 see 默认值处理
if (currentAction.value === 'edit' || currentAction.value === 'see') {
if (item.editDefaultValue && isFunction(item.editDefaultValue)) {
form.value[item.dataIndex] = await item.editDefaultValue(form.value)
} else if (typeof item.editDefaultValue != 'undefined') {
form.value[item.dataIndex] = item.editDefaultValue
}
}
// editsee 默认值处理
if (currentAction.value === 'edit' || currentAction.value === 'see') {
if (item.editDefaultValue && isFunction(item.editDefaultValue)) {
form.value[item.dataIndex] = await item.editDefaultValue(form.value)
} else if (typeof item.editDefaultValue != 'undefined') {
form.value[item.dataIndex] = item.editDefaultValue
}
}
})
}

item.disabled = undefined
item.readonly = undefined
Expand Down

0 comments on commit d721788

Please sign in to comment.