# BiuPage 列表页面
# 简单用法
tb-height
可以设置表格的高度,max-height
可设置最大高度biu-table
默认是开启虚拟表格的,如果你想关闭只需要配置virtual=false
- 自定义渲染可以使用
render
或者插槽两种方式,插槽优先级更高
<template>
<div style="height: 300px">
<biu-page
v-model="form"
:loading="loading"
:columns="columns"
:table-data="tableData"
@search="search"
@reset="reset"
></biu-page>
</div>
</template>
<script lang="tsx">
import { Vue, Component } from 'vue-property-decorator'
import { pageColumnsType } from 'calm-harbin/types/biu-page'
const defaultValue = {}
@Component
export default class BiuPageDemo extends Vue {
form: any = { ...defaultValue }
loading = false
tableData: any[] = []
packingOptions = [
{
label: '苹果apple',
value: 'apple'
},
{
label: '橘子orange',
value: 'orange'
},
{
label: '梨pear',
value: 'pear'
}
]
get columns(): pageColumnsType[] {
return [
{
formType: 'select',
label: '商品编码',
id: 'packing',
formAttr: {
options: this.packingOptions
}
},
{
label: '商品名称',
id: 'goodsName',
noSearch: true,
width: 150
},
{
label: '总数量',
id: 'number',
noSearch: true
},
{
label: '总重量(KG)',
id: 'weight',
// 使用render实现自定义渲染
noSearch: true,
render: (h, { row, col }) => <div>custom-{row[col.id]}</div>
},
{
label: '总体积(m³)',
id: 'volume',
noSearch: true
},
{
label: '长(m)',
id: 'length',
noSearch: true
},
{
label: '宽(m)',
id: 'width',
noSearch: true
},
{
label: '高(m)',
id: 'height',
noSearch: true
},
{
label: '净重',
id: 'netWeight',
noSearch: true
},
{
label: '备注',
id: 'remark',
width: 200,
noSearch: true
}
]
}
created() {
this.add(20)
}
/**
* 添加数据
*/
add(num: number) {
const length = this.tableData.length
setTimeout(() => {
new Array(num).fill('').forEach((_item, index) => {
this.tableData.push({
id: length + index,
packing: ['apple', 'orange', 'pear'][~~(Math.random() * 3)],
goodsName: ['苹果', '橘子', '梨'][~~(Math.random() * 3)],
number: ~~(Math.random() * 1000),
remark: '',
weight: 10,
volume: 1000,
length: 10,
width: 10,
height: 10,
netWeight: 99.99
})
})
}, 1000)
}
/**
* 搜索
*/
search() {
alert('搜索')
}
/**
* 重置
*/
reset() {
this.form = { ...defaultValue }
alert('重置')
this.search()
}
}
</script>
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
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
显示代码
# 常规用法
- 配置
show-header-filter=true
即可开启表头筛选功能,同时筛选条件改变会触发search
事件 - 使用
operationOptions
可以配置操作按钮,更多用法见Operation
按钮组件 - 使用
tablePostfixOptions
可以配置表格右侧操作列,更多用法见BiuTable
表格组件 - 配置
show-summary
可开启合计功能,不过需要手动计算数据。更多用法见BiuTable
表格组件 - 配置
pagination
即可开启分页功能,注意使用sync
用法哦,不然你的页面数据不会同步。分页改变会触发pagination
事件 - 配置
selection=true
可以开启多选功能,同时传入multipleSelection
来控制勾选的数据
提示
BiuTable
,BiuForm
组件的render
以及插槽用法也可以直接使用。
- render 用法参考 总重量 列
- 插槽用法参考 总体积 列
如果你想使用 Element 的一些配置,请直接传入给BiuPage
组件,最终会传入到 Element 的 Table 组件上。
<template>
<div style="height: 500px">
<biu-page
v-model="form"
:loading="loading"
:columns="columns"
:table-data="tableData"
:operation-options="operationOptions"
:table-postfix-options="tablePostfixOptions"
show-header-filter
show-summary
selection
:multiple-selection.sync="multipleSelection"
:pagination.sync="pagination"
@search="search"
@reset="reset"
@pagination="() => search()"
>
<!-- 表头插槽 -->
<template slot="table-header-volume" slot-scope="{ col }">
<span style="color: #409eff">{{ col.label }}</span>
</template>
<!-- 表头筛选框插槽 -->
<template slot="table-form-volume" slot-scope="{ col }">
<el-input
v-model="form[col.id]"
type="number"
size="mini"
></el-input>
</template>
<!-- 表格插槽写法,使用table-前缀 -->
<template slot="table-volume" slot-scope="{ row, col, $index }">
<div>{{ row[col.id] }}-{{ $index }}</div>
</template>
<!-- 表单插槽写法,使用form-前缀 -->
<template slot="form-volume" slot-scope="{ col }">
<el-form-item :label="col.label" :prop="col.id">
<el-input v-model="form[col.id]" type="number"></el-input>
</el-form-item>
</template>
</biu-page>
</div>
</template>
<script lang="tsx">
import { Vue, Component } from 'vue-property-decorator'
import { pageColumnsType, paginationType } from 'calm-harbin/types/biu-page'
import { OperationOptionType } from 'calm-harbin/types/operation'
import { tablePostfixOptionsType } from 'calm-harbin/types/biu-table'
import { startandends, exportExcel, summary } from 'calm-harbin'
const defaultValue = {
createdTime: startandends(30) // 生成距离当前30天的时间,用法见文档中的方法
}
@Component
export default class BiuPageDemo extends Vue {
form: any = { ...defaultValue }
loading = false
tableData: any[] = []
// 多选的数据
multipleSelection: any[] = []
packingOptions = [
{
label: '苹果apple',
value: 'apple'
},
{
label: '橘子orange',
value: 'orange'
},
{
label: '梨pear',
value: 'pear'
}
]
// 列配置
get columns(): pageColumnsType[] {
return [
{
formType: 'date',
label: '下单时间',
id: 'createdTime',
width: 230,
align: 'center',
noShow: true,
formAttr: {
dateType: 'daterange'
}
},
{
formType: 'select',
label: '商品编码',
id: 'packing',
formAttr: {
options: this.packingOptions
}
},
{
formType: 'input',
label: '商品名称',
id: 'goodsName',
width: 150
},
{
formType: 'date',
label: '发货时间',
id: 'deliverTime',
width: 230,
align: 'center',
timeFormat: 'YYYY-MM-DD hh:mm:ss',
formAttr: {
dateType: 'daterange'
}
},
{
formType: 'area',
label: '发货地',
id: 'area',
width: 200,
formAttr: {
areaType: 'area'
}
},
{
formType: 'slot',
label: '总数量',
id: 'number',
noSearch: true,
formAttr: {
render: (h, { col }) => (
<el-input-number
style="width: 100%"
v-model={this.form[col.id]}
min={0}
precision={3}
controls={false}
size="mini"
></el-input-number>
)
}
},
{
formType: 'slot',
label: '总重量(KG)',
id: 'weight',
// 表头渲染
headRender: (h, col) => {
return <span style="color: #409eff">{col.label}</span>
},
// 单元格渲染
render: (h, { row, col, $index }) => (
<div>
{row[col.id]}-{$index}
</div>
),
formAttr: {
// 表单自定义渲染
render: (h, col) => {
return (
<biu-form-item
formType="input"
style="width: 100%"
type="number"
v-model={this.form[col.id]}
size="mini"
></biu-form-item>
)
}
}
},
{
formType: 'slot',
label: '总体积(m³)',
id: 'volume'
},
{
formType: 'input',
label: '长(m)',
id: 'length'
},
{
formType: 'input',
label: '宽(m)',
id: 'width'
},
{
formType: 'input',
label: '高(m)',
id: 'height'
},
{
label: '净重',
id: 'netWeight',
noSearch: true
},
{
label: '备注',
id: 'remark',
width: 200,
noSearch: true
}
]
}
// 按钮配置
get operationOptions(): OperationOptionType[] {
return [
{
title: '添加',
hidden: false,
callback: () => {
console.log('添加')
}
},
{
title: '导出全部',
hidden: false,
callback: () => {
exportExcel(
this.columns,
this.tableData.slice(0, -1),
'test数据导出'
)
}
}
]
}
// 表格右侧操作配置
get tablePostfixOptions(): tablePostfixOptionsType[] {
return [
{
title: '编辑',
hidden: false,
icon: 'el-icon-edit-outline',
disabled: ({ $index }) => {
if ($index % 2 === 0) return true
return false
},
message: ({ $index }) => {
if ($index % 2 === 0) return '奇数行不可编辑哦'
return ''
},
callback: () => {
console.log('编辑')
}
},
{
title: '作废',
hidden: false,
icon: 'el-icon-delete',
callback: () => {
console.log('作废')
}
}
]
}
created() {
this.add(20)
}
pagination: paginationType = {
page: 1,
size: 20,
total: 0
}
/**
* 添加数据
*/
add(num: number) {
const length = this.tableData.length
setTimeout(() => {
new Array(num).fill('').forEach((_item, index) => {
this.tableData.push({
id: length + index,
packing: ['apple', 'orange', 'pear'][~~(Math.random() * 3)],
goodsName: ['苹果', '橘子', '梨'][~~(Math.random() * 3)],
deliverTime: Date.now(),
area: '上海市-上海市-嘉定区',
number: ~~(Math.random() * 1000),
remark: '',
weight: 10,
volume: 1000,
length: 10,
width: 10,
height: 10,
netWeight: 99.99
})
})
// 计算合计数据
const total = summary(this.tableData, {
number: 0,
weight: 0,
volume: 0,
length: 0,
width: 0,
height: 0,
netWeight: 0
})
this.tableData.push(total)
}, 1000)
}
/**
* 搜索
*/
search() {
console.log(this.form)
alert(`搜索,参数${JSON.stringify(this.form)}`)
}
/**
* 重置
*/
reset() {
this.form = { ...defaultValue }
alert('重置')
this.search()
}
}
</script>
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
显示代码
# BiuPage Attributes
参数 | 说明 | 必填 | 类型 | 默认值 |
---|---|---|---|---|
tbHeight | 表格高度,默认自适应 | number | — | |
value / v-model | 绑定值,给表单和表头筛选使用 | objType | — | |
columns | 配置项,表格和表单共用 | pageColumnsType[] | — | |
operationOptions | 操作按钮配置 | OperationOptionType[] | — | |
pagination | 分页配置,支持 sync 用法 | paginationType | — |
# 事件
事件名 | 说明 | 类型 |
---|---|---|
search | 搜索事件,点击搜索按钮,或者改变表头筛选触发 | () => void |
reset | 重置,点击重置按钮触发 | () => void |
pagination | 分页改变事件 | (data: { page: number, limit: number}) => void |
← 更新日志 BiuTable 表格 →