Skip to content

Commit

Permalink
addDisplay、editDisplay、addReadonly和editReadonly属性支持Function
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoqingping committed Jun 4, 2024
1 parent 8668ecd commit 6abba2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/components/ma-crud/components/form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ const settingFormLayout = (layout) => {

const formItemShow = (item) => {
if (currentAction.value === 'add') {
return item.addDisplay !== false
return isFunction(item.addDisplay) ? (item.addDisplay() !== false) : (item.addDisplay !== false)
}
if (currentAction.value === 'edit' || currentAction.value === 'see') {
return item.editDisplay !== false
return isFunction(item.editDisplay) ? (item.editDisplay(form.value) !== false) : (item.editDisplay !== false)
}
return item.display !== false
}
Expand All @@ -351,10 +351,10 @@ const formItemDisabled = (item) => {
}
const formItemReadonly = (item) => {
if (currentAction.value === 'add' && ! isUndefined(item.addReadonly)) {
return item.addReadonly
return isFunction(item.addReadonly) ? item.addReadonly() : item.addReadonly
}
if (currentAction.value === 'edit' && ! isUndefined(item.editReadonly)) {
return item.editReadonly
return isFunction(item.editReadonly) ? item.editReadonly(form.value) : item.editReadonly
}
if (! isUndefined(item.readonly)) {
return item.readonly
Expand Down
8 changes: 4 additions & 4 deletions src/components/ma-crud/types/columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ export interface BasicColumn {
// 编辑|创建 通用是否显示字段
display?: boolean;
// 添加弹窗是否显示字段
addDisplay?: boolean;
addDisplay?: boolean | (() => boolean);
// 编辑弹窗是否显示字段
editDisplay?: boolean;
editDisplay?: boolean | ((record) => boolean);
// 编辑|创建 通用是否禁用字段
disabled?: boolean;
// 添加弹窗是否禁用字段
Expand All @@ -86,9 +86,9 @@ export interface BasicColumn {
// 编辑|创建 通用是否只读字段
readonly?: boolean;
// 添加弹窗是否只读字段
addReadonly?: boolean;
addReadonly?: boolean | (() => boolean);
// 编辑弹窗是否只读字段
editReadonly?: boolean;
editReadonly?: boolean | ((record) => boolean);
// 自定义渲染
customRender?:
| (({ record, column, rowIndex }) => VNodeChild | JSX.Element)
Expand Down

0 comments on commit 6abba2c

Please sign in to comment.