index.vue
23.2 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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
<template>
<div class="glsx-table">
<el-table id="initTable"
class="hightline"
: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"
:tableId="tableId"
@sort-change="sortChange"
@selection-change="handleSelect"
:size="size"
:header-cell-style="headerStyle"
:show-summary="tableParams.showSummary"
:summary-method="tableParams.summaryMethod"
v-bind="$attrs"
v-on="$listeners">
<!-- //实现高亮竖线 -->
<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"
class-name="select-column"
type="selection"
width="48"
:selectable="checkSelectable"
:reserve-selection="true"></el-table-column>
<el-table-column v-if="hasNum"
:fixed="numHasFixed"
align="left"
width="74"
label="序号"
class-name="select-index"
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"
:label="item.label"
:prop="item.prop"
:width="item.width"
:min-width="item.minWidth"
:fixed="item.fixed"
:align="item.align || 'left'"
:sortable="item.sortable"
:render-header="item.renderHeader"
v-bind="item.columnattrs ? item.columnattrs : {}"
v-on="item.columnlisteners ? item.columnlisteners : {}">
<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 - 36) / 14) * 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) || '--' }} -->
{{ item.formatter(scope.row) | tableCellFormat }}
</span>
</template>
<template v-else-if="getListApi">
<el-popover v-if="scope.row[item.prop] && scope.row[item.prop].length >= Math.ceil((item.width - 36) / 14) * 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] || '--' }} -->
{{ scope.row[item.prop] | tableCellFormat }}
</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 - 36) / 14) * 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 : '' }">
<!-- {{ tableData[scope.$index][item.prop] || '--' }} -->
{{ tableData[scope.$index][item.prop] | tableCellFormat }}
</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"
:tableData="tableData"
:getListApi="getListApi"></sub-el-table-column>
</el-table-column>
<el-table-column class-name="gl-btns"
v-if="tableParams.tableOption"
label="操作"
:align="tableParams.tableOption.align || 'left'"
: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">
<div class="emptyBg">
<img class="noDataImg"
:src="noDataImg"
v-if="noDataImg"
alt="" />
<div class="noDataText">{{ noDataText }}</div>
<slot name="additionalContent"></slot>
</div>
</template>
</el-table>
<!-- hasPageComputed -->
<el-pagination v-if="hasPageComputed"
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"
v-bind="paginationattrs"
v-on="paginationlisteners"></el-pagination>
</div>
</template>
<script>
import noDataImgUrl from '@/assets/empty.png'
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: noDataImgUrl
},
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,
// 默认值是: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: 'total,sizes,prev,pager,next,jumper'
},
// 序号,默认有
hasNum: {
type: Boolean,
default: true
},
// table的配置项参数
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: () => []
},
// 表格项属性穿透
columnattrs: {
type: Object,
default: () => ({})
},
// 表格项事件穿透
columnlisteners: {
type: Object,
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()
},
'tableParams.tableColumns'(newVal, oldVal) {
// console.log('newVal',newVal)
this.tableColumns = newVal
}
// data: {
// immediate: true,
// handler(val) {
// this.showClass = val.length > 0 ? true : false
// },
// deep: true
// }
},
computed: {
// 分页计算属性
hasPageComputed() {
if (!this.hasPage) {
return false
}
// 没有数据的时候隐藏分页 api
if (this.getListApi) {
if (this.data.length == 0) {
return false
}
} else {
// 直接传数据的情况
if (this.tableData.length == 0) {
return false
}
}
// //直接传数据的情况
// if (this.tableTotal && this.tableTotal > this.page[this.pageConf.pageSize]) {
// return true
// }
// //传list api的情况 总数 一页多少条
// if(this.total <= this.page[this.pageConf.pageSize]){
// return false
// }
// if (this.page[this.pageConf.pageNum] <= 1) {
// return false
// }
return true
},
numHasFixed() {
return this.tableParams.tableColumns.some(item => {
return item.fixed == 'left'
})
}
},
methods: {
findShowHeadCol() {
// findShowHeadCol事件
this.tableColumns = []
this.tableParams.tableColumns.forEach(item => {
let isCustomCol = item.hasOwnProperty('isCustomCol')
if (!isCustomCol || (isCustomCol && this.customHeadShowList.includes(item.label))) {
this.tableColumns.push(item)
}
})
},
// @vuese
// 设置表格禁用
// @arg row 每一行表格内容
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()
},
// @vuese
// 设置表格高度
// @arg 1.navHeight,这个减值,2.addHeight是增值, 默认都为0
setTableHeightFun(navHeight = 0, addHeight = 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
}
let offsettop = document.getElementById('initTable').offsetTop
let 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';
// let tableHeight = clientHeight - offsettop - paginationHeight - baseNavEleHeight - baseSubNavEleHeight - 10 - 30 - 20
let tableHeight = clientHeight - offsettop - paginationHeight - baseNavEleHeight - baseSubNavEleHeight - navHeight + 10 + addHeight
// console.log('tableHeight: ', tableHeight, clientHeight, offsettop, paginationHeight, baseNavEleHeight, baseSubNavEleHeight, navHeight)
if (tableHeight < 240) {
tableHeight = 240
}
this.tableHeightValues = tableHeight
},
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) {
// 每页条数
let 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)
},
//原table mounted要做的要做的事情
tableInit() {
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()
setTimeout(() => {
// console.log('123456doLayout')
this.$refs[this.tableParams.mutiSelectName + 'MutiTable']?.doLayout()
}, 100)
}
},
mounted() {
this.tableInit()
// 注册事件 -- 防抖
window.onresize = () => {
if (!this.bAntiShike) {
this.bAntiShike = true
setTimeout(() => {
// console.log('组件跟新时间')
this.bAntiShike = false
this.componentKey = Date.now()
}, 300)
}
}
},
beforeDestroy() {
// 事件注销
window.onresize = null
}
}
</script>
<style lang="scss">
// @import '@/theme/global.scss';
.a-click {
cursor: pointer;
}
.el-table .cell {
line-height: 1.2;
}
.gl-btns .el-button + .el-button {
margin-left: 10px;
}
.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 {
// .select-column{
// .cell{
// }
// }
// .select-index{
// .cell{
// }
// }
.el-table__empty-text {
line-height: 1;
}
.emptyBg {
padding-top: 4px;
padding-bottom: 4px;
.noDataImg {
margin-bottom: 12px;
width: 64px;
height: 40px;
}
}
// .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: rgba(144, 147, 153, 0.3);
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: $color-primary;
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: $color-primary;
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; //设置高优先,以覆盖内联样式
}
// 滚动条上边头部栏的背景色
.el-table__fixed-right-patch {
background: #f4f6fc;
border-bottom: 1px solid #ebeef5;
}
}
/* 样式新增光亮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>