|
@@ -1,63 +1,80 @@
|
|
<template>
|
|
<template>
|
|
<div id="add">
|
|
<div id="add">
|
|
- <el-form ref="form" :model="form" :rules="rules" :label-width="labelWidth" class="form" size="small" @submit.native.prevent :style="styles">
|
|
|
|
|
|
+ <el-form
|
|
|
|
+ ref="form"
|
|
|
|
+ :model="form"
|
|
|
|
+ :rules="rules"
|
|
|
|
+ :label-width="labelWidth"
|
|
|
|
+ class="form"
|
|
|
|
+ size="small"
|
|
|
|
+ @submit.native.prevent
|
|
|
|
+ :style="styles"
|
|
|
|
+ :inline="inline"
|
|
|
|
+ >
|
|
<template v-for="(item, index) in fields">
|
|
<template v-for="(item, index) in fields">
|
|
<template v-if="!loading">
|
|
<template v-if="!loading">
|
|
<el-form-item v-if="display(item)" :key="'form-field-' + index" :label="getField('label', item)" :prop="item.model" :required="item.required">
|
|
<el-form-item v-if="display(item)" :key="'form-field-' + index" :label="getField('label', item)" :prop="item.model" :required="item.required">
|
|
<template v-if="!item.custom">
|
|
<template v-if="!item.custom">
|
|
- <el-tooltip class="item" effect="dark" :content="item.tip" placement="top-start" :disabled="!item.tip">
|
|
|
|
- <template v-if="item.type === `date` || item.type === `datetime`">
|
|
|
|
- <el-date-picker v-model="form[item.model]" :type="item.type" placeholder="选择择" format="yyyy-MM-dd" value-format="yyyy-MM-dd">
|
|
|
|
- </el-date-picker>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === `year` || item.type === `week` || item.type === `day`">
|
|
|
|
- <el-date-picker
|
|
|
|
- v-model="form[item.model]"
|
|
|
|
- :type="item.type"
|
|
|
|
- placeholder="选择择"
|
|
|
|
- :format="`${item.type === 'year' ? 'yyyy' : item.type === 'week' ? 'MM' : 'dd'}`"
|
|
|
|
- :value-format="`${item.type === 'year' ? 'yyyy' : item.type === 'week' ? 'MM' : 'dd'}`"
|
|
|
|
- >
|
|
|
|
- </el-date-picker>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'radio'">
|
|
|
|
- <el-radio-group v-model="form[item.model]" size="mini" v-bind="item.options">
|
|
|
|
- <slot name="radios" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
- </el-radio-group>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'checkbox'">
|
|
|
|
- <el-checkbox-group v-model="form[item.model]" v-bind="item.options">
|
|
|
|
- <slot name="checkboxs" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
- </el-checkbox-group>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'select'">
|
|
|
|
- <el-select v-model="form[item.model]" v-bind="item.options" filterable>
|
|
|
|
- <slot name="options" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
- </el-select>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'textarea'">
|
|
|
|
- <el-input v-model="form[item.model]" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }"></el-input>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'editor'">
|
|
|
|
- <wang-editor v-model="form[item.model]"></wang-editor>
|
|
|
|
- </template>
|
|
|
|
- <template v-else-if="item.type === 'text'">
|
|
|
|
- <el-row>
|
|
|
|
- <el-col :span="24">
|
|
|
|
- {{ form[item.model] }}
|
|
|
|
- </el-col>
|
|
|
|
- </el-row>
|
|
|
|
- </template>
|
|
|
|
- <template v-else>
|
|
|
|
- <el-input
|
|
|
|
- v-model="form[item.model]"
|
|
|
|
- :type="getField('type', item)"
|
|
|
|
- :placeholder="getField('placeholder', item)"
|
|
|
|
- :show-password="getField('type', item) === 'password'"
|
|
|
|
- v-bind="item.options"
|
|
|
|
- ></el-input>
|
|
|
|
- </template>
|
|
|
|
- </el-tooltip>
|
|
|
|
|
|
+ <template v-if="item.type !== 'text'">
|
|
|
|
+ <el-tooltip class="item" effect="dark" :content="item.tip" placement="top-start" :disabled="!item.tip">
|
|
|
|
+ <template v-if="item.type === `date` || item.type === `datetime`">
|
|
|
|
+ <el-date-picker
|
|
|
|
+ v-model="form[item.model]"
|
|
|
|
+ :type="item.type"
|
|
|
|
+ placeholder="选择择"
|
|
|
|
+ format="yyyy-MM-dd"
|
|
|
|
+ value-format="yyyy-MM-dd"
|
|
|
|
+ v-bind="item.options"
|
|
|
|
+ >
|
|
|
|
+ </el-date-picker>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === `year` || item.type === `week` || item.type === `day`">
|
|
|
|
+ <el-date-picker
|
|
|
|
+ v-model="form[item.model]"
|
|
|
|
+ :type="item.type"
|
|
|
|
+ placeholder="选择择"
|
|
|
|
+ :format="`${item.type === 'year' ? 'yyyy' : item.type === 'week' ? 'MM' : 'dd'}`"
|
|
|
|
+ :value-format="`${item.type === 'year' ? 'yyyy' : item.type === 'week' ? 'MM' : 'dd'}`"
|
|
|
|
+ v-bind="item.options"
|
|
|
|
+ >
|
|
|
|
+ </el-date-picker>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === 'radio'">
|
|
|
|
+ <el-radio-group v-model="form[item.model]" size="mini" v-bind="item.options">
|
|
|
|
+ <slot name="radios" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
+ </el-radio-group>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === 'checkbox'">
|
|
|
|
+ <el-checkbox-group v-model="form[item.model]" v-bind="item.options">
|
|
|
|
+ <slot name="checkboxs" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
+ </el-checkbox-group>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === 'select'">
|
|
|
|
+ <el-select v-model="form[item.model]" v-bind="item.options" filterable clearable>
|
|
|
|
+ <slot name="options" v-bind="{ item, form, fieldChange }"></slot>
|
|
|
|
+ </el-select>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === 'textarea'">
|
|
|
|
+ <el-input clearable v-model="form[item.model]" type="textarea" :autosize="{ minRows: 3, maxRows: 5 }"></el-input>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else-if="item.type === 'editor'">
|
|
|
|
+ <wang-editor v-model="form[item.model]"></wang-editor>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else>
|
|
|
|
+ <el-input
|
|
|
|
+ clearable
|
|
|
|
+ v-model="form[item.model]"
|
|
|
|
+ :type="getField('type', item)"
|
|
|
|
+ :placeholder="getField('placeholder', item)"
|
|
|
|
+ :show-password="getField('type', item) === 'password'"
|
|
|
|
+ v-bind="item.options"
|
|
|
|
+ ></el-input>
|
|
|
|
+ </template>
|
|
|
|
+ </el-tooltip>
|
|
|
|
+ </template>
|
|
|
|
+ <template v-else>
|
|
|
|
+ {{ form[item.model] }}
|
|
|
|
+ </template>
|
|
</template>
|
|
</template>
|
|
<template v-else>
|
|
<template v-else>
|
|
<slot name="custom" v-bind="{ item, form, fieldChange }"></slot>
|
|
<slot name="custom" v-bind="{ item, form, fieldChange }"></slot>
|
|
@@ -94,6 +111,8 @@ export default {
|
|
labelWidth: { type: String, default: '120px' },
|
|
labelWidth: { type: String, default: '120px' },
|
|
useEnter: { type: Boolean, default: true },
|
|
useEnter: { type: Boolean, default: true },
|
|
submitText: { type: String, default: '保存' },
|
|
submitText: { type: String, default: '保存' },
|
|
|
|
+ inline: { type: Boolean, default: false },
|
|
|
|
+ reset: { type: Boolean, default: true },
|
|
},
|
|
},
|
|
components: {
|
|
components: {
|
|
wangEditor,
|
|
wangEditor,
|
|
@@ -146,7 +165,7 @@ export default {
|
|
this.$refs['form'].validate(valid => {
|
|
this.$refs['form'].validate(valid => {
|
|
if (valid) {
|
|
if (valid) {
|
|
this.$emit(`save`, { isNew: this.isNew, data: JSON.parse(JSON.stringify(this.form)) });
|
|
this.$emit(`save`, { isNew: this.isNew, data: JSON.parse(JSON.stringify(this.form)) });
|
|
- this.$refs.form.resetFields();
|
|
|
|
|
|
+ if (this.reset) this.$refs.form.resetFields();
|
|
} else {
|
|
} else {
|
|
console.warn('form validate error!!!');
|
|
console.warn('form validate error!!!');
|
|
}
|
|
}
|