Commit 06249cc2283ac768f4e98fadf4a220846de9e22d
1 parent
600fee60
Exists in
master
and in
1 other branch
优化新式表单自定义类名
Showing
3 changed files
with
21 additions
and
6 deletions
Show diff stats
examples/views/page/form-new/form-render.vue
| 1 | <template> | 1 | <template> |
| 2 | <!-- 在row上使用flex,防止表单组件大小不一导致错位 --> | 2 | <!-- 在row上使用flex,防止表单组件大小不一导致错位 --> |
| 3 | - <component :is="rowComponent" class="eagle-form__flex-wrap" :class="contentClass || 'eagle-form__group-content'"> | 3 | + <component :is="rowComponent" class="eagle-form__flex-wrap"> |
| 4 | <template v-for="(item, index) in list"> | 4 | <template v-for="(item, index) in list"> |
| 5 | <!-- 表单项有设置分组时 --> | 5 | <!-- 表单项有设置分组时 --> |
| 6 | <component :is="colComponent" v-if="item.group && item.list" :key="index" | 6 | <component :is="colComponent" v-if="item.group && item.list" :key="index" |
| 7 | :span="type === 'div' ? undefined : item.group.span || 24" :style="{ width: type === 'div' ? '100%' : undefined }" | 7 | :span="type === 'div' ? undefined : item.group.span || 24" :style="{ width: type === 'div' ? '100%' : undefined }" |
| 8 | > | 8 | > |
| 9 | - <component :is="rowComponent" class="eagle-form__flex-wrap"> | 9 | + <component :is="rowComponent" class="eagle-form__flex-wrap" :class="groupClass || 'eagle-form__group'"> |
| 10 | <!-- 表单分组标题 --> | 10 | <!-- 表单分组标题 --> |
| 11 | <component :is="rowComponent" :class="titleClass || 'eagle-form__group-title'" v-if="item.group.title" style="width: 100%;"> | 11 | <component :is="rowComponent" :class="titleClass || 'eagle-form__group-title'" v-if="item.group.title" style="width: 100%;"> |
| 12 | {{ item.group.title || item.group }} | 12 | {{ item.group.title || item.group }} |
| 13 | </component> | 13 | </component> |
| 14 | <!-- 递归本组件 --> | 14 | <!-- 递归本组件 --> |
| 15 | - <form-render :title-class="titleClass" :item-class="itemClass" :list="item.list" :value="value" | 15 | + <form-render :title-class="titleClass" :item-class="itemClass" :content-class="contentClass" :group-class="groupClass" |
| 16 | + :class="contentClass || 'eagle-form__group-content'" :list="item.list" :value="value" | ||
| 16 | :model="itemKey ? model[itemKey] || {} : model" :itemKey="item.group.key" :type="type" | 17 | :model="itemKey ? model[itemKey] || {} : model" :itemKey="item.group.key" :type="type" |
| 17 | @item-change="onItemChange" @form-item-change="onFormItemChange" @item-update="onItemUpdate" | 18 | @item-change="onItemChange" @form-item-change="onFormItemChange" @item-update="onItemUpdate" |
| 18 | :span="type === 'div' ? undefined : span * (24 / (item.group.span || 24))" | 19 | :span="type === 'div' ? undefined : span * (24 / (item.group.span || 24))" |
| @@ -45,6 +46,7 @@ export default { | @@ -45,6 +46,7 @@ export default { | ||
| 45 | titleClass: String, | 46 | titleClass: String, |
| 46 | contentClass: String, | 47 | contentClass: String, |
| 47 | itemClass: String, | 48 | itemClass: String, |
| 49 | + groupClass: String, | ||
| 48 | type: String, | 50 | type: String, |
| 49 | span: Number, | 51 | span: Number, |
| 50 | }, | 52 | }, |
examples/views/page/form-new/index.vue
| @@ -23,8 +23,8 @@ | @@ -23,8 +23,8 @@ | ||
| 23 | 23 | ||
| 24 | <template> | 24 | <template> |
| 25 | <el-form ref="form" size="mini" :class="formClass" :model="formModel" :label-width="labelWidth" :label-position="labelPosition || labelWidth ? 'right' : 'top'"> | 25 | <el-form ref="form" size="mini" :class="formClass" :model="formModel" :label-width="labelWidth" :label-position="labelPosition || labelWidth ? 'right' : 'top'"> |
| 26 | - <form-render :title-class="titleClass" :content-class="contentClass" :item-class="itemClass" :list="formList" :value="model" | ||
| 27 | - :model="model" :span="span" :type="type" | 26 | + <form-render :title-class="titleClass" :content-class="contentClass" :item-class="itemClass" :group-class="groupClass" |
| 27 | + :list="formList" :value="model" :model="model" :span="span" :type="type" | ||
| 28 | @item-change="onItemChange" @form-item-change="onFormItemChange" @item-update="onItemUpdate" | 28 | @item-change="onItemChange" @form-item-change="onFormItemChange" @item-update="onItemUpdate" |
| 29 | ></form-render> | 29 | ></form-render> |
| 30 | </el-form> | 30 | </el-form> |
| @@ -44,6 +44,7 @@ export default { | @@ -44,6 +44,7 @@ export default { | ||
| 44 | titleClass: String, | 44 | titleClass: String, |
| 45 | contentClass: String, | 45 | contentClass: String, |
| 46 | itemClass: String, | 46 | itemClass: String, |
| 47 | + groupClass: String, | ||
| 47 | labelWidth: String, | 48 | labelWidth: String, |
| 48 | labelPosition: String, | 49 | labelPosition: String, |
| 49 | type: String, | 50 | type: String, |
examples/views/page/other.vue
| @@ -7,12 +7,23 @@ | @@ -7,12 +7,23 @@ | ||
| 7 | } | 7 | } |
| 8 | .custom-content { | 8 | .custom-content { |
| 9 | background: #fcc; | 9 | background: #fcc; |
| 10 | + margin: 10px; | ||
| 11 | +} | ||
| 12 | +.custom-item { | ||
| 13 | + background: #fcf; | ||
| 14 | +} | ||
| 15 | +.custom-group { | ||
| 16 | + background: #ffffff; | ||
| 17 | + padding: 0; | ||
| 18 | + border: 1px solid grey; | ||
| 19 | + margin: 10px; | ||
| 20 | + box-shadow: -2px 2px 8px grey; | ||
| 10 | } | 21 | } |
| 11 | </style> | 22 | </style> |
| 12 | 23 | ||
| 13 | <template> | 24 | <template> |
| 14 | <div> | 25 | <div> |
| 15 | - <pre>{{ tableData }}</pre> | 26 | + <pre>{{ model }}</pre> |
| 16 | <eg-table v-model="tableData" :list="option.list" :tableProps="{ border: true }" editable | 27 | <eg-table v-model="tableData" :list="option.list" :tableProps="{ border: true }" editable |
| 17 | @cell-edit="onCellEdit" @row-new="onRowNew" @row-edit="onRowEdit" @row-delete="onRowDelete" | 28 | @cell-edit="onCellEdit" @row-new="onRowNew" @row-edit="onRowEdit" @row-delete="onRowDelete" |
| 18 | > | 29 | > |
| @@ -32,6 +43,7 @@ | @@ -32,6 +43,7 @@ | ||
| 32 | <!-- <eg-form ref="form" v-model="model" :list="option.list" @validate="onValidate" label-width="80px" :span="6" type="div"></eg-form> --> | 43 | <!-- <eg-form ref="form" v-model="model" :list="option.list" @validate="onValidate" label-width="80px" :span="6" type="div"></eg-form> --> |
| 33 | <eg-form | 44 | <eg-form |
| 34 | ref="form" v-model="model" :list="option.list" @validate="onValidate" :span="4" | 45 | ref="form" v-model="model" :list="option.list" @validate="onValidate" :span="4" |
| 46 | + group-class="custom-group" | ||
| 35 | form-class="custom-form" title-class="custom-title" content-class="custom-content" item-class="custom-item" | 47 | form-class="custom-form" title-class="custom-title" content-class="custom-content" item-class="custom-item" |
| 36 | ></eg-form> | 48 | ></eg-form> |
| 37 | </div> | 49 | </div> |