Skip to content

Commit

Permalink
[feature]{WidgetFormItem}: 修复事件冒泡bug
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBoooooo committed Mar 21, 2019
1 parent 082b6de commit cf8e874
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 32 deletions.
56 changes: 31 additions & 25 deletions src/components/CrudTable/components/GenerateFormDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<generate-form
ref="generateForm"
:data="jsonData"
:value="formValue"
:value="formValues"
:entity.sync="models"
:disabled="disabled"
/>
Expand Down Expand Up @@ -75,7 +75,7 @@ export default {
},
tableName: String,
dialogStatus: String,
formValue: {
formValues: {
type: Object,
default: () => ({}),
},
Expand Down Expand Up @@ -110,32 +110,37 @@ export default {
});
},
},
created() {
// 如果select,radio,checkbox等组件为多选情况 后台返回逗号分隔字符串 => 数组
for (const row of this.jsonData.list) {
if (row.columns) {
for (const column of row.columns) {
const { list } = column;
if (Array.isArray(list)) {
list.forEach((citem) => {
if (citem.options.multiple) {
if (!Array.isArray(this.formValues[citem.model])
&& this.formValues[citem.model]) {
this.formValues[citem.model] = this.formValues[citem.model].split(',');
}
watch: {
formValues: {
deep: true,
immediate: true,
handler() {
// 如果select,radio,checkbox等组件为多选情况 后台返回逗号分隔字符串 => 数组
for (const row of this.jsonData.list) {
if (row.columns) {
for (const column of row.columns) {
const { list } = column;
if (Array.isArray(list)) {
list.forEach((citem) => {
if (citem.options.multiple) {
if (!Array.isArray(this.formValues[citem.model])
&& this.formValues[citem.model]) {
this.formValues[citem.model] = this.formValues[citem.model].split(',');
}
}
});
}
});
}
} else if (row.options.multiple) {
if (!Array.isArray(this.formValues[row.model])
&& this.formValues[row.model]) {
this.formValues[row.model] = this.formValues[row.model].split(',');
}
}
}
} else if (row.options.multiple) {
if (!Array.isArray(this.formValues[row.model])
&& this.formValues[row.model]) {
this.formValues[row.model] = this.formValues[row.model].split(',');
}
}
}
},
watch: {
},
},
dialogFormVisible(val) {
this.visible = val;
},
Expand All @@ -148,6 +153,7 @@ export default {
},
},
}
</script>
<style lang="scss" scoped>
Expand Down
12 changes: 6 additions & 6 deletions src/components/CrudTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
:disabled="disabled"
:tableName="tableName"
:dialogStatus="dialogStatus"
:formValue="formValue"
:formValues="formValues"
@afterSave="Refresh"
:jsonData="jsonData"
:entity.sync="models"
Expand Down Expand Up @@ -82,7 +82,7 @@ export default {
return {
operation,
models: {}, // 表单内部实体
formValue: {}, // 当前表单实体model
formValues: {}, // 当前表单实体model
listQuery: {
totalCount: null,
pageSize: 10,
Expand Down Expand Up @@ -158,8 +158,8 @@ export default {
New() {
this.dialogStatus = 'create';
Object.keys(this.formValue).forEach((k) => {
this.formValue[k] = '';
Object.keys(this.formValues).forEach((k) => {
this.formValues[k] = '';
});
this.dialogFormVisible = true;
},
Expand All @@ -185,13 +185,13 @@ export default {
async Edit(id) {
this.dialogStatus = 'update';
const response = await this.crud('detail', this.tableName, { id });
this.formValue = response.data;
this.formValues = response.data;
this.dialogFormVisible = true;
},
async Detail(id) {
this.dialogStatus = 'update';
const response = await this.crud('detail', this.tableName, { id });
this.formValue = response.data;
this.formValues = response.data;
this.dialogFormVisible = true;
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/FormDesigner/WidgetFormItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:class="{active: selectWidget.key == element.key, 'is_req': element.options.required}"
:label="element.name"
class="widget-view "
@click.native="handleSelectWidget(index)"
@click.native.stop="handleSelectWidget(index)"
:label-width="element.name===''?'0px':''"

>
Expand Down

0 comments on commit cf8e874

Please sign in to comment.