Files
mes-ui-d2/src/views/demo/d2-crud/demo17/index.vue
FairyEver 604cf8e8df 缩减代码 去掉示例中无用的 slot="footer"
Former-commit-id: 1278ba413886c6d14fb950fd4f71b47880fab3be [formerly 1278ba413886c6d14fb950fd4f71b47880fab3be [formerly 1278ba413886c6d14fb950fd4f71b47880fab3be [formerly 1278ba413886c6d14fb950fd4f71b47880fab3be [formerly e00d73fd4a2af8b188808ef179cf216a01bd1dcd [formerly 740915a65bb3026522374bf96232908b19076cf7]]]]]
Former-commit-id: a77592ea3bd65774403a92981f42fefad3152707
Former-commit-id: f2c0a19e4475c09aa794963b2f0526d8abc203df
Former-commit-id: e6614173b8c84555d3af403b8798ac061645d110 [formerly f4e4a70714e058f6f7603fd0da2b51acef34d14b]
Former-commit-id: 92cb4f3595678b07468892be9e2b44073e91a42e
Former-commit-id: d8aa1a1ce90d353edbdc46680196fec486193a60
Former-commit-id: b0a97c8e7caaf45425067873d5accbb4c88c329d
Former-commit-id: d79733f1d6c84df34cb2c418661c0a248e2495da
Former-commit-id: 7a2548981507f7ba7cf174b09fe59c86319725b7
2019-08-28 09:41:42 +08:00

186 lines
4.2 KiB
Vue
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.

<template>
<d2-container>
<template slot="header">修改数据</template>
<d2-crud
ref="d2Crud"
:columns="columns"
:data="data"
:rowHandle="rowHandle"
edit-title="我的修改"
:edit-template="editTemplate"
:form-options="formOptions"
@dialog-open="handleDialogOpen"
@row-edit="handleRowEdit"
@dialog-cancel="handleDialogCancel">
<el-button slot="header" style="margin-bottom: 5px" @click="editRowWithNewTemplate">使用自定义模板编辑第三行</el-button>
</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>
<d2-link-btn
slot="footer"
title="文档"
link="https://doc.d2admin.fairyever.com/zh/ecosystem-d2-crud/"/>
</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 弄',
forbidEdit: true,
showEditButton: true
},
{
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀区金沙江路 1517 弄',
forbidEdit: false,
showEditButton: true
},
{
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀区金沙江路 1519 弄',
forbidEdit: false,
showEditButton: false
},
{
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀区金沙江路 1516 弄',
forbidEdit: false,
showEditButton: true
}
],
rowHandle: {
columnHeader: '编辑表格',
edit: {
icon: 'el-icon-edit',
text: '点我进行编辑',
size: 'small',
show (index, row) {
if (row.showEditButton) {
return true
}
return false
},
disabled (index, row) {
if (row.forbidEdit) {
return true
}
return false
}
}
},
editTemplate: {
date: {
title: '日期',
value: ''
},
name: {
title: '姓名',
value: ''
},
address: {
title: '地址',
value: ''
},
forbidEdit: {
title: '禁用按钮',
value: false,
component: {
show: false
}
},
showEditButton: {
title: '显示按钮',
value: true,
component: {
show: false
}
}
},
formOptions: {
labelWidth: '80px',
labelPosition: 'left',
saveLoading: false
}
}
},
methods: {
handleDialogOpen ({ mode, row }) {
this.$message({
message: '打开模态框,模式为:' + mode,
type: 'success'
})
},
editRowWithNewTemplate () {
this.$refs.d2Crud.showDialog({
mode: 'edit',
rowIndex: 2,
template: {
date: {
title: '日期',
value: ''
},
name: {
title: '姓名',
value: ''
}
}
})
},
handleRowEdit ({ index, row }, done) {
this.formOptions.saveLoading = true
setTimeout(() => {
console.log(index)
console.log(row)
this.$message({
message: '编辑成功',
type: 'success'
})
done({
address: '我是通过done事件传入的数据'
})
this.formOptions.saveLoading = false
}, 300)
},
handleDialogCancel (done) {
this.$message({
message: '取消编辑',
type: 'warning'
})
done()
}
}
}
</script>