|
|
@ -1,6 +1,7 @@ |
|
|
|
<script> |
|
|
|
import {deepClone} from '@/utils/index' |
|
|
|
import render from '@/components/render/render.js' |
|
|
|
import _ from 'lodash' |
|
|
|
|
|
|
|
const ruleTrigger = { |
|
|
|
'el-input': 'blur', |
|
|
@ -14,6 +15,12 @@ const ruleTrigger = { |
|
|
|
'el-rate': 'change' |
|
|
|
} |
|
|
|
|
|
|
|
const processType = { |
|
|
|
'el-select': '__slot__.options', |
|
|
|
'el-radio-group': '__slot__.options', |
|
|
|
'el-checkbox-group': '__slot__.options' |
|
|
|
} |
|
|
|
|
|
|
|
const layouts = { |
|
|
|
colFormItem(h, scheme) { |
|
|
|
const config = scheme.__config__ |
|
|
@ -100,7 +107,8 @@ function formBtns(h) { |
|
|
|
<el-form-item size="large" class="submit-btn-form-item" style="margin-top:30px;"> |
|
|
|
<el-row type="flex" justify="center"> |
|
|
|
<el-col span={btnSpan}> |
|
|
|
<el-button style={style} type="primary" onClick={this.submitForm}>{this.formConfCopy.submitBtnText}</el-button> |
|
|
|
<el-button style={style} type="primary" |
|
|
|
onClick={this.submitForm}>{this.formConfCopy.submitBtnText}</el-button> |
|
|
|
</el-col> |
|
|
|
</el-row> |
|
|
|
</el-form-item> |
|
|
@ -127,8 +135,16 @@ function renderChildren(h, scheme) { |
|
|
|
} |
|
|
|
|
|
|
|
function setValue(event, config, scheme) { |
|
|
|
debugger |
|
|
|
this.$set(config, 'defaultValue', event) |
|
|
|
this.$set(this[this.formConf.formModel], scheme.__vModel__, event) |
|
|
|
if (processType[config.tag]) { |
|
|
|
let item = _.find(_.get(scheme, processType[config.tag]), {'value': event}) |
|
|
|
this.$set(this[this.formConf.labelFormModel], scheme.__vModel__, item.label) |
|
|
|
} else { |
|
|
|
this.$set(this[this.formConf.labelFormModel], scheme.__vModel__, event) |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function buildListeners(scheme) { |
|
|
@ -161,6 +177,7 @@ export default { |
|
|
|
handler(val) { |
|
|
|
this.formConfCopy = val |
|
|
|
this.initFormData(data.formConfCopy.fields, data[this.formConf.formModel]) |
|
|
|
this.initFormData(data.formConfCopy.fields, data[this.formConf.labelFormModel]) |
|
|
|
this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules]) |
|
|
|
}, |
|
|
|
deep: true |
|
|
@ -171,17 +188,22 @@ export default { |
|
|
|
serialNumber: 1,//序号 |
|
|
|
formConfCopy: deepClone(this.formConf), |
|
|
|
[this.formConf.formModel]: {}, |
|
|
|
[this.formConf.labelFormModel]: {}, |
|
|
|
[this.formConf.formRules]: {} |
|
|
|
} |
|
|
|
this.initFormData(data.formConfCopy.fields, data[this.formConf.formModel]) |
|
|
|
this.initFormData(data.formConfCopy.fields, data[this.formConf.labelFormModel]) |
|
|
|
this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules]) |
|
|
|
return data |
|
|
|
}, |
|
|
|
methods: { |
|
|
|
initFormData(componentList, formData) { |
|
|
|
//设置默认值 |
|
|
|
componentList.forEach(cur => { |
|
|
|
const config = cur.__config__ |
|
|
|
if (cur.__vModel__) formData[cur.__vModel__] = config.defaultValue |
|
|
|
if (cur.__vModel__) { |
|
|
|
formData[cur.__vModel__] = config.defaultValue |
|
|
|
} |
|
|
|
if (config.children) this.initFormData(config.children, formData) |
|
|
|
}) |
|
|
|
}, |
|
|
@ -215,7 +237,10 @@ export default { |
|
|
|
this.$refs[this.formConf.formRef].validate(valid => { |
|
|
|
if (!valid) return false |
|
|
|
// 触发sumit事件 |
|
|
|
this.$emit('submit', this[this.formConf.formModel]) |
|
|
|
this.$emit('submit', { |
|
|
|
formModel: this[this.formConf.formModel], |
|
|
|
labelFormModel: this[this.formConf.labelFormModel] |
|
|
|
}) |
|
|
|
return true |
|
|
|
}) |
|
|
|
} |
|
|
|