-
Notifications
You must be signed in to change notification settings - Fork 92
/
index.vue
125 lines (121 loc) · 4.15 KB
/
index.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<template>
<d2-container>
<template slot="header">插槽式自定义组件
<example-helper title="插槽式自定义组件帮助说明" >
<span>自定义插槽需要<a href="https://github.com/greper/d2-crud" target="_blank">d2-crud的修改版</a>才能支持</span>
<d2-highlight :code="helper.crud"/>
<d2-highlight :code="helper.template"/>
</example-helper>
</template>
<crud-search ref="search" :options="crud.searchOptions" @submit="handleSearch" class="d2-mb-10" >
<template slot="slotExampleSearchSlot" slot-scope="scope">
<el-input v-model="scope.form['slotExample']" placeholder="blur有事件触发" @blur="inputBlur('search')"></el-input>
</template>
</crud-search>
<d2-crud
ref="d2Crud"
:columns="crud.columns"
:data="crud.list"
:rowHandle="crud.rowHandle"
edit-title="修改"
:add-template="crud.addTemplate"
:add-rules="crud.addRules"
:edit-template="crud.editTemplate"
:edit-rules="crud.editRules"
:form-options="crud.formOptions"
:options="crud.options"
:loading="crud.loading"
@dialog-open="handleDialogOpen"
@row-edit="handleRowEdit"
@row-add="handleRowAdd"
@row-remove="handleRowRemove"
@dialog-cancel="handleDialogCancel"
@form-data-change="handleFormDataChange"
@custom-emit="customEmit">
<el-button slot="header" style="margin-bottom: 5px" size="small" type="primary" @click="addRow">新增</el-button>
<template slot="createDateSlot" slot-scope="scope">
创建时间:{{scope.row['createDate'] | date_timeline('YYYY-MM-DD HH:mm:ss')}}<br/>
更新时间:{{scope.row['updateDate'] | date_timeline('YYYY-MM-DD HH:mm:ss')}}<br/>
</template>
<template slot="slotExampleSlot" slot-scope="scope">
<el-tag>{{scope.row['slotExample']}}</el-tag>
</template>
<template slot="slotExampleFormSlot" slot-scope="scope">
slot自定义:<el-input v-model="scope.form['slotExample']" placeholder="这是通过slot自定义的" style="width:130px" @blur="inputBlur('form')" ></el-input>
</template>
<template slot="topicsFormSlot" slot-scope="scope">
<el-input class="d2-mb-5" v-for="(item,index) in scope.form.topics" :key="index" v-model="scope.form.topics[index]" >
<el-button slot="append" icon="el-icon-remove-outline" v-on:click="removeTopic(index)"></el-button>
</el-input>
<el-button v-on:click="addTopic">添加主题</el-button>
</template>
</d2-crud>
<crud-footer ref="footer"
:current="crud.page.current"
:size="crud.page.size"
:total="crud.page.total"
@change="handlePaginationChange"
>
</crud-footer>
</d2-container>
</template>
<script>
import { AddObj, GetList, UpdateObj, DelObj } from './api'
import { crudOptions } from './crud'
import { d2CrudPlus } from 'd2-crud-plus'
import helper from './helper'
export default {
name: 'slotPage',
components: {},
mixins: [d2CrudPlus.crud],
data () {
return {
helper: helper
}
},
computed: {
helperHeight () {
let height = document.documentElement.clientHeight - 100
console.log('height:', height)
return height + 'px'
}
},
methods: {
getCrudOptions () {
return crudOptions
},
pageRequest (query) {
return GetList(query)
},
addRequest (row) {
return AddObj(row)
},
updateRequest (row) {
return UpdateObj(row)
},
delRequest (row) {
return DelObj(row.id)
},
inputBlur (event) {
console.log('失去焦点:', event)
this.$message('失去焦点:' + event)
},
customEmit () {
this.$message('自定义按钮')
},
addTopic () {
let form = this.getEditForm()
console.log('form:', form)
if (form.topics == null || form.topics === '') {
form.topics = []
}
form.topics.push('')
},
removeTopic (index) {
let form = this.getEditForm()
console.log('form:', form)
form.topics.splice(index, 1)
}
}
}
</script>