index.vue
18.7 KB
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
<template>
<div class="glsx-table">
<el-table id="initTable" class="hightline" v-bind="$attrs" v-on="$listeners" :key="componentKey" :ref="tableParams.mutiSelectName + 'MutiTable' || 'MutiTable'" :data="getListApi ? data : tableData" :row-class-name="tableParams.rowClassName" :row-style="tableParams.rowStyle" :row-key="tableParams.mutiSelectUniqueKey || ''" v-loading="loading" :height="tableHeightValues" :border="border" :table-id="tableId" @sort-change="sortChange" @selection-change="handleSelect" :size="size" :header-cell-style="headerStyle" :show-summary="tableParams.showSummary" :summary-method="tableParams.summaryMethod">
<!-- //实现高亮竖线 -->
<el-table-column fixed="left" width="5">
<template slot-scope="scope">
<span :scope="scope"></span>
</template>
</el-table-column>
<el-table-column v-if="tableParams.mutiSelectUniqueKey && tableParams.mutiSelectName" type="selection" width="55" :selectable="checkSelectable" :reserve-selection="true"></el-table-column>
<el-table-column v-if="hasNum" align="center" width="60px" label="序号" type="index" :index="index => index + (page[this.pageConf.pageNum] - 1) * page[this.pageConf.pageSize] + 1"></el-table-column>
<el-table-column v-for="(item, index) in tableColumns" :key="index" v-bind="item.columnattrs ? item.columnattrs : {}" v-on="item.columnlisteners ? item.columnlisteners : {}" :label="item.label" :prop="item.prop" :width="item.width" :min-width="item.minWidth" :fixed="item.fixed" :align="item.align || 'center'" :sortable="item.sortable" :render-header="item.renderHeader">
<template slot-scope="scope">
<slot v-if="item.addHtml" :name="item.addHtml" :scope="scope.row" :prop="item.prop" :width="item.width"></slot>
<template v-else-if="item.formatter">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="item.formatter(scope.row)">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ item.formatter(scope.row) | lineEllipsis(item.width, item.line) }}
</span>
</el-popover>
<span v-else class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ item.formatter(scope.row) }}
</span>
</template>
<template v-else-if="getListApi">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="scope.row[item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ scope.row[item.prop] | lineEllipsis(item.width, item.line) }}
</span>
</el-popover>
<span v-else class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ scope.row[item.prop] }}
</span>
</template>
<template v-else>
<!-- 大于10或 20个字节长度 宽度160px -->
<el-popover v-if="tableData[scope.$index][item.prop] && tableData[scope.$index][item.prop].length >= Math.ceil(item.width / 16) * item.line" placement="top" popper-class="base-popper" trigger="hover" :content="tableData[scope.$index][item.prop]">
<span slot="reference" class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }">
{{ tableData[scope.$index][item.prop] | lineEllipsis(item.width, item.line) }}
</span>
</el-popover>
<span v-else class="line-ellipsis" :style="{ '-webkit-line-clamp': item.line ? item.line : '' }" v-text="tableData[scope.$index][item.prop]"></span>
</template>
<template v-if="item.addSymbol">
<span v-text="item.addSymbol"></span>
</template>
</template>
<!-- 递归 -->
<sub-el-table-column v-if="item.children" :data="item.children" :table-data="tableData" :get-list-api="getListApi"></sub-el-table-column>
</el-table-column>
<el-table-column v-if="tableParams.tableOption" label="操作" :align="tableParams.tableOption.align || 'center'" :width="tableParams.tableOption.width || '200'" fixed="right">
<template slot-scope="scope">
<slot name="auth-button" :scope="scope.row"></slot>
</template>
</el-table-column>
<template slot="empty" class="emptyBg">
<img class="noDataImg" :src="noDataImg" v-if="noDataImg" alt="" />
<div>{{ noDataText }}</div>
<slot name="additionalContent"></slot>
</template>
</el-table>
<el-pagination v-if="hasPage" v-bind="paginationattrs" v-on="paginationlisteners" background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page[this.pageConf.pageNum]" :page-sizes="pageSizes" :page-size="page[this.pageConf.pageSize]" :total="getListApi ? total : tableTotal" :layout="layout"></el-pagination>
</div>
</template>
<script>
import SubElTableColumn from './sub-el-table-column.vue'
import GlSubTableColumn from '../../GlSubTableColumn'
import GlSubTable from '../../GlSubTable'
export default {
name: 'GLTable',
components: {
SubElTableColumn,
GlSubTableColumn,
GlSubTable
},
props: {
// `medium` / `small` / `mini`
size: {
type: String,
default: 'medium'
},
height: {
type: String,
default: ''
},
// maxHeight:{
// type:String,
// default:'3000'
// },
noDataImg: {
type: String,
default: ''
},
noDataText: {
type: String,
default: '暂无数据'
},
border: {
type: Boolean,
default: false
},
headerStyle: {
type: Object,
default: () => {}
},
// 表格需要多传入一个id的情况
tableId: {
type: String,
default: ''
},
// 搜索条件
searchForm: {
type: Object,
default: () => {}
},
// 是否定制表头
isCustomHead: {
type: Boolean,
default: false
},
// 表头展示
customHeadShowList: {
type: Array,
default: () => []
},
// 表格数据-外部传入
tableData: {
type: Array,
default: () => []
},
tableTotal: {
type: Number,
default: 0
},
// 获取列表接口
getListApi: {
type: Function,
default: null
},
// 搜索前操作
beforeSearchFn: {
type: Function,
default: () => {
return new Promise((resolve, reject) => {
resolve()
})
}
},
pageSizes: {
type: Array,
default: () => [10, 20, 30, 40]
},
// 分页,默认有
hasPage: {
type: Boolean,
default: true
},
pageConf: {
type: Object,
default: () => ({
pageSize: 'pageSize',
pageNum: 'pageNum',
totalCount: 'totalCount'
})
},
// 分页组件配置
layout: {
type: String,
default: 'sizes,total,->,prev,pager,next,jumper'
},
// 序号,默认有
hasNum: {
type: Boolean,
default: true
},
tableParams: {
type: Object,
default: () => {
return {
// 多选-判断来自哪个页面
// mutiSelectName: {
// type: String,
// default: ''
// },
// 多选-唯一标识-行数据的key
// mutiSelectUniqueKey: {
// type: String,
// default: ''
// },
// 设置禁止选中的行数据
checkSelectKey: {
type: String,
default: ''
},
// 设置禁止选中的值
checkSelectVal: {
type: Array,
default: () => []
},
// 后端返回列表参数名
listName: {
type: String,
default: ''
},
// 表格操作,默认没有
// tableOption: {
// type: Object,
// default: null
// },
// 表格栏
tableColumns: {
type: Array,
default: () => []
}
}
}
},
// el分页组件属性透传
paginationattrs: {
type: Object,
default: () => ({})
},
// el分页组件事件透传
paginationlisteners: {
type: Object,
default: () => ({})
}
},
data() {
return {
loading: false,
data: [],
// 页码
page: {},
total: 10,
// 多选数组
mutiSelectArr: {},
tableColumns: [],
showClass: false,
tableHeightValues: null,
bAntiShike: false, // 防抖
componentKey: Date.now(), // 用于更新组件
hightCell: ''
}
},
watch: {
customHeadShowList(val) {
this.isCustomHead && this.findShowHeadCol()
}
// data: {
// immediate: true,
// handler(val) {
// this.showClass = val.length > 0 ? true : false
// },
// deep: true
// }
},
methods: {
findShowHeadCol() {
// findShowHeadCol事件
this.tableColumns = []
this.tableParams.tableColumns.forEach(item => {
const isCustomCol = item.hasOwnProperty('isCustomCol')
if (!isCustomCol || (isCustomCol && this.customHeadShowList.includes(item.label))) {
this.tableColumns.push(item)
}
})
},
checkSelectable(row) {
// 设置禁止选中的行数据
if (this.tableParams.checkSelectKey && this.tableParams.checkSelectVal.length > 0) {
return this.tableParams.checkSelectVal.indexOf(row[this.tableParams.checkSelectKey]) == -1
} else {
return true
}
},
sortChange({ column, prop, order }) {
// 排序
// @arg column \ prop \ order
this.$emit('sortChange', { column, prop, order })
},
handleSelect(val) {
this.mutiSelectArr[this.tableParams.mutiSelectName] = val
// 多选
this.$emit('selectionTable', val)
},
clearMutiSelect() {
// 清空多选
this.mutiSelectArr[this.tableParams.mutiSelectName] = []
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].clearSelection()
},
setTableHeightFun(navHeight = 0) {
// 设置表格高度
// navHeight 传值底部高度
var baseNavEle = document.querySelector('.scrm-base-nav')
var baseSubNavEle = document.querySelector('.scrm-base-sub-nav')
var baseNavEleHeight = baseNavEle ? baseNavEle.clientHeight : 0
var baseSubNavEleHeight = baseSubNavEle ? baseSubNavEle.clientHeight : 0
let paginationHeight
if (document.querySelector('.el-pagination')) {
paginationHeight = document.querySelector('.el-pagination').clientHeight + 20
} else {
paginationHeight = 0
}
const offsettop = document.getElementById('initTable').offsetTop
const clientHeight = document.documentElement.clientHeight
// document.getElementById('initTable').style.height = clientHeight - offsettop - paginationHeight - navHeight + 'px'
// document.querySelector('.el-table__empty-block').style.height=(clientHeight - offsettop - paginationHeight - navHeight)+'px';
this.tableHeightValues = clientHeight - offsettop - paginationHeight - baseNavEleHeight - baseSubNavEleHeight - 10 - 30 - 20 + 'px'
},
refreshTable(isResetPageNum = true, isClearMuti = true) {
// 刷新table
this.beforeSearchFn().then(res => {
// 清空多选
isClearMuti && this.clearMutiSelect()
this.loading = true
isResetPageNum && (this.page[this.pageConf.pageNum] = 1)
var params = {
...this.page,
...this.searchForm
}
if (this.tableId) {
params.id = this.tableId
}
this.getListApi(params)
.then(res => {
this.data = this.findVal(res, this.tableParams.listName)
this.total = this.findVal(res, this.pageConf.totalCount)
this.loading = false
this.$nextTick(() => {
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].doLayout()
})
// 表格请求到数据
// console.log('表格请求到数据this.data',this.data)
this.$emit('setTableFinishFun', this.data)
})
.catch(() => {
this.loading = false
})
})
},
findVal(res, rankStr) {
// 找返回值
var rankList = rankStr.split('.')
if (!rankStr) {
return res
}
return this.findVal(res[rankList[0]], rankList.splice(1).join('.'))
},
handleSizeChange(value) {
// 每页条数
const offsettop = document.getElementById('initTable').offsetTop
this.page[this.pageConf.pageSize] = value
// 刷新表格
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page)
},
handleCurrentChange(value) {
// 页码
this.page[this.pageConf.pageNum] = value
this.getListApi ? this.refreshTable(false, false) : this.$emit('refreshTable', this.page)
}
},
mounted() {
this.isCustomHead ? this.findShowHeadCol() : (this.tableColumns = this.tableParams.tableColumns)
this.page = {}
this.page[this.pageConf.pageSize] = this.pageSizes[0]
this.page[this.pageConf.pageNum] = 1
this.getListApi && this.refreshTable()
// 注册事件 -- 防抖
window.onresize = () => {
if (!this.bAntiShike) {
this.bAntiShike = true
setTimeout(() => {
// console.log('组件跟新时间')
this.bAntiShike = false
this.componentKey = Date.now()
}, 300)
}
}
//
setTimeout(() => {
// console.log('123456doLayout')
this.$refs[this.tableParams.mutiSelectName + 'MutiTable'].doLayout()
}, 100)
},
beforeDestroy() {
// 事件注销
window.onresize = null
}
}
</script>
<style lang="scss">
.a-click {
cursor: pointer;
}
.el-table .cell {
line-height: 1.2;
}
.glsx-table p {
margin: 10px 0;
}
// .glsx-table .line-ellipsis {
// display: -webkit-box;
// width: 100%;
// overflow: hidden;
// text-overflow: ellipsis;
// -webkit-line-clamp: 2;
// -webkit-box-orient: vertical;
// }
.el-table-column--selection .cell {
padding-left: 14px !important;
padding-right: 14px !important;
}
.glsx-table .emptyBg {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
}
.el-table__body-wrapper::-webkit-scrollbar {
width: 8px;
height: 8px;
/* display: none; */
}
/*正常情况下滑块的样式*/
.el-table__body-wrapper::-webkit-scrollbar-thumb {
background-color: rgba(0, 0, 0, 0.05);
border-radius: 8px;
box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
}
/*鼠标悬浮在该类指向的控件上时滑块的样式*/
.el-table__body-wrapper::-webkit-scrollbar-thumb {
/* background-color: rgba(0, 0, 0, 0.2); */
background: #e9e8ff;
border-radius: 8px;
box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
}
/*鼠标悬浮在滑块上时滑块的样式*/
/* &::-webkit-scrollbar-thumb:hover {
background-color: rgba(0, 0, 0, 0.4);
box-shadow: inset 1px 1px 0 rgba(0, 0, 0, 0.1);
} */
/*正常时候的主干部分*/
.el-table__body-wrapper::-webkit-scrollbar-track {
border-radius: 8px;
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
background-color: white;
}
/*鼠标悬浮在滚动条上的主干部分*/
/* .el-table__body-wrapper::-webkit-scrollbar-track:hover {
box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.4);
background-color: rgba(0, 0, 0, 0.01);
} */
/* .hasTableContent .el-table__body{
height: 100%;
} */
/* .hasTableContent .el-table__body-wrapper{
height: 100%;
} */
/* 样式新增光亮tr */
/* .el-table */
//处理闪的问题
.el-table--enable-row-transition .el-table__body td.el-table__cell {
transition: background-color 0s ease !important;
}
.el-table--enable-row-transition .el-table__body td{
transition: background-color 0s ease !important;
}
.el-table .el-table__body tr.hover-row {
transform: translate3d(0, 0, 0);
box-shadow: 0px 3px 10px rgba(114, 112, 151, 0.25);
}
.el-table__body tr.hover-row > td {
background-color: #f4f4fc !important;
// box-shadow: 0px 3px 10px rgba(114, 112, 151, 0.25);
}
.el-table .el-table__body tr.hover-row > td.el-table__cell {
background-color: #f4f4fc !important;
// box-shadow: 0px 3px 10px rgba(114, 112, 151, 0.25);
}
.el-table tbody tr:hover {
transform: translate3d(0, 0, 0);
box-shadow: 0px 3px 10px rgba(114, 112, 151, 0.25);
}
// 去掉滚动条的上边框
.el-table tbody tr:last-child td {
border-bottom: 1px solid #fff;
}
//添加高亮行的竖线
.el-table.hightline .el-table__body tr.hover-row {
// background-color: #f4f4fc !important;
td:first-child {
position: relative;
// // background-color: #5850ff !important;
// background-color: #f4f4fc !important;
&:after {
position: absolute;
top: 0;
left: 0;
display: block;
content: '';
width: 5px;
height: 100%;
background-color: #5850ff;
}
}
}
.el-table.hightline tbody tr:hover {
// background-color: #f4f4fc !important;
td:first-child {
position: relative;
// // background-color: #5850ff !important;
// background-color: #f4f4fc !important;
&:after {
position: absolute;
top: 0;
left: 0;
display: block;
content: '';
width: 5px;
height: 100%;
background-color: #5850ff;
}
}
}
//除去左边fixed的阴影,添加竖线的时候
.el-table.hightline .el-table__fixed {
box-shadow: none !important;
}
//切换table后 el_table 固定列下方多了一条线
.glsx-table {
/deep/ .el-table__fixed,
/deep/ .el-table__fixed-right {
height: 100% !important; //设置高优先,以覆盖内联样式
}
}
/* 样式新增光亮tr */
/* 多级表头的样式调整 */
.el-table.hightline .el-table__fixed .el-table__row td:first-child {
border-right: none;
}
.el-table.hightline .el-table__fixed th.is-leaf:first-child {
border: none;
}
</style>