Files
mes-ui-d2/src/views/demo/d2-crud/demo16/index.vue
liyang 605c7e5db9 使用 $options.__file 实现更简单的源码查看功能
Former-commit-id: 4c6a0a1f72e1f512b919b934d8483ed430b54766 [formerly f1a4641c19751caddc88308bd8e29fb337f88982] [formerly 4c6a0a1f72e1f512b919b934d8483ed430b54766 [formerly f1a4641c19751caddc88308bd8e29fb337f88982] [formerly 4c6a0a1f72e1f512b919b934d8483ed430b54766 [formerly f1a4641c19751caddc88308bd8e29fb337f88982] [formerly f1a4641c19751caddc88308bd8e29fb337f88982 [formerly 065fde485c713b3ae79131d9da1234dfcbc73cc4 [formerly 470fef55bcb2073a14b6fcc998caabcb83a1097c]]]]]
Former-commit-id: c239db922bd8bd06fb68041118a2d25a9c7b475d
Former-commit-id: ac5808e62e6ac021da35462b59a04004d62db2dc
Former-commit-id: 7890270a60f4db69526403a56cb2dd4feb662e27 [formerly 7b8dd27f1eb72f5e3748d8174fa69c801a73ce1a]
Former-commit-id: 027ba79fa86ad1be42f14ef03afebde0cc6ed924
Former-commit-id: 0425a72d2e2b3536fb2ac74199ede23a1e4bea96
Former-commit-id: 96bdce03185ba3befec93d08016d63c7c3c2030a
Former-commit-id: e988828be9b03917a9579651a2912d2ed840fb7d
Former-commit-id: 07646c36ed91ea4e1efac1bdf1b16b84d8d32eaa
2019-04-27 20:08:40 +08:00

150 lines
3.5 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"
add-title="我的新增"
:add-template="addTemplate"
: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>
<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">
<d2-link-btn title="文档" link="https://doc.d2admin.fairyever.com/zh/ecosystem-d2-crud/"/>
</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 弄'
}
],
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({
address: '我是通过done事件传入的数据'
})
this.formOptions.saveLoading = false
}, 300)
},
handleDialogCancel (done) {
this.$message({
message: '取消保存',
type: 'warning'
})
done()
}
}
}
</script>