Former-commit-id: db05786be3e9ab66abe0b3b604d01562542cfacc [formerly db05786be3e9ab66abe0b3b604d01562542cfacc [formerly db05786be3e9ab66abe0b3b604d01562542cfacc [formerly db05786be3e9ab66abe0b3b604d01562542cfacc [formerly 2acd0640d624075a9ddc5f9a86ee5adec2b88bc0 [formerly f87fab303d38481b3aa9a8dfda9f727d4bc25904]]]]]
Former-commit-id: 7030151b1f70b55f37114edc200cf3552469d190
Former-commit-id: 1b25ebdf8718b92e2b76e2d20fc75cbd79b6b9b4
Former-commit-id: 8e0c4a7c70905f515f10b7ad17077e42dbce7e4a [formerly d576cf89831968e4b6d972279add9a571f934c7c]
Former-commit-id: 9508887808bd8d888911e5b801180124bad7d072
Former-commit-id: 83245f1c040f9fdaee900aee9a08efd9e40c1f8d
Former-commit-id: 65380a255ed238316df9da4ec1865eaeea4ffee1
Former-commit-id: ef70b25a26296e2d17945d77175934a4e1e9e94d
Former-commit-id: 40cd5c6889f026242af0508bd051d138d7d973d8
This commit is contained in:
孙昊翔
2018-12-24 14:03:12 +08:00
parent 3188b0c740
commit 52d3c46da2
3 changed files with 62 additions and 19 deletions

View File

@@ -1,15 +1,16 @@
export default `<template>
<div>
<d2-crud
ref="d2Crud"
:columns="columns"
:data="data"
title="D2 CRUD"
add-mode
:add-button="addButton"
:form-template="formTemplate"
:form-options="formOptions"
@row-add="handleRowAdd"
@dialog-cancel="handleDialogCancel"/>
@dialog-cancel="handleDialogCancel">
<el-button slot="header" style="margin-bottom: 5px" @click="addRow">新增</el-button>
<el-button slot="header" style="margin-bottom: 5px" @click="addRowWithNewTemplate">使用自定义模板新增</el-button>
</d2-crud>
</div>
</template>
@@ -53,11 +54,7 @@ export default {
address: '上海市普陀区金沙江路 1516 弄'
}
],
addButton: {
icon: 'el-icon-plus',
size: 'small'
},
formTemplate: {
addTemplate: {
date: {
title: '日期',
value: '2016-05-05'
@@ -79,6 +76,32 @@ export default {
}
},
methods: {
// 普通的新增
addRow () {
this.$refs.d2Crud.showDialog({
mode: 'add'
})
},
// 传入自定义模板的新增
addRowWithNewTemplate () {
this.$refs.d2Crud.showDialog({
mode: 'add',
template: {
name: {
title: '姓名',
value: ''
},
value1: {
title: '新属性1',
value: ''
},
value2: {
title: '新属性2',
value: ''
}
}
})
},
handleRowAdd (row, done) {
this.formOptions.saveLoading = true
setTimeout(() => {

View File

@@ -1 +1 @@
通过 `D2 Crud` 传入 `add-mode` 可开启新增模式,需要传入 `form-template` 来为新增的表单添加模板,向`form-options` 中传入 `labelWidth``labelPosition` 来控制表单中label的显示, `saveLoading` 则控制保存按钮的loading状态`addButton` 可以控制表格顶部新增按钮的样式, `row-add` 事件控制数据新增,接收两个参数: `row` 是当前新增行的数据, `done` 用于控制保存成功,可以在 `done()` 之前加入自己的逻辑代码,`done()`可以传入包含表单字段的对象来覆盖提交的数据,`done(false)` 可以取消新增。代码如下:
通过 `ref` 调用 `D2 Crud` `showDialog` 方法,并传入 `mode: 'add'`属性,可开启新增模式,需要定义 `add-template` 来为新增的表单添加模板,也可以向 `showDialog` 中传入 `template`对象来灵活定义新的模板,`form-options` 中传入 `labelWidth``labelPosition` 来控制表单中label的显示, `saveLoading` 则控制保存按钮的loading状态 `row-add` 事件控制数据新增,接收两个参数: `row` 是当前新增行的数据, `done` 用于控制保存成功,可以在 `done()` 之前加入自己的逻辑代码,`done()`可以传入包含表单字段的对象来覆盖提交的数据,`done(false)` 可以取消新增。代码如下:

View File

@@ -2,15 +2,15 @@
<d2-container :filename="filename">
<template slot="header">新增数据</template>
<d2-crud
ref="d2Crud"
:columns="columns"
:data="data"
title="D2 CRUD"
add-mode
:add-button="addButton"
:form-template="formTemplate"
:add-template="addTemplate"
:form-options="formOptions"
@row-add="handleRowAdd"
@dialog-cancel="handleDialogCancel">
<el-button slot="header" style="margin-bottom: 5px" @click="addRow">新增</el-button>
<el-button slot="header" style="margin-bottom: 5px" @click="addRowWithNewTemplate">使用自定义模板新增</el-button>
</d2-crud>
<el-card shadow="never" class="d2-mb">
<d2-markdown :source="doc"/>
@@ -70,11 +70,7 @@ export default {
address: '上海市普陀区金沙江路 1516 弄'
}
],
addButton: {
icon: 'el-icon-plus',
size: 'small'
},
formTemplate: {
addTemplate: {
date: {
title: '日期',
value: '2016-05-05'
@@ -96,6 +92,30 @@ export default {
}
},
methods: {
addRow () {
this.$refs.d2Crud.showDialog({
mode: 'add'
})
},
addRowWithNewTemplate () {
this.$refs.d2Crud.showDialog({
mode: 'add',
template: {
name: {
title: '姓名',
value: ''
},
value1: {
title: '新属性1',
value: ''
},
value2: {
title: '新属性2',
value: ''
}
}
})
},
handleRowAdd (row, done) {
this.formOptions.saveLoading = true
setTimeout(() => {