|
1 | 1 | <template> |
2 | | - <div class="v-table-views v-table-class" :style="{'width': internalWidth+'px', 'height': getTableHeight+'px'}"> |
| 2 | + <div class="v-table-views v-table-class" :style="{'width': internalWidth+'px', 'height': getTableHeight+'px','background-color':tableBgColor}"> |
3 | 3 | <!--左列--> |
4 | 4 | <template v-if="frozenCols.length > 0"> |
5 | 5 | <div class="v-table-leftview" :style="{'width':leftViewWidth+'px'}"> |
|
75 | 75 | <table class="v-table-btable" cellspacing="0" cellpadding="0" border="0"> |
76 | 76 | <tbody> |
77 | 77 | <tr v-for="(item,rowIndex) in internalTableData" class="v-table-row" |
78 | | - :style="[trBgColor(rowIndex+1),setRowHoverColor(item.__mouseenter__),setRowClickColor(item.__columnCellClick__)]" |
| 78 | + :style="[trBgColor(rowIndex+1)]" |
79 | 79 | @mouseenter.stop="handleMouseEnter(rowIndex)" |
80 | 80 | @mouseleave.stop="handleMouseOut(rowIndex)"> |
81 | 81 | <td v-if="cellMergeInit(rowIndex,col.field,item,true)" |
|
222 | 222 | <table class="v-table-btable" cellspacing="0" cellpadding="0" border="0"> |
223 | 223 | <tbody> |
224 | 224 | <tr :key="rowIndex" v-for="(item,rowIndex) in internalTableData" class="v-table-row" |
225 | | - :style="[trBgColor(rowIndex+1),setRowHoverColor(item.__mouseenter__),setRowClickColor(item.__columnCellClick__)]" |
| 225 | + :style="[trBgColor(rowIndex+1)]" |
226 | 226 | @mouseenter.stop="handleMouseEnter(rowIndex)" |
227 | 227 | @mouseleave.stop="handleMouseOut(rowIndex)" |
228 | 228 | > |
|
327 | 327 | import checkboxSelectionMixin from './checkbox-selection-mixin.js' |
328 | 328 | import tableFooterMixin from './table-footer-mixin.js' |
329 | 329 | import scrollBarControlMixin from './scroll-bar-control-mixin.js' |
| 330 | + import tableRowMouseEventsMixin from './table-row-mouse-events-mixin' |
330 | 331 |
|
331 | 332 | import utils from '../../src/utils/utils.js' |
332 | 333 | import deepClone from '../../src/utils/deepClone.js' |
|
338 | 339 |
|
339 | 340 | export default { |
340 | 341 | name: 'v-table', |
341 | | - mixins: [classesMixin, tableResizeMixin, frozenColumnsMixin, scrollControlMixin, sortControlMixin, tableEmptyMixin, dragWidthMixin, cellEditMixin, bodyCellMergeMixin, titleCellMergeMixin, checkboxSelectionMixin, tableFooterMixin, scrollBarControlMixin], |
| 342 | + mixins: [classesMixin, tableResizeMixin, frozenColumnsMixin, scrollControlMixin, sortControlMixin, tableEmptyMixin, dragWidthMixin, cellEditMixin, bodyCellMergeMixin, titleCellMergeMixin, checkboxSelectionMixin, tableFooterMixin, scrollBarControlMixin,tableRowMouseEventsMixin], |
342 | 343 | components: {tableEmpty, loading, VCheckboxGroup, VCheckbox}, |
343 | 344 | data(){ |
344 | 345 | return { |
|
363 | 364 | width: [Number, String], |
364 | 365 | minWidth: { |
365 | 366 | type: Number, |
366 | | - require: false, |
367 | 367 | default: 50 |
368 | 368 | }, |
369 | 369 | height: { |
|
372 | 372 | }, |
373 | 373 | minHeight: { |
374 | 374 | type: Number, |
375 | | - require: false, |
376 | 375 | default: 50 |
377 | 376 | }, |
378 | 377 | titleRowHeight: { |
379 | 378 | type: Number, |
380 | | - require: false, |
381 | 379 | default: 38 |
382 | 380 | }, |
383 | 381 | // 随着浏览器窗口改变,横向自适应 |
384 | 382 | isHorizontalResize: { |
385 | 383 | type: Boolean, |
386 | | - require: false, |
387 | 384 | default: false |
388 | 385 | }, |
389 | 386 | // 随着浏览器窗口改变,垂直自适应 |
390 | 387 | isVerticalResize: { |
391 | 388 | type: Boolean, |
392 | | - require: false, |
393 | 389 | default: false |
394 | 390 | }, |
395 | 391 |
|
|
399 | 395 | default: 0 |
400 | 396 | }, |
401 | 397 |
|
| 398 | + tableBgColor:{ |
| 399 | + type: String, |
| 400 | + default: '#fff' |
| 401 | + }, |
| 402 | +
|
402 | 403 | // 表头背景颜色 |
403 | 404 | titleBgColor: { |
404 | 405 | type: String, |
405 | | - require: false, |
406 | 406 | default: '#fff' |
407 | 407 | }, |
408 | 408 |
|
409 | 409 | // 奇数行颜色 |
410 | 410 | oddBgColor: { |
411 | 411 | type: String, |
412 | | - default: '#fff' |
| 412 | + default: '' |
413 | 413 | }, |
414 | 414 | // 偶数行颜色 |
415 | 415 | evenBgColor: { |
416 | | - type: String |
| 416 | + type: String, |
| 417 | + default: '' |
417 | 418 | }, |
418 | 419 | // 内容行高 |
419 | 420 | rowHeight: { |
420 | 421 | type: Number, |
421 | | - require: false, |
422 | 422 | default: 40 |
423 | 423 | }, |
424 | 424 | // 多列排序 |
425 | 425 | multipleSort: { |
426 | 426 | type: Boolean, |
427 | | - require: false, |
428 | 427 | default: true |
429 | 428 | }, |
430 | 429 | columns: { |
|
491 | 490 | }, |
492 | 491 | footerRowHeight: { |
493 | 492 | type: Number, |
494 | | - require: false, |
495 | 493 | default: 40 |
496 | 494 | }, |
497 | 495 | columnWidthDrag: { |
|
621 | 619 | this.$emit('on-custom-comp', params); |
622 | 620 | }, |
623 | 621 |
|
624 | | - setRowHoverColor(isMouseenter){ |
625 | | -
|
626 | | - if (this.rowHoverColor && this.rowHoverColor.length > 0 && isMouseenter) { |
627 | | -
|
628 | | - return {'background-color': this.rowHoverColor}; |
629 | | - } |
630 | | - }, |
631 | | -
|
632 | | - setRowClickColor(isColumnCellClick){ |
633 | | -
|
634 | | - if (this.rowClickColor && this.rowClickColor.length > 0 && isColumnCellClick) { |
635 | | -
|
636 | | - return {'background-color': this.rowClickColor}; |
637 | | - } |
638 | | - }, |
639 | | -
|
640 | 622 | // 行颜色 |
641 | 623 | trBgColor(num){ |
642 | 624 | if ((this.evenBgColor && this.evenBgColor.length > 0) || (this.oddBgColor && this.oddBgColor.length > 0)) { |
643 | 625 | return num % 2 === 0 ? {'background-color': this.evenBgColor} : {'background-color': this.oddBgColor}; |
644 | 626 | } |
645 | 627 | }, |
646 | 628 |
|
647 | | - handleMouseEnter(rowIndex){ |
648 | | -
|
649 | | - this.internalTableData[rowIndex].__mouseenter__ = true; |
650 | | - this.rowMouseEnter && this.rowMouseEnter(rowIndex); |
651 | | - }, |
652 | | -
|
653 | | - handleMouseOut(rowIndex){ |
654 | | -
|
655 | | - this.internalTableData[rowIndex].__mouseenter__ = false; |
656 | | - this.rowMouseLeave && this.rowMouseLeave(rowIndex); |
657 | | - }, |
658 | | -
|
659 | 629 | // 设置 column 列的样式 |
660 | 630 | setColumnCellClassName(rowIndex, field, rowData){ |
661 | 631 |
|
662 | 632 | return this.columnCellClassName && this.columnCellClassName(rowIndex, field, rowData); |
663 | 633 | }, |
664 | 634 |
|
665 | | - //点击数据行时,回调点击事件 |
666 | | - onCellClick(rowIndex, rowData, column){ |
667 | | - if (Array.isArray(this.internalTableData) && this.internalTableData.length > 0) { |
668 | | -
|
669 | | - var clickCell = this.internalTableData.find(x => x.__columnCellClick__); |
670 | | -
|
671 | | - if (clickCell) { |
672 | | - clickCell.__columnCellClick__ = false; |
673 | | - } |
674 | | -
|
675 | | - this.internalTableData[rowIndex].__columnCellClick__ = true; |
676 | | - } |
677 | | -
|
678 | | - this.onRowClick && this.onRowClick(rowIndex, rowData, column); |
679 | | - }, |
680 | | -
|
681 | 635 | // 获取每个表头列的宽度 |
682 | 636 | titleColumnWidth(fields){ |
683 | 637 | var result = 0; |
|
804 | 758 |
|
805 | 759 | initInternalTableData(data){ |
806 | 760 |
|
807 | | - var result = Array.isArray(this.tableData) ? deepClone(this.tableData) : []; |
808 | | -
|
809 | | - if (result.length > 0) { |
810 | | -
|
811 | | - result.map(x => { |
812 | | - x.__mouseenter__ = false; |
813 | | - x.__columnCellClick__ = false; |
814 | | - }) |
815 | | - } |
816 | | -
|
817 | | - return result; |
| 761 | + return Array.isArray(this.tableData) ? deepClone(this.tableData) : []; |
818 | 762 | }, |
819 | 763 |
|
820 | 764 | // 对外暴露(隐藏显示切换时) |
|
830 | 774 |
|
831 | 775 | this.internalTableData = this.initInternalTableData(this.tableData); |
832 | 776 |
|
833 | | - this.updateCheckboxGroupModel(); |
834 | | -
|
835 | 777 | if (Array.isArray(this.columns) && this.columns.length > 0) { |
836 | 778 |
|
837 | 779 | this.initColumns(); |
838 | 780 | } |
839 | 781 |
|
| 782 | + this.updateCheckboxGroupModel(); |
| 783 | +
|
840 | 784 | this.$nextTick(x => { |
841 | 785 | this.initView(); |
842 | 786 | }) |
|
0 commit comments