Files
mes-ui-d2/src/pages/demo/d2-crud/demo16/code.js
liyang 3a7037614c 修复格式代码格式问题
Former-commit-id: e83f9eb4a0a8eef2d14aa91b0d2eb77a8225fb2f [formerly e83f9eb4a0a8eef2d14aa91b0d2eb77a8225fb2f [formerly e83f9eb4a0a8eef2d14aa91b0d2eb77a8225fb2f [formerly e83f9eb4a0a8eef2d14aa91b0d2eb77a8225fb2f [formerly 7e59347fbe499bfad601d8eda1e1b58eb9278992 [formerly d22e39a4666f1afb2165fc1fb0298a365c4eb7e4]]]]]
Former-commit-id: e00d260ce93ff2bd76efb87f7fb5afe4377df80f
Former-commit-id: 5dea41cbedf50ff16683f38ec7817e9bebbb1452
Former-commit-id: ac53260ea0ff60617e720c73d37efb42d7339414 [formerly 266ccd78d17215c9bcb7b46914ebb64a0d61d549]
Former-commit-id: 2cc31d60bc63f32a72b0c3fc66412e2a36a5ca25
Former-commit-id: b2b67c0b74d9341c967cd3f29d13c81abf0ba9e2
Former-commit-id: a3b007a26f4c861b250296e53c69e114bbcd9641
Former-commit-id: debe0a70011e84fa6cafcecd40ccf56a9309e209
Former-commit-id: c9298110d2c2adf97e81658ab52c82b803e1036d
2018-12-28 09:00:21 +08:00

139 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export default `<template>
<div>
<d2-crud
ref="d2Crud"
:columns="columns"
:data="data"
add-title="我的新增"
:form-template="formTemplate"
:form-options="formOptions"
@dialog-open="handleDialogOpen"
@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>
</div>
</template>
<script>
export default {
data () {
return {
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 弄'
}
],
addTemplate: {
date: {
title: '日期',
value: '2016-05-05'
},
name: {
title: '姓名',
value: '王小虎'
},
address: {
title: '地址',
value: '上海市普陀区金沙江路 1520 弄'
}
},
formOptions: {
labelWidth: '80px',
labelPosition: 'left',
saveLoading: false
}
}
},
methods: {
handleDialogOpen ({ mode }) {
this.$message({
message: '打开模态框,模式为:' + mode,
type: 'success'
})
},
// 普通的新增
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(() => {
console.log(row)
this.$message({
message: '保存成功',
type: 'success'
});
// done可以传入一个对象来修改提交的某个字段
done({
address: '我是通过done事件传入的数据'
})
this.formOptions.saveLoading = false
}, 300)
},
handleDialogCancel (done) {
this.$message({
message: '取消保存',
type: 'warning'
});
done()
}
}
}
</script>`