Former-commit-id: 684a411bad42ef4bd2e6f04660333d508e174a49 Former-commit-id: 1baddb969e04ebe172bef7681abe172910b7b50e Former-commit-id: d187b6bfc2ff341f8e31ef6db63746782c4cbf61 Former-commit-id: f79e152fca08e3685231938be30d48cec2d32218 [formerly 4ab64a70047e16bd0c15e33451734d8b0044a54a] Former-commit-id: 1168bbc2acd5afc389f7ca8665f0fc72e6be2f03 Former-commit-id: 11c5b20af4ce577fdd8fa3e215757e5d7be215ca Former-commit-id: 14e83d06f609b45d22e3f0f964ddc6b3a6ce2ddf Former-commit-id: f6505c3794292801d3e3dfdd1bcd5a21d9c6e198 Former-commit-id: 30634a2ac6f6d9d3329e15b95f6199642af11f67
186 lines
4.2 KiB
Vue
186 lines
4.2 KiB
Vue
<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://fairyever.com/d2-admin/doc/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>
|