|
@@ -7,154 +7,213 @@
|
|
|
'el-table--hidden': isHidden,
|
|
|
'el-table--group': isGroup,
|
|
|
'el-table--fluid-height': maxHeight,
|
|
|
+ 'el-table--scrollable-x': layout.scrollX,
|
|
|
+ 'el-table--scrollable-y': layout.scrollY,
|
|
|
'el-table--enable-row-hover': !store.states.isComplex,
|
|
|
'el-table--enable-row-transition': (store.states.data || []).length !== 0 && (store.states.data || []).length < 100
|
|
|
}, tableSize ? `el-table--${ tableSize }` : '']"
|
|
|
@mouseleave="handleMouseLeave($event)">
|
|
|
<div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
|
|
|
- <div class="el-table__header-wrapper" ref="headerWrapper" v-if="showHeader" v-mousewheel="handleHeaderFooterMousewheel">
|
|
|
+ <div
|
|
|
+ v-if="showHeader"
|
|
|
+ v-mousewheel="handleHeaderFooterMousewheel"
|
|
|
+ class="el-table__header-wrapper"
|
|
|
+ ref="headerWrapper">
|
|
|
<table-header
|
|
|
ref="tableHeader"
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
:border="border"
|
|
|
:default-sort="defaultSort"
|
|
|
- :style="{ width: layout.bodyWidth ? layout.bodyWidth + 'px' : '' }">
|
|
|
+ :style="{
|
|
|
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
|
|
|
+ }">
|
|
|
</table-header>
|
|
|
</div>
|
|
|
<div
|
|
|
class="el-table__body-wrapper"
|
|
|
ref="bodyWrapper"
|
|
|
- :class="[layout.scrollX ? `is-scroll-${scrollPosition}` : 'is-scroll-none']"
|
|
|
+ :class="[layout.scrollX ? `is-scrolling-${scrollPosition}` : 'is-scrolling-none']"
|
|
|
:style="[bodyHeight]">
|
|
|
<table-body
|
|
|
:context="context"
|
|
|
:store="store"
|
|
|
:stripe="stripe"
|
|
|
- :layout="layout"
|
|
|
:row-class-name="rowClassName"
|
|
|
:row-style="rowStyle"
|
|
|
:highlight="highlightCurrentRow"
|
|
|
- :style="{ width: bodyWidth }">
|
|
|
+ :style="{
|
|
|
+ width: bodyWidth
|
|
|
+ }">
|
|
|
</table-body>
|
|
|
- <div :style="{ width: bodyWidth }" class="el-table__empty-block" v-if="!data || data.length === 0">
|
|
|
- <span class="el-table__empty-text"><slot name="empty">{{ emptyText || t('el.table.emptyText') }}</slot></span>
|
|
|
+ <div
|
|
|
+ v-if="!data || data.length === 0"
|
|
|
+ class="el-table__empty-block"
|
|
|
+ ref="emptyBlock"
|
|
|
+ :style="{
|
|
|
+ width: bodyWidth
|
|
|
+ }">
|
|
|
+ <span class="el-table__empty-text">
|
|
|
+ <slot name="empty">{{ emptyText || t('el.table.emptyText') }}</slot>
|
|
|
+ </span>
|
|
|
</div>
|
|
|
- <div class="el-table__append-wrapper" ref="appendWrapper" v-if="$slots.append">
|
|
|
+ <div
|
|
|
+ v-if="$slots.append"
|
|
|
+ class="el-table__append-wrapper"
|
|
|
+ ref="appendWrapper">
|
|
|
<slot name="append"></slot>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="el-table__footer-wrapper" ref="footerWrapper" v-if="showSummary" v-show="data && data.length > 0" v-mousewheel="handleHeaderFooterMousewheel">
|
|
|
+ <div
|
|
|
+ v-if="showSummary"
|
|
|
+ v-show="data && data.length > 0"
|
|
|
+ v-mousewheel="handleHeaderFooterMousewheel"
|
|
|
+ class="el-table__footer-wrapper"
|
|
|
+ ref="footerWrapper">
|
|
|
<table-footer
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
:border="border"
|
|
|
:sum-text="sumText || t('el.table.sumText')"
|
|
|
:summary-method="summaryMethod"
|
|
|
:default-sort="defaultSort"
|
|
|
- :style="{ width: layout.bodyWidth ? layout.bodyWidth + 'px' : '' }">
|
|
|
+ :style="{
|
|
|
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
|
|
|
+ }">
|
|
|
</table-footer>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed" ref="fixedWrapper"
|
|
|
+ <div
|
|
|
v-if="fixedColumns.length > 0"
|
|
|
v-mousewheel="handleFixedMousewheel"
|
|
|
- :style="[
|
|
|
- { width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' },
|
|
|
- fixedHeight
|
|
|
- ]">
|
|
|
- <div class="el-table__fixed-header-wrapper" ref="fixedHeaderWrapper" v-if="showHeader">
|
|
|
+ class="el-table__fixed"
|
|
|
+ ref="fixedWrapper"
|
|
|
+ :style="[{
|
|
|
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
|
|
|
+ },
|
|
|
+ fixedHeight]">
|
|
|
+ <div
|
|
|
+ v-if="showHeader"
|
|
|
+ class="el-table__fixed-header-wrapper"
|
|
|
+ ref="fixedHeaderWrapper" >
|
|
|
<table-header
|
|
|
ref="fixedTableHeader"
|
|
|
fixed="left"
|
|
|
:border="border"
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
- :style="{ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' }"></table-header>
|
|
|
+ :style="{
|
|
|
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
|
|
|
+ }"></table-header>
|
|
|
</div>
|
|
|
<div
|
|
|
class="el-table__fixed-body-wrapper"
|
|
|
ref="fixedBodyWrapper"
|
|
|
- :style="[
|
|
|
- { top: layout.headerHeight + 'px' },
|
|
|
- fixedBodyHeight
|
|
|
- ]">
|
|
|
+ :style="[{
|
|
|
+ top: layout.headerHeight + 'px'
|
|
|
+ },
|
|
|
+ fixedBodyHeight]">
|
|
|
<table-body
|
|
|
fixed="left"
|
|
|
:store="store"
|
|
|
:stripe="stripe"
|
|
|
- :layout="layout"
|
|
|
:highlight="highlightCurrentRow"
|
|
|
:row-class-name="rowClassName"
|
|
|
:row-style="rowStyle"
|
|
|
- :style="{ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' }">
|
|
|
+ :style="{
|
|
|
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
|
|
|
+ }">
|
|
|
</table-body>
|
|
|
- <div class="el-table__append-gutter" :style="{ height: layout.appendHeight + 'px' }" v-if="$slots.append"></div>
|
|
|
+ <div
|
|
|
+ v-if="$slots.append"
|
|
|
+ class="el-table__append-gutter"
|
|
|
+ :style="{
|
|
|
+ height: layout.appendHeight + 'px'
|
|
|
+ }"></div>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed-footer-wrapper" ref="fixedFooterWrapper" v-if="showSummary" v-show="data && data.length > 0">
|
|
|
+ <div
|
|
|
+ v-if="showSummary"
|
|
|
+ v-show="data && data.length > 0"
|
|
|
+ class="el-table__fixed-footer-wrapper"
|
|
|
+ ref="fixedFooterWrapper">
|
|
|
<table-footer
|
|
|
fixed="left"
|
|
|
:border="border"
|
|
|
:sum-text="sumText || t('el.table.sumText')"
|
|
|
:summary-method="summaryMethod"
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
- :style="{ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '' }"></table-footer>
|
|
|
+ :style="{
|
|
|
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
|
|
|
+ }"></table-footer>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed-right" ref="rightFixedWrapper"
|
|
|
+ <div
|
|
|
v-if="rightFixedColumns.length > 0"
|
|
|
v-mousewheel="handleFixedMousewheel"
|
|
|
- :style="[
|
|
|
- { width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' },
|
|
|
- { right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : '' },
|
|
|
- fixedHeight
|
|
|
- ]">
|
|
|
- <div class="el-table__fixed-header-wrapper" ref="rightFixedHeaderWrapper" v-if="showHeader">
|
|
|
+ class="el-table__fixed-right"
|
|
|
+ ref="rightFixedWrapper"
|
|
|
+ :style="[{
|
|
|
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
|
|
|
+ right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : ''
|
|
|
+ },
|
|
|
+ fixedHeight]">
|
|
|
+ <div v-if="showHeader"
|
|
|
+ class="el-table__fixed-header-wrapper"
|
|
|
+ ref="rightFixedHeaderWrapper">
|
|
|
<table-header
|
|
|
ref="rightFixedTableHeader"
|
|
|
fixed="right"
|
|
|
:border="border"
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
- :style="{ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' }"></table-header>
|
|
|
+ :style="{
|
|
|
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : ''
|
|
|
+ }"></table-header>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed-body-wrapper" ref="rightFixedBodyWrapper"
|
|
|
- :style="[
|
|
|
- { top: layout.headerHeight + 'px' },
|
|
|
- fixedBodyHeight
|
|
|
- ]">
|
|
|
+ <div
|
|
|
+ class="el-table__fixed-body-wrapper"
|
|
|
+ ref="rightFixedBodyWrapper"
|
|
|
+ :style="[{
|
|
|
+ top: layout.headerHeight + 'px'
|
|
|
+ },
|
|
|
+ fixedBodyHeight]">
|
|
|
<table-body
|
|
|
fixed="right"
|
|
|
:store="store"
|
|
|
:stripe="stripe"
|
|
|
- :layout="layout"
|
|
|
:row-class-name="rowClassName"
|
|
|
:row-style="rowStyle"
|
|
|
:highlight="highlightCurrentRow"
|
|
|
- :style="{ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' }">
|
|
|
+ :style="{
|
|
|
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : ''
|
|
|
+ }">
|
|
|
</table-body>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed-footer-wrapper" ref="rightFixedFooterWrapper" v-if="showSummary" v-show="data && data.length > 0">
|
|
|
+ <div
|
|
|
+ v-if="showSummary"
|
|
|
+ v-show="data && data.length > 0"
|
|
|
+ class="el-table__fixed-footer-wrapper"
|
|
|
+ ref="rightFixedFooterWrapper">
|
|
|
<table-footer
|
|
|
fixed="right"
|
|
|
:border="border"
|
|
|
:sum-text="sumText || t('el.table.sumText')"
|
|
|
:summary-method="summaryMethod"
|
|
|
:store="store"
|
|
|
- :layout="layout"
|
|
|
- :style="{ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '' }"></table-footer>
|
|
|
+ :style="{
|
|
|
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : ''
|
|
|
+ }"></table-footer>
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div class="el-table__fixed-right-patch"
|
|
|
+ <div
|
|
|
v-if="rightFixedColumns.length > 0"
|
|
|
- :style="{ width: layout.scrollY ? layout.gutterWidth + 'px' : '0', height: layout.headerHeight + 'px' }"></div>
|
|
|
+ class="el-table__fixed-right-patch"
|
|
|
+ ref="rightFixedPatch"
|
|
|
+ :style="{
|
|
|
+ width: layout.scrollY ? layout.gutterWidth + 'px' : '0',
|
|
|
+ height: layout.headerHeight + 'px'
|
|
|
+ }"></div>
|
|
|
<div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script type="text/babel">
|
|
|
import ElCheckbox from 'element-ui/packages/checkbox';
|
|
|
- import throttle from 'throttle-debounce/throttle';
|
|
|
import debounce from 'throttle-debounce/debounce';
|
|
|
import { addResizeListener, removeResizeListener } from 'element-ui/src/utils/resize-event';
|
|
|
import Mousewheel from 'element-ui/src/directives/mousewheel';
|
|
@@ -346,32 +405,44 @@
|
|
|
});
|
|
|
|
|
|
if (this.fit) {
|
|
|
- this.windowResizeListener = throttle(50, () => {
|
|
|
- if (this.$ready) this.doLayout();
|
|
|
- });
|
|
|
- addResizeListener(this.$el, this.windowResizeListener);
|
|
|
+ addResizeListener(this.$el, this.resizeListener);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ resizeListener() {
|
|
|
+ if (!this.$ready) return;
|
|
|
+ let shouldUpdateLayout = false;
|
|
|
+ const el = this.$el;
|
|
|
+ const { width: oldWidth, height: oldHeight } = this.resizeState;
|
|
|
+
|
|
|
+ const width = el.offsetWidth;
|
|
|
+ if (oldWidth !== width) {
|
|
|
+ shouldUpdateLayout = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ const height = el.offsetHeight;
|
|
|
+ if (this.height && oldHeight !== height) {
|
|
|
+ shouldUpdateLayout = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shouldUpdateLayout) {
|
|
|
+ this.resizeState.width = width;
|
|
|
+ this.resizeState.height = height;
|
|
|
+ this.doLayout();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
doLayout() {
|
|
|
- this.store.updateColumns();
|
|
|
- this.updateScrollY();
|
|
|
- this.layout.update();
|
|
|
- this.$nextTick(() => {
|
|
|
- if (this.height) {
|
|
|
- this.layout.setHeight(this.height);
|
|
|
- } else if (this.maxHeight) {
|
|
|
- this.layout.setMaxHeight(this.maxHeight);
|
|
|
- } else if (this.shouldUpdateHeight) {
|
|
|
- this.layout.updateHeight();
|
|
|
- }
|
|
|
- });
|
|
|
+ if (this.shouldUpdateHeight) {
|
|
|
+ this.layout.updateElsHeight();
|
|
|
+ }
|
|
|
+ this.layout.updateColumnsWidth();
|
|
|
}
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
- this.tableId = 'el-table_' + tableIdSeed + '_';
|
|
|
- this.debouncedLayout = debounce(50, () => this.doLayout());
|
|
|
+ this.tableId = 'el-table_' + tableIdSeed++;
|
|
|
+ this.debouncedUpdateLayout = debounce(50, () => this.doLayout());
|
|
|
},
|
|
|
|
|
|
computed: {
|
|
@@ -384,7 +455,7 @@
|
|
|
},
|
|
|
|
|
|
shouldUpdateHeight() {
|
|
|
- return typeof this.height === 'number' ||
|
|
|
+ return this.height ||
|
|
|
this.fixedColumns.length > 0 ||
|
|
|
this.rightFixedColumns.length > 0;
|
|
|
},
|
|
@@ -409,34 +480,29 @@
|
|
|
return this.store.states.rightFixedColumns;
|
|
|
},
|
|
|
|
|
|
- bodyHeight() {
|
|
|
- let style = {};
|
|
|
+ bodyWidth() {
|
|
|
+ const { bodyWidth, scrollY, gutterWidth } = this.layout;
|
|
|
+ return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : '';
|
|
|
+ },
|
|
|
|
|
|
+ bodyHeight() {
|
|
|
if (this.height) {
|
|
|
- style = {
|
|
|
+ return {
|
|
|
height: this.layout.bodyHeight ? this.layout.bodyHeight + 'px' : ''
|
|
|
};
|
|
|
} else if (this.maxHeight) {
|
|
|
- style = {
|
|
|
+ return {
|
|
|
'max-height': (this.showHeader
|
|
|
? this.maxHeight - this.layout.headerHeight - this.layout.footerHeight
|
|
|
: this.maxHeight - this.layout.footerHeight) + 'px'
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
- return style;
|
|
|
- },
|
|
|
-
|
|
|
- bodyWidth() {
|
|
|
- const { bodyWidth, scrollY, gutterWidth } = this.layout;
|
|
|
- return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : '';
|
|
|
+ return {};
|
|
|
},
|
|
|
|
|
|
fixedBodyHeight() {
|
|
|
- let style = {};
|
|
|
-
|
|
|
if (this.height) {
|
|
|
- style = {
|
|
|
+ return {
|
|
|
height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : ''
|
|
|
};
|
|
|
} else if (this.maxHeight) {
|
|
@@ -448,38 +514,40 @@
|
|
|
|
|
|
maxHeight -= this.layout.footerHeight;
|
|
|
|
|
|
- style = {
|
|
|
+ return {
|
|
|
'max-height': maxHeight + 'px'
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- return style;
|
|
|
+ return {};
|
|
|
},
|
|
|
|
|
|
fixedHeight() {
|
|
|
- let style = {};
|
|
|
-
|
|
|
if (this.maxHeight) {
|
|
|
- style = {
|
|
|
+ return {
|
|
|
bottom: (this.layout.scrollX && this.data.length) ? this.layout.gutterWidth + 'px' : ''
|
|
|
};
|
|
|
} else {
|
|
|
- style = {
|
|
|
+ return {
|
|
|
height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : ''
|
|
|
};
|
|
|
}
|
|
|
-
|
|
|
- return style;
|
|
|
}
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
- height(value) {
|
|
|
- this.layout.setHeight(value);
|
|
|
+ height: {
|
|
|
+ immediate: true,
|
|
|
+ handler(value) {
|
|
|
+ this.layout.setHeight(value);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- maxHeight(value) {
|
|
|
- this.layout.setMaxHeight(value);
|
|
|
+ maxHeight: {
|
|
|
+ immediate: true,
|
|
|
+ handler(value) {
|
|
|
+ this.layout.setMaxHeight(value);
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
currentRowKey(newVal) {
|
|
@@ -488,8 +556,8 @@
|
|
|
|
|
|
data: {
|
|
|
immediate: true,
|
|
|
- handler(val) {
|
|
|
- this.store.commit('setData', val);
|
|
|
+ handler(value) {
|
|
|
+ this.store.commit('setData', value);
|
|
|
if (this.$ready) {
|
|
|
this.$nextTick(() => {
|
|
|
this.doLayout();
|
|
@@ -509,13 +577,19 @@
|
|
|
},
|
|
|
|
|
|
destroyed() {
|
|
|
- if (this.windowResizeListener) removeResizeListener(this.$el, this.windowResizeListener);
|
|
|
+ if (this.resizeListener) removeResizeListener(this.$el, this.resizeListener);
|
|
|
},
|
|
|
|
|
|
mounted() {
|
|
|
this.bindEvents();
|
|
|
+ this.store.updateColumns();
|
|
|
this.doLayout();
|
|
|
|
|
|
+ this.resizeState = {
|
|
|
+ width: this.$el.offsetWidth,
|
|
|
+ height: this.$el.offsetHeight
|
|
|
+ };
|
|
|
+
|
|
|
// init filters
|
|
|
this.store.states.columns.forEach(column => {
|
|
|
if (column.filteredValue && column.filteredValue.length) {
|
|
@@ -542,11 +616,15 @@
|
|
|
showHeader: this.showHeader
|
|
|
});
|
|
|
return {
|
|
|
- store,
|
|
|
layout,
|
|
|
+ store,
|
|
|
isHidden: false,
|
|
|
renderExpanded: null,
|
|
|
resizeProxyVisible: false,
|
|
|
+ resizeState: {
|
|
|
+ width: null,
|
|
|
+ height: null
|
|
|
+ },
|
|
|
// 是否拥有多级表头
|
|
|
isGroup: false,
|
|
|
scrollPosition: 'left'
|