diff --git a/src/components/parser/Parser.vue b/src/components/parser/Parser.vue index 76ae707..150235d 100644 --- a/src/components/parser/Parser.vue +++ b/src/components/parser/Parser.vue @@ -17,6 +17,7 @@ const ruleTrigger = { const processType = { 'el-select': '__slot__.options', + 'el-cascader': 'options', 'el-radio-group': '__slot__.options', 'el-checkbox-group': '__slot__.options' } @@ -135,16 +136,40 @@ 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) + setValueLabel.call(this, event, config, scheme) +} + +function setValueLabel(event, config, scheme) { + let tagOptionKey = processType[config.tag] + if (tagOptionKey) { + if (event instanceof Array) { + let labelStr = '' + event.forEach(item => { + let {label} = getObject(_.get(scheme, tagOptionKey), 'value', item) + labelStr += label + ',' + }) + this.$set(this[this.formConf.labelFormModel], scheme.__vModel__, labelStr) + } else { + let item = _.find(_.get(scheme, tagOptionKey), {'value': event}) + this.$set(this[this.formConf.labelFormModel], scheme.__vModel__, item.label) + } } else { this.$set(this[this.formConf.labelFormModel], scheme.__vModel__, event) } +} +function getObject(array, key, value) { + let o + array.some(function iter(a) { + if (a[key] === value) { + o = a + return true + } + return Array.isArray(a.children) && a.children.some(iter) + }) + return o } function buildListeners(scheme) { @@ -177,7 +202,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.initLabelFormData(data.formConfCopy.fields, data[this.formConf.labelFormModel]) this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules]) }, deep: true @@ -192,11 +217,35 @@ export default { [this.formConf.formRules]: {} } this.initFormData(data.formConfCopy.fields, data[this.formConf.formModel]) - this.initFormData(data.formConfCopy.fields, data[this.formConf.labelFormModel]) + this.initLabelFormData(data.formConfCopy.fields, data[this.formConf.labelFormModel]) this.buildRules(data.formConfCopy.fields, data[this.formConf.formRules]) return data }, methods: { + initLabelFormData(componentList, formData) { + //设置默认值 + componentList.forEach(cur => { + let temConfig = cur.__config__ + if (cur.__vModel__) { + let tagOptionKey = processType[temConfig.tag] + let defaultValue = temConfig.defaultValue + let labelStr = '' + if (tagOptionKey) { + if (defaultValue instanceof Array) { + defaultValue.forEach(item => { + let {label} = getObject(_.get(cur, tagOptionKey), 'value', item) + labelStr += label + ',' + }) + formData[cur.__vModel__] = labelStr + } else { + let {label} = _.find(_.get(cur, tagOptionKey), {'value': defaultValue}) + formData[cur.__vModel__] = label + } + } + } + if (temConfig.children) this.initLabelFormData(temConfig.children, formData) + }) + }, initFormData(componentList, formData) { //设置默认值 componentList.forEach(cur => { diff --git a/src/views/account/login.vue b/src/views/account/login.vue index 3daf79e..de6937b 100644 --- a/src/views/account/login.vue +++ b/src/views/account/login.vue @@ -61,6 +61,7 @@ diff --git a/src/views/form/index.vue b/src/views/form/index.vue index 684c4c2..e595aa6 100644 --- a/src/views/form/index.vue +++ b/src/views/form/index.vue @@ -22,6 +22,7 @@ + @@ -30,17 +31,18 @@ import editor from './editor' import theme from './theme' import setting from './setting' import publish from './publish' - +import statistics from './statistics' export default { components: { editor, theme, setting, - publish + publish, + statistics }, data() { return { - activeIndex: '4', + activeIndex: '5', projectKey: '' } }, diff --git a/src/views/form/statistics.vue b/src/views/form/statistics.vue new file mode 100644 index 0000000..7aff57b --- /dev/null +++ b/src/views/form/statistics.vue @@ -0,0 +1,75 @@ + + + + +