2018-08-28 14:11:54 +08:00
|
|
|
|
<template>
|
2019-04-27 20:08:40 +08:00
|
|
|
|
<d2-container>
|
2018-08-28 14:11:54 +08:00
|
|
|
|
<template slot="header">新增数据</template>
|
|
|
|
|
|
<d2-crud
|
2018-12-24 14:03:12 +08:00
|
|
|
|
ref="d2Crud"
|
2018-08-28 14:11:54 +08:00
|
|
|
|
:columns="columns"
|
|
|
|
|
|
:data="data"
|
2018-12-25 14:05:25 +08:00
|
|
|
|
add-title="我的新增"
|
2018-12-24 14:03:12 +08:00
|
|
|
|
:add-template="addTemplate"
|
2018-08-28 14:11:54 +08:00
|
|
|
|
:form-options="formOptions"
|
2018-12-27 14:41:34 +08:00
|
|
|
|
@dialog-open="handleDialogOpen"
|
2018-08-28 14:11:54 +08:00
|
|
|
|
@row-add="handleRowAdd"
|
|
|
|
|
|
@dialog-cancel="handleDialogCancel">
|
2018-12-24 14:03:12 +08:00
|
|
|
|
<el-button slot="header" style="margin-bottom: 5px" @click="addRow">新增</el-button>
|
|
|
|
|
|
<el-button slot="header" style="margin-bottom: 5px" @click="addRowWithNewTemplate">使用自定义模板新增</el-button>
|
2018-08-28 14:11:54 +08:00
|
|
|
|
</d2-crud>
|
|
|
|
|
|
<el-card shadow="never" class="d2-mb">
|
|
|
|
|
|
<d2-markdown :source="doc"/>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
<el-card shadow="never" class="d2-mb">
|
|
|
|
|
|
<d2-highlight :code="code"/>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
<template slot="footer">
|
2018-10-24 10:37:04 +08:00
|
|
|
|
<d2-link-btn title="文档" link="https://doc.d2admin.fairyever.com/zh/ecosystem-d2-crud/"/>
|
2018-08-28 14:11:54 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</d2-container>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import doc from './doc.md'
|
|
|
|
|
|
import code from './code.js'
|
|
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
doc,
|
|
|
|
|
|
code,
|
|
|
|
|
|
columns: [
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '日期',
|
|
|
|
|
|
key: 'date'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '姓名',
|
|
|
|
|
|
key: 'name'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
title: '地址',
|
|
|
|
|
|
key: 'address'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
data: [
|
|
|
|
|
|
{
|
|
|
|
|
|
date: '2016-05-02',
|
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
|
address: '上海市普陀区金沙江路 1518 弄'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
date: '2016-05-04',
|
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
|
address: '上海市普陀区金沙江路 1517 弄'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
date: '2016-05-01',
|
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
|
address: '上海市普陀区金沙江路 1519 弄'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
date: '2016-05-03',
|
|
|
|
|
|
name: '王小虎',
|
|
|
|
|
|
address: '上海市普陀区金沙江路 1516 弄'
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
2018-12-24 14:03:12 +08:00
|
|
|
|
addTemplate: {
|
2018-08-28 14:11:54 +08:00
|
|
|
|
date: {
|
|
|
|
|
|
title: '日期',
|
|
|
|
|
|
value: '2016-05-05'
|
|
|
|
|
|
},
|
|
|
|
|
|
name: {
|
|
|
|
|
|
title: '姓名',
|
|
|
|
|
|
value: '王小虎'
|
|
|
|
|
|
},
|
|
|
|
|
|
address: {
|
|
|
|
|
|
title: '地址',
|
|
|
|
|
|
value: '上海市普陀区金沙江路 1520 弄'
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
formOptions: {
|
|
|
|
|
|
labelWidth: '80px',
|
|
|
|
|
|
labelPosition: 'left',
|
|
|
|
|
|
saveLoading: false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
2018-12-28 09:00:21 +08:00
|
|
|
|
handleDialogOpen ({ mode }) {
|
2018-12-27 14:41:34 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '打开模态框,模式为:' + mode,
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2018-12-24 14:03:12 +08:00
|
|
|
|
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: ''
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
2018-08-28 14:11:54 +08:00
|
|
|
|
handleRowAdd (row, done) {
|
|
|
|
|
|
this.formOptions.saveLoading = true
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
console.log(row)
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '保存成功',
|
|
|
|
|
|
type: 'success'
|
|
|
|
|
|
})
|
2018-11-26 13:22:01 +08:00
|
|
|
|
done({
|
|
|
|
|
|
address: '我是通过done事件传入的数据!'
|
|
|
|
|
|
})
|
2018-08-28 14:11:54 +08:00
|
|
|
|
this.formOptions.saveLoading = false
|
|
|
|
|
|
}, 300)
|
|
|
|
|
|
},
|
|
|
|
|
|
handleDialogCancel (done) {
|
|
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '取消保存',
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
})
|
|
|
|
|
|
done()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|