/
complete_demo.vue
281 lines (276 loc) · 8.31 KB
/
complete_demo.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<template>
<div id="app">
<el-json-form :config="formJson" :model="formModel" ref="form" label-width="80px">
<div slot="append" class="submit-item el-form-item">
<el-button type="primary" :loading="loading" @click="onSubmit({currentPage: 1})">提交</el-button>
</div>
</el-json-form>
<el-json-table :config="tableJson" :data="tableData" @on-query="onSubmit" @select="select" @select-all="selectAll" @selection-change="handleSelectionChange" @cell-click="handleCellClick" @sort-change="handleSortChange">
<!--如果要自定义table-column, 只要指定v-slot:名字, 然后像以前一样写就可以了(3.0以上才支持v-slot,可以改成slot="xxx" slot-scope="scope")-->
<template slot="name" slot-scope="scope" >
<el-button type="text" @click="openModel(scope.row)">{{scope.row.name + '自定义row'}}
</el-button>
</template>
<template slot="sex" slot-scope="scope" >
<span>{{scope.row.sex === 1 ? '男' : '女'}}</span>
</template>
<template slot="operate" slot-scope="scope" >
<el-button type="text" @click="openModel(scope.row)">
{{'操作1'}}</el-button>
<el-button type="text" @click="openModel(scope.row)">{{'操作2'}}</el-button>
</template>
</el-json-table>
</div>
</template>
<script>
/* eslint-disable */
import Vue from 'vue'
export default {
name: "app",
components: {},
data() {
return {
loading: false,
formModel: {},
timer: null,
tableData: [],
tableJson: {
"style": {
"width": "300px"
},
"border": true,
"columns": [{
type: 'selection',
width: 55
}, {
prop: 'name',
label: 'Name',
width: 140,
sortable: true
}, {
prop: 'mobile',
label: 'Mobile',
minWidth: 100
}, {
prop: 'sex',
label: 'Sex',
width: 80,
renderHeader: (h, { column, $index }) => {
return h(
'span', null,
[
column.label,
h('el-button',
{
props: {
size: 'mini',
type: 'primary',
},
class: 'm-l-5',
on: {
click: () => {console.log('刷新')}
}
},
['刷新']
)
]
);
},
}, {
prop: 'operate',
label: '操作',
width: 180
}],
"pagination": {
layout: "total, sizes, prev, pager, next, jumper",
// hideOnSinglePage: true,
}
},
formJson: {
"title": "这是一个form+table+pagination完整demo(带搜索&&分页)",
"describe": "基于emelent ui",
"formAttr": {
"inline": true,
"label-position": "right",
"rules": {
"name": [{
"required": false,
"message": '请输入名称'
},
{
"max": 5,
"message": '最多 5 个字符'
}
]
},
"size": "mini"
},
"properties": {
"name": {
"type": "input",
// "mode": "text", // textarea, number, password...
"label": "活动名称",
"placeholder": "请输入...",
},
"sex": {
"type": "select",
"label": "性别",
// "multiple": true,
"options": [{
"label": "男",
"value": 1
},
{
"label": "女",
"value": 2
},
]
},
"date": {
"type": "datePicker",
"label": "日期",
"_type": "daterange",
"format": "yyyy 第 WW 周",
"placeholder": "选择周",
"rangeSeparator": "至",
"start-placeholder": "开始日期1",
"end-placeholder": "结束日期"
},
"switch": {
"type": "switch"
},
"button": {
"type": "button",
"text": "按钮",
"_type": "success"
},
"search": {
"type": "autocomplete",
"label": "远程搜索",
"placeholder": "请搜索...",
},
"id": {
"type": "input",
// "mode": "text", // textarea, number, password...
"label": "工号",
// "suffix-icon": "el-icon-search",
"placeholder": "请输入工号...",
},
},
}
}
},
mounted() {
// 如果options是后端数据的demo, 手动修改this.formJson即可
new Promise((resolve) => {
setTimeout(() => {
this.formJson.properties.sex.options = [{
"label": "男1111",
"value": 1
},
{
"label": "女",
"value": 2
},
]
}, 1000)
})
// 绑定change,blur,focus等事件demo
this.formJson.properties.id.change = (value) => {
console.log(value)
this.onSubmit()
}
this.formJson.properties.button.click = (value) => {
console.log(value)
this.onSubmit()
}
this.formJson.properties.date.change = (value) => {
console.log(value[0], value[1])
this.onSubmit()
}
// 异步搜索demo
this.formJson.properties.search.fetchSuggestions = (queryString, cb) => this.fetch(queryString, cb)
},
methods: {
// 异步搜索demo
fetch(queryString, cb) {
if (this.timer) clearTimeout(this.timer)
this.timer = setTimeout(() => {
cb([{
"label": "结果1",
"value": "结果1"
}, {
"label": "结果2",
"value": "结果2"
}, ])
}, 3000 * Math.random())
},
handleSizeChange(val) {
console.log(`每页 ${val} 条`);
},
handleCurrentChange(val) {
console.log(`当前页: ${val}`);
},
onSubmit(payload={}) {
console.log('submit! formValue:', this.$refs.form.values);
console.log('pagination-payload:', payload)
// 调用form实例的方法demo
// this.$refs.form.resetFields();
this.$refs.form.validate((valid, err) => {
if (valid) {
const resJson = {
data: [{
name: 'Sam',
mobile: '15299xxxx',
sex: 0
},
{
name: 'Jean',
mobile: '13452xxxx',
sex: 1
},
{
name: 'Tony',
mobile: '187233xxxx',
sex: 0
}
],
total: 98,
currentPage: payload.currentPage || 1
}
this.loading = true
setTimeout(() => {
this.tableData = resJson.data
this.tableJson.pagination = {
total: resJson.total,
currentPage: resJson.currentPage
}
this.loading = false
}, 1500 * Math.random())
} else {
console.log('error submit!!', err);
return false;
}
});
},
handleSelectionChange(val) {
console.log('handleSelectionChange', val)
},
selectAll(val) {
console.log('selectAll', val)
},
select(val) {
console.log('select', val)
},
handleCellClick(val) {
console.log('handleCellClick', val)
},
handleSortChange(sort) {
console.log('handleSortChange', sort)
},
openModel(row) {
console.log('openModel', row)
}
}
};
</script>