Commit 098b7b96db64d78e328ca5a0dc6cad3558be2fe9
1 parent
54091a8b
Exists in
master
and in
3 other branches
feat: 新增动态表单项规则
Showing
1 changed file
with
19 additions
and
1 deletions
Show diff stats
packages/form/form-render.vue
| @@ -46,7 +46,7 @@ | @@ -46,7 +46,7 @@ | ||
| 46 | :style="{ width: type === 'div' && item.style && item.style.width.includes('%') ? item.style.width : undefined, paddingRight: '10px' }" | 46 | :style="{ width: type === 'div' && item.style && item.style.width.includes('%') ? item.style.width : undefined, paddingRight: '10px' }" |
| 47 | :class="colClassRender(item, index, colClass)" | 47 | :class="colClassRender(item, index, colClass)" |
| 48 | > | 48 | > |
| 49 | - <el-form-item :label="item.label" :label-width="item.labelWidth" :prop="item.fullKey" :rules="item.rules" :class="itemClass || 'zee-form__item'"> | 49 | + <el-form-item :label="item.label" :label-width="item.labelWidth" :prop="item.fullKey" :rules="item | bindItemRulesFilter(model)" :class="itemClass || 'zee-form__item'"> |
| 50 | <slot v-if="$scopedSlots[item.fullKey]" :name="item.fullKey" :value="itemValue(item)" :model1="value"></slot> | 50 | <slot v-if="$scopedSlots[item.fullKey]" :name="item.fullKey" :value="itemValue(item)" :model1="value"></slot> |
| 51 | <template v-else> | 51 | <template v-else> |
| 52 | <!-- 自定义组件 --> | 52 | <!-- 自定义组件 --> |
| @@ -111,6 +111,24 @@ export default { | @@ -111,6 +111,24 @@ export default { | ||
| 111 | return this.type === 'div' ? 'div' : 'el-col'; | 111 | return this.type === 'div' ? 'div' : 'el-col'; |
| 112 | }, | 112 | }, |
| 113 | }, | 113 | }, |
| 114 | + filters: { | ||
| 115 | + /** | ||
| 116 | + * @description 绑定表单项规则 | ||
| 117 | + * @param {Object} item 表单项配置 | ||
| 118 | + * @returns {Function} 事件函数 | ||
| 119 | + */ | ||
| 120 | + bindItemRulesFilter(item = {}, model) { | ||
| 121 | + if (item.rules) { | ||
| 122 | + if (typeof item.rules === 'function') { | ||
| 123 | + return item.rules(model); | ||
| 124 | + } else { | ||
| 125 | + return item.rules; | ||
| 126 | + } | ||
| 127 | + } else { | ||
| 128 | + return undefined; | ||
| 129 | + } | ||
| 130 | + }, | ||
| 131 | + }, | ||
| 114 | methods: { | 132 | methods: { |
| 115 | /** | 133 | /** |
| 116 | * @description 渲染col class | 134 | * @description 渲染col class |