|
101 | 101 |
|
102 | 102 | <script> |
103 | 103 | import responsiveMixin from './mixins/responsiveMixin' |
104 | | -import { isUnDef, is, castArray, getDeepVal, setDeepVal } from './tools/utils' |
| 104 | +import { isUnDef, is, castArray, getDeepVal, setDeepVal, isEmpty } from './tools/utils' |
105 | 105 | import { throttle } from 'throttle-debounce' |
106 | 106 | import localeMixin from 'element-ui/src/mixins/locale' |
107 | 107 | import { t } from './locale' |
@@ -573,12 +573,24 @@ export default { |
573 | 573 | typeof disabled === 'function' ? disabled(formData) : disabled |
574 | 574 | ) |
575 | 575 |
|
| 576 | + // 4.默认值 |
| 577 | + let defaultValue = typeof formItem.default === 'function' ? formItem.default(formData) : formItem.default |
| 578 | + // 默认值不为空 & (值为空 || 老值和当前值) |
| 579 | + if (!isEmpty(defaultValue) && (isEmpty(this.formData[field]) || formItem._defaultValue === this.formData[field])) { |
| 580 | + // 判断是否有格式化函数 |
| 581 | + if (this.computedFormDesc[field].displayFormatter) { |
| 582 | + defaultValue = this.desc.displayFormatter(defaultValue, this.formData) |
| 583 | + } |
| 584 | + setDeepVal(this.formData, field, defaultValue) |
| 585 | + } |
| 586 | +
|
576 | 587 | const fullPath = field.split('.').join('.chidlren.') |
577 | 588 | setDeepVal(this.formDesc, fullPath + '._type', type) |
578 | 589 | setDeepVal(this.formDesc, fullPath + '._vif', vif) |
579 | 590 | setDeepVal(this.formDesc, fullPath + '._disabled', disabled) |
| 591 | + setDeepVal(this.formDesc, fullPath + '._defaultValue', defaultValue) |
580 | 592 |
|
581 | | - // 4.重新获取 options |
| 593 | + // 5.重新获取 options |
582 | 594 | if (formItem.isReloadOptions) { |
583 | 595 | this.changeOptions( |
584 | 596 | getDeepVal(this.formDesc, fullPath), |
|
0 commit comments