Browse Source

完善功能

old
wangqing 5 years ago
parent
commit
eb190a1cbc
  1. 31
      src/components/parser/Parser.vue
  2. 1
      src/views/form/ProjectForm.vue

31
src/components/parser/Parser.vue

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

1
src/views/form/ProjectForm.vue

@ -69,6 +69,7 @@ export default {
__methods__: {}, __methods__: {},
formRef: 'elForm', formRef: 'elForm',
formModel: 'formData', formModel: 'formData',
labelFormModel: 'labelFormData',
size: 'small', size: 'small',
labelPosition: 'top', labelPosition: 'top',
labelWidth: 100, labelWidth: 100,

Loading…
Cancel
Save