umy-ui-table 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/lib/button.js +1 -0
- package/lib/icon.js +1 -0
- package/lib/index.js +1 -0
- package/lib/locale/format.js +56 -0
- package/lib/locale/index.js +72 -0
- package/lib/locale/lang/en.js +123 -0
- package/lib/locale/lang/zh-CN.js +119 -0
- package/lib/mixins/locale.js +17 -0
- package/lib/theme-chalk/base.css +0 -0
- package/lib/theme-chalk/button.css +1 -0
- package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
- package/lib/theme-chalk/fonts/element-icons.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
- package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
- package/lib/theme-chalk/icon.css +1 -0
- package/lib/theme-chalk/index.css +1 -0
- package/lib/theme-chalk/u-table-column.css +0 -0
- package/lib/theme-chalk/u-table.css +1 -0
- package/lib/theme-chalk/ux-grid.css +1 -0
- package/lib/theme-chalk/ux-table-column.css +0 -0
- package/lib/u-table-column.js +1 -0
- package/lib/u-table.js +1 -0
- package/lib/umd/locale/en.js +139 -0
- package/lib/umd/locale/zh-CN.js +135 -0
- package/lib/umy-ui.common.js +1 -0
- package/lib/utils/svg.js +33 -0
- package/lib/utils/types.js +35 -0
- package/lib/utils/util.js +268 -0
- package/lib/ux-grid.js +1 -0
- package/lib/ux-table-column.js +1 -0
- package/package.json +117 -0
- package/packages/button/index.js +7 -0
- package/packages/button/src/button-group.vue +10 -0
- package/packages/button/src/button.vue +166 -0
- package/packages/checkbox/index.js +8 -0
- package/packages/checkbox/src/checkbox-button.vue +199 -0
- package/packages/checkbox/src/checkbox-group.vue +48 -0
- package/packages/checkbox/src/checkbox.vue +222 -0
- package/packages/checkbox-button/index.js +8 -0
- package/packages/checkbox-group/index.js +8 -0
- package/packages/icon/index.js +7 -0
- package/packages/icon/src/icon.vue +40 -0
- package/packages/input/index.js +2 -0
- package/packages/input/src/calcTextareaHeight.js +104 -0
- package/packages/input/src/input.vue +424 -0
- package/packages/option/index.js +2 -0
- package/packages/pagination/index.js +2 -0
- package/packages/pagination/src/pager.vue +163 -0
- package/packages/pagination/src/pagination.js +386 -0
- package/packages/scrollbar/index.js +8 -0
- package/packages/scrollbar/src/bar.js +92 -0
- package/packages/scrollbar/src/main.js +130 -0
- package/packages/scrollbar/src/util.js +34 -0
- package/packages/select/index.js +2 -0
- package/packages/select/src/navigation-mixin.js +54 -0
- package/packages/select/src/option-group.vue +60 -0
- package/packages/select/src/option.vue +163 -0
- package/packages/select/src/select-dropdown.vue +74 -0
- package/packages/select/src/select.vue +889 -0
- package/packages/table/index.js +8 -0
- package/packages/table/src/config.js +123 -0
- package/packages/table/src/dropdown.js +28 -0
- package/packages/table/src/filter-panel.vue +194 -0
- package/packages/table/src/layout-observer.js +68 -0
- package/packages/table/src/store/current.js +71 -0
- package/packages/table/src/store/expand.js +65 -0
- package/packages/table/src/store/helper.js +37 -0
- package/packages/table/src/store/index.js +145 -0
- package/packages/table/src/store/tree.js +208 -0
- package/packages/table/src/store/watcher.js +448 -0
- package/packages/table/src/table-body.js +493 -0
- package/packages/table/src/table-column.js +381 -0
- package/packages/table/src/table-footer.js +174 -0
- package/packages/table/src/table-header.js +537 -0
- package/packages/table/src/table-layout.js +231 -0
- package/packages/table/src/table.vue +741 -0
- package/packages/table/src/util.js +256 -0
- package/packages/tag/index.js +8 -0
- package/packages/tag/src/tag.vue +58 -0
- package/packages/tools/directives/mousewheel.js +18 -0
- package/packages/tools/directives/repeat-click.js +24 -0
- package/packages/tools/locale/format.js +46 -0
- package/packages/tools/locale/index.js +48 -0
- package/packages/tools/locale/lang/en.js +120 -0
- package/packages/tools/locale/lang/zh-CN.js +116 -0
- package/packages/tools/mixins/emitter.js +33 -0
- package/packages/tools/mixins/focus.js +9 -0
- package/packages/tools/mixins/locale.js +9 -0
- package/packages/tools/mixins/migrating.js +54 -0
- package/packages/tools/transitions/collapse-transition.js +77 -0
- package/packages/tools/utils/after-leave.js +27 -0
- package/packages/tools/utils/aria-dialog.js +90 -0
- package/packages/tools/utils/aria-utils.js +122 -0
- package/packages/tools/utils/clickoutside.js +76 -0
- package/packages/tools/utils/date-util.js +292 -0
- package/packages/tools/utils/date.js +368 -0
- package/packages/tools/utils/dom.js +227 -0
- package/packages/tools/utils/menu/aria-menubar.js +14 -0
- package/packages/tools/utils/menu/aria-menuitem.js +49 -0
- package/packages/tools/utils/menu/aria-submenu.js +59 -0
- package/packages/tools/utils/merge.js +15 -0
- package/packages/tools/utils/popper.js +1276 -0
- package/packages/tools/utils/popup/index.js +218 -0
- package/packages/tools/utils/popup/popup-manager.js +194 -0
- package/packages/tools/utils/resize-event.js +35 -0
- package/packages/tools/utils/scroll-into-view.js +27 -0
- package/packages/tools/utils/scrollbar-width.js +29 -0
- package/packages/tools/utils/shared.js +7 -0
- package/packages/tools/utils/svg.js +1 -0
- package/packages/tools/utils/types.js +28 -0
- package/packages/tools/utils/util.js +241 -0
- package/packages/tools/utils/vdom.js +5 -0
- package/packages/tools/utils/vue-popper.js +198 -0
- package/packages/tooltip/index.js +8 -0
- package/packages/tooltip/src/main.js +241 -0
- package/packages/u-table/index.js +4 -0
- package/packages/u-table/revise-el-table-mixins/index.js +10 -0
- package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
- package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
- package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
- package/packages/u-table/src/u-table.vue +248 -0
- package/packages/u-table/u-table-mixins/index.js +483 -0
- package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
- package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
- package/packages/u-table-column/index.js +8 -0
- package/packages/utils/common.js +27 -0
- package/packages/ux-grid/index.js +6 -0
- package/packages/ux-grid/mixins/index.js +707 -0
- package/packages/ux-grid/src/interceptor.js +6 -0
- package/packages/ux-grid/src/ux-grid.vue +301 -0
- package/packages/ux-table-column/index.js +10 -0
- package/tools/locale/format.js +46 -0
- package/tools/locale/index.js +54 -0
- package/tools/locale/lang/en.js +120 -0
- package/tools/locale/lang/zh-CN.js +116 -0
- package/tools/mixins/locale.js +9 -0
- package/tools/utils/svg.js +1 -0
- package/tools/utils/types.js +28 -0
- package/tools/utils/util.js +241 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import Popper from '../../tools/utils/vue-popper';
|
|
2
|
+
import debounce from 'throttle-debounce/debounce';
|
|
3
|
+
import { addClass, removeClass, on, off } from '../../tools/utils/dom';
|
|
4
|
+
import { generateId } from '../../tools/utils/util';
|
|
5
|
+
import Vue from 'vue';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: 'ElTooltip',
|
|
9
|
+
|
|
10
|
+
mixins: [Popper],
|
|
11
|
+
|
|
12
|
+
props: {
|
|
13
|
+
openDelay: {
|
|
14
|
+
type: Number,
|
|
15
|
+
default: 0
|
|
16
|
+
},
|
|
17
|
+
disabled: Boolean,
|
|
18
|
+
manual: Boolean,
|
|
19
|
+
effect: {
|
|
20
|
+
type: String,
|
|
21
|
+
default: 'dark'
|
|
22
|
+
},
|
|
23
|
+
arrowOffset: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: 0
|
|
26
|
+
},
|
|
27
|
+
popperClass: String,
|
|
28
|
+
content: String,
|
|
29
|
+
visibleArrow: {
|
|
30
|
+
default: true
|
|
31
|
+
},
|
|
32
|
+
transition: {
|
|
33
|
+
type: String,
|
|
34
|
+
default: 'el-fade-in-linear'
|
|
35
|
+
},
|
|
36
|
+
popperOptions: {
|
|
37
|
+
default() {
|
|
38
|
+
return {
|
|
39
|
+
boundariesPadding: 10,
|
|
40
|
+
gpuAcceleration: false
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
enterable: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: true
|
|
47
|
+
},
|
|
48
|
+
hideAfter: {
|
|
49
|
+
type: Number,
|
|
50
|
+
default: 0
|
|
51
|
+
},
|
|
52
|
+
tabindex: {
|
|
53
|
+
type: Number,
|
|
54
|
+
default: 0
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
data() {
|
|
59
|
+
return {
|
|
60
|
+
tooltipId: `el-tooltip-${generateId()}`,
|
|
61
|
+
timeoutPending: null,
|
|
62
|
+
focusing: false
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
beforeCreate() {
|
|
66
|
+
if (this.$isServer) return;
|
|
67
|
+
|
|
68
|
+
this.popperVM = new Vue({
|
|
69
|
+
data: { node: '' },
|
|
70
|
+
render(h) {
|
|
71
|
+
return this.node;
|
|
72
|
+
}
|
|
73
|
+
}).$mount();
|
|
74
|
+
|
|
75
|
+
this.debounceClose = debounce(200, () => this.handleClosePopper());
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
render(h) {
|
|
79
|
+
if (this.popperVM) {
|
|
80
|
+
this.popperVM.node = (
|
|
81
|
+
<transition
|
|
82
|
+
name={ this.transition }
|
|
83
|
+
onAfterLeave={ this.doDestroy }>
|
|
84
|
+
<div
|
|
85
|
+
onMouseleave={ () => { this.setExpectedState(false); this.debounceClose(); } }
|
|
86
|
+
onMouseenter= { () => { this.setExpectedState(true); } }
|
|
87
|
+
ref="popper"
|
|
88
|
+
role="tooltip"
|
|
89
|
+
id={this.tooltipId}
|
|
90
|
+
aria-hidden={ (this.disabled || !this.showPopper) ? 'true' : 'false' }
|
|
91
|
+
v-show={!this.disabled && this.showPopper}
|
|
92
|
+
class={
|
|
93
|
+
['el-tooltip__popper', 'is-' + this.effect, this.popperClass]
|
|
94
|
+
}>
|
|
95
|
+
{ this.$slots.content || this.content }
|
|
96
|
+
</div>
|
|
97
|
+
</transition>);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const firstElement = this.getFirstElement();
|
|
101
|
+
if (!firstElement) return null;
|
|
102
|
+
|
|
103
|
+
const data = firstElement.data = firstElement.data || {};
|
|
104
|
+
data.staticClass = this.addTooltipClass(data.staticClass);
|
|
105
|
+
|
|
106
|
+
return firstElement;
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
mounted() {
|
|
110
|
+
this.referenceElm = this.$el;
|
|
111
|
+
if (this.$el.nodeType === 1) {
|
|
112
|
+
this.$el.setAttribute('aria-describedby', this.tooltipId);
|
|
113
|
+
this.$el.setAttribute('tabindex', this.tabindex);
|
|
114
|
+
on(this.referenceElm, 'mouseenter', this.show);
|
|
115
|
+
on(this.referenceElm, 'mouseleave', this.hide);
|
|
116
|
+
on(this.referenceElm, 'focus', () => {
|
|
117
|
+
if (!this.$slots.default || !this.$slots.default.length) {
|
|
118
|
+
this.handleFocus();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const instance = this.$slots.default[0].componentInstance;
|
|
122
|
+
if (instance && instance.focus) {
|
|
123
|
+
instance.focus();
|
|
124
|
+
} else {
|
|
125
|
+
this.handleFocus();
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
on(this.referenceElm, 'blur', this.handleBlur);
|
|
129
|
+
on(this.referenceElm, 'click', this.removeFocusing);
|
|
130
|
+
}
|
|
131
|
+
// fix issue https://github.com/ElemeFE/element/issues/14424
|
|
132
|
+
if (this.value && this.popperVM) {
|
|
133
|
+
this.popperVM.$nextTick(() => {
|
|
134
|
+
if (this.value) {
|
|
135
|
+
this.updatePopper();
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
watch: {
|
|
141
|
+
focusing(val) {
|
|
142
|
+
if (val) {
|
|
143
|
+
addClass(this.referenceElm, 'focusing');
|
|
144
|
+
} else {
|
|
145
|
+
removeClass(this.referenceElm, 'focusing');
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
methods: {
|
|
150
|
+
show() {
|
|
151
|
+
this.setExpectedState(true);
|
|
152
|
+
this.handleShowPopper();
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
hide() {
|
|
156
|
+
this.setExpectedState(false);
|
|
157
|
+
this.debounceClose();
|
|
158
|
+
},
|
|
159
|
+
handleFocus() {
|
|
160
|
+
this.focusing = true;
|
|
161
|
+
this.show();
|
|
162
|
+
},
|
|
163
|
+
handleBlur() {
|
|
164
|
+
this.focusing = false;
|
|
165
|
+
this.hide();
|
|
166
|
+
},
|
|
167
|
+
removeFocusing() {
|
|
168
|
+
this.focusing = false;
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
addTooltipClass(prev) {
|
|
172
|
+
if (!prev) {
|
|
173
|
+
return 'el-tooltip';
|
|
174
|
+
} else {
|
|
175
|
+
return 'el-tooltip ' + prev.replace('el-tooltip', '');
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
handleShowPopper() {
|
|
180
|
+
if (!this.expectedState || this.manual) return;
|
|
181
|
+
clearTimeout(this.timeout);
|
|
182
|
+
this.timeout = setTimeout(() => {
|
|
183
|
+
this.showPopper = true;
|
|
184
|
+
}, this.openDelay);
|
|
185
|
+
|
|
186
|
+
if (this.hideAfter > 0) {
|
|
187
|
+
this.timeoutPending = setTimeout(() => {
|
|
188
|
+
this.showPopper = false;
|
|
189
|
+
}, this.hideAfter);
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
handleClosePopper() {
|
|
194
|
+
if (this.enterable && this.expectedState || this.manual) return;
|
|
195
|
+
clearTimeout(this.timeout);
|
|
196
|
+
|
|
197
|
+
if (this.timeoutPending) {
|
|
198
|
+
clearTimeout(this.timeoutPending);
|
|
199
|
+
}
|
|
200
|
+
this.showPopper = false;
|
|
201
|
+
|
|
202
|
+
if (this.disabled) {
|
|
203
|
+
this.doDestroy();
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
setExpectedState(expectedState) {
|
|
208
|
+
if (expectedState === false) {
|
|
209
|
+
clearTimeout(this.timeoutPending);
|
|
210
|
+
}
|
|
211
|
+
this.expectedState = expectedState;
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
getFirstElement() {
|
|
215
|
+
const slots = this.$slots.default;
|
|
216
|
+
if (!Array.isArray(slots)) return null;
|
|
217
|
+
let element = null;
|
|
218
|
+
for (let index = 0; index < slots.length; index++) {
|
|
219
|
+
if (slots[index] && slots[index].tag) {
|
|
220
|
+
element = slots[index];
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
return element;
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
|
|
227
|
+
beforeDestroy() {
|
|
228
|
+
this.popperVM && this.popperVM.$destroy();
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
destroyed() {
|
|
232
|
+
const reference = this.referenceElm;
|
|
233
|
+
if (reference.nodeType === 1) {
|
|
234
|
+
off(reference, 'mouseenter', this.show);
|
|
235
|
+
off(reference, 'mouseleave', this.hide);
|
|
236
|
+
off(reference, 'focus', this.handleFocus);
|
|
237
|
+
off(reference, 'blur', this.handleBlur);
|
|
238
|
+
off(reference, 'click', this.removeFocusing);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import Table from "../../table";
|
|
2
|
+
|
|
3
|
+
import "./table-extend";
|
|
4
|
+
import tableMixins from "./table.mixins";
|
|
5
|
+
import uTableTreeMixins from "../u-table-tree-mixins/u-table-tree-mixins";
|
|
6
|
+
if (!Table.mixins) {
|
|
7
|
+
Table.mixins = [];
|
|
8
|
+
}
|
|
9
|
+
Table.mixins.push(tableMixins);
|
|
10
|
+
Table.mixins.push(uTableTreeMixins);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import ElTable from "../../../packages/table";
|
|
2
|
+
|
|
3
|
+
import VirtualTableBodyRender from "./virtual-table-body-render.js";
|
|
4
|
+
|
|
5
|
+
const ElTableBody = ElTable.components.TableBody; // 表体
|
|
6
|
+
|
|
7
|
+
// 改变表格数据流
|
|
8
|
+
const oldDataComputed = ElTableBody.computed.data;
|
|
9
|
+
ElTableBody.computed.data = function () {
|
|
10
|
+
const { table } = this;
|
|
11
|
+
const tableData = oldDataComputed.call(this);
|
|
12
|
+
if (table.useVirtual) {
|
|
13
|
+
return tableData.slice(table.start, table.end);
|
|
14
|
+
} else {
|
|
15
|
+
return tableData;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// const oldHoverRowHandler = ElTableBody.watch && ElTableBody.watch['store.states.hoverRow']
|
|
20
|
+
// if (oldHoverRowHandler) {
|
|
21
|
+
// ElTableBody.watch['store.states.hoverRow'] = function (newVal, oldVal) {
|
|
22
|
+
// if (!this.table.useVirtual) {
|
|
23
|
+
// oldHoverRowHandler && oldHoverRowHandler.call(this, newVal, oldVal)
|
|
24
|
+
// }
|
|
25
|
+
// }
|
|
26
|
+
// }
|
|
27
|
+
|
|
28
|
+
// 表体行索引
|
|
29
|
+
ElTableBody.methods.getIndex = function (index) {
|
|
30
|
+
return this.table.start + index;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 添加表格行样式
|
|
34
|
+
const oldGetRowClassHandler = ElTableBody.methods.getRowClass;
|
|
35
|
+
ElTableBody.methods.getRowClass = function (row, rowIndex) {
|
|
36
|
+
let classes = oldGetRowClassHandler.call(this, row, rowIndex);
|
|
37
|
+
// 当表格行被禁止,添加不透明度
|
|
38
|
+
if (row.disabled) {
|
|
39
|
+
classes.push("pl-disabled");
|
|
40
|
+
}
|
|
41
|
+
// if (this.table.useVirtual && rowIndex === this.store.states.hoverRow && (this.table.rightFixedColumns.length || this.table.fixedColumns.length)) {
|
|
42
|
+
// // 兼容element-ui低版本
|
|
43
|
+
// if (Object.prototype.toString.call(classes) === '[object Array]') {
|
|
44
|
+
// classes.push('hover-row')
|
|
45
|
+
// } else if (typeof classes === 'string') {
|
|
46
|
+
// classes += ' hover-row'
|
|
47
|
+
// }
|
|
48
|
+
// }
|
|
49
|
+
return classes;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// 修改ele表体源码 (进行重新渲染)
|
|
53
|
+
const oldRender = ElTableBody.render;
|
|
54
|
+
ElTableBody.render = function (h) {
|
|
55
|
+
if (this.table.useVirtual) {
|
|
56
|
+
return VirtualTableBodyRender.call(this, h);
|
|
57
|
+
} else {
|
|
58
|
+
return oldRender.call(this, h);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
// 扩展el-table成为pl-table
|
|
2
|
+
import Vue from "vue";
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
rowHeight: {
|
|
7
|
+
type: Number,
|
|
8
|
+
default: 60,
|
|
9
|
+
},
|
|
10
|
+
excessRows: {
|
|
11
|
+
type: Number,
|
|
12
|
+
default: 3,
|
|
13
|
+
},
|
|
14
|
+
rowId: String,
|
|
15
|
+
headerDragStyle: {
|
|
16
|
+
type: Boolean,
|
|
17
|
+
default: false,
|
|
18
|
+
},
|
|
19
|
+
tooltipPlacement: {
|
|
20
|
+
default: "top",
|
|
21
|
+
type: String,
|
|
22
|
+
},
|
|
23
|
+
useVirtual: {
|
|
24
|
+
type: Boolean,
|
|
25
|
+
default: false,
|
|
26
|
+
},
|
|
27
|
+
// 大数据下是否更改全选框,单选框卡顿问题
|
|
28
|
+
bigDataCheckbox: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: false,
|
|
31
|
+
},
|
|
32
|
+
fixedColumnsRoll: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: false,
|
|
35
|
+
},
|
|
36
|
+
showHeaderOverflow: { type: [Boolean, String], default: null }, // 设置表头所有内容过长时显示为省略号
|
|
37
|
+
showBodyOverflow: { type: [Boolean, String], default: null }, // 设置表体所有内容过长时显示为省略号
|
|
38
|
+
selectTrClass: String, // 如果当前行被选中了 type类型为selection,就给当前行给个类样式
|
|
39
|
+
dataChangesScrollTop: Boolean, // 数据变化滚动到顶部
|
|
40
|
+
},
|
|
41
|
+
data() {
|
|
42
|
+
return {
|
|
43
|
+
scrollTop: 0,
|
|
44
|
+
scrollLeft: 0,
|
|
45
|
+
innerTop: 0,
|
|
46
|
+
start: 0,
|
|
47
|
+
end: 0,
|
|
48
|
+
judgeFlse: false,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
computed: {
|
|
52
|
+
visibleCount() {
|
|
53
|
+
return Math.ceil(parseFloat(this.height || this.maxHeight) / this.rowHeight);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
virtualBodyHeight() {
|
|
57
|
+
const { data } = this.store.states;
|
|
58
|
+
return data ? data.length * this.rowHeight : 0;
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
watch: {
|
|
62
|
+
scrollTop: {
|
|
63
|
+
immediate: true,
|
|
64
|
+
handler(top) {
|
|
65
|
+
if (parseFloat(top) <= 0) {
|
|
66
|
+
this.scrollTop = 0;
|
|
67
|
+
}
|
|
68
|
+
this.computeScrollToRow(top);
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
useVirtual: {
|
|
73
|
+
immediate: true,
|
|
74
|
+
handler(newVal) {
|
|
75
|
+
// 把当前状态存入store.states里面
|
|
76
|
+
this.store.states.useVirtual = newVal;
|
|
77
|
+
this.computeScrollToRow(this.scrollTop);
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
bigDataCheckbox: {
|
|
82
|
+
immediate: true,
|
|
83
|
+
handler(newVal) {
|
|
84
|
+
// 把当前状态存入store.states里面
|
|
85
|
+
this.store.states.bigDataCheckbox = newVal;
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
virtualBodyHeight() {
|
|
90
|
+
if (this.useVirtual) setTimeout(this.doLayout, 10);
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
height: {
|
|
94
|
+
immediate: true,
|
|
95
|
+
handler(value) {
|
|
96
|
+
if (this.useVirtual) {
|
|
97
|
+
this.layout.setHeight(value);
|
|
98
|
+
this.computeScrollToRow(this.scrollTop);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
maxHeight: {
|
|
104
|
+
immediate: true,
|
|
105
|
+
handler(value) {
|
|
106
|
+
if (this.useVirtual) {
|
|
107
|
+
this.layout.setMaxHeight(value);
|
|
108
|
+
this.computeScrollToRow(this.scrollTop);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
data: {
|
|
114
|
+
immediate: true,
|
|
115
|
+
handler(value) {
|
|
116
|
+
if (this.useVirtual) {
|
|
117
|
+
if (this.rowId) {
|
|
118
|
+
this.plTreeInit(value);
|
|
119
|
+
} else {
|
|
120
|
+
this.store.commit("setData", value);
|
|
121
|
+
}
|
|
122
|
+
if (this.dataChangesScrollTop) {
|
|
123
|
+
this.pagingScrollTop(0, this.scrollLeft);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
mounted() {
|
|
130
|
+
// 暴露store对象对pl-table
|
|
131
|
+
this.$parent.newTableStore = this.store;
|
|
132
|
+
this.bindEvent("bind");
|
|
133
|
+
},
|
|
134
|
+
methods: {
|
|
135
|
+
bindEvent(action) {
|
|
136
|
+
const tableBodyWrapper = this.$el.querySelector(".el-table__body-wrapper");
|
|
137
|
+
if (!this.binded && action === "bind") {
|
|
138
|
+
tableBodyWrapper.addEventListener("scroll", this.handleScroll);
|
|
139
|
+
this.binded = true;
|
|
140
|
+
} else if (this.binded && action === "unbind") {
|
|
141
|
+
tableBodyWrapper.removeEventListener("scroll", this.handleScroll);
|
|
142
|
+
this.binded = false;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
scrollBottom() {
|
|
147
|
+
const { data } = this.store.states;
|
|
148
|
+
this.pagingScrollTop(data.length * this.rowHeight);
|
|
149
|
+
},
|
|
150
|
+
// 表体滚动到什么位置
|
|
151
|
+
pagingScrollTop(top = 0, left = 0, type) {
|
|
152
|
+
if (!this.$refs.bodyWrapper) return Vue.nextTick(() => this.pagingScrollTop(top, left));
|
|
153
|
+
if (this.$refs.bodyWrapper) {
|
|
154
|
+
if (type && type === "不倒计时") {
|
|
155
|
+
this.$nextTick(() => {
|
|
156
|
+
this.$refs.bodyWrapper.scrollTop = top;
|
|
157
|
+
this.$refs.bodyWrapper.scrollLeft = left || this.scrollLeft;
|
|
158
|
+
const bodyScrollHeight = this.visibleCount * this.rowHeight;
|
|
159
|
+
if (this.virtualBodyHeight < top + bodyScrollHeight) {
|
|
160
|
+
top = this.virtualBodyHeight - bodyScrollHeight;
|
|
161
|
+
}
|
|
162
|
+
this.scrollTop = top;
|
|
163
|
+
this.scrollLeft = left || this.scrollLeft;
|
|
164
|
+
});
|
|
165
|
+
} else {
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
this.$refs.bodyWrapper.scrollTop = top;
|
|
168
|
+
this.$refs.bodyWrapper.scrollLeft = left || this.scrollLeft;
|
|
169
|
+
const bodyScrollHeight = this.visibleCount * this.rowHeight;
|
|
170
|
+
if (this.virtualBodyHeight < top + bodyScrollHeight) {
|
|
171
|
+
top = this.virtualBodyHeight - bodyScrollHeight;
|
|
172
|
+
}
|
|
173
|
+
this.scrollTop = top;
|
|
174
|
+
this.scrollLeft = left || this.scrollLeft;
|
|
175
|
+
}, 10);
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error("表格还没加载完毕");
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
|
|
182
|
+
computeScrollToRow(scrollTop) {
|
|
183
|
+
if (!this.useVirtual) return;
|
|
184
|
+
let startIndex = parseInt(scrollTop / this.rowHeight);
|
|
185
|
+
|
|
186
|
+
const { start, end } = this.getVisibleRange(startIndex);
|
|
187
|
+
|
|
188
|
+
this.$parent.position = {
|
|
189
|
+
start: start,
|
|
190
|
+
end: end,
|
|
191
|
+
};
|
|
192
|
+
this.start = start;
|
|
193
|
+
this.end = end;
|
|
194
|
+
this.innerTop = this.start * this.rowHeight;
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
getVisibleRange(expectStart) {
|
|
198
|
+
const start = expectStart - this.excessRows;
|
|
199
|
+
return {
|
|
200
|
+
start: start >= 0 ? start : 0,
|
|
201
|
+
end: expectStart + this.visibleCount + this.excessRows,
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
handleScroll(e) {
|
|
206
|
+
const ele = e.srcElement || e.target;
|
|
207
|
+
let { scrollTop, scrollLeft } = ele;
|
|
208
|
+
if (this.useVirtual) {
|
|
209
|
+
const bodyScrollHeight = this.visibleCount * this.rowHeight;
|
|
210
|
+
// 解决 滚动时 行hover高亮的问题
|
|
211
|
+
this.store.states.hoverRow = null;
|
|
212
|
+
if (this.virtualBodyHeight < scrollTop + bodyScrollHeight) {
|
|
213
|
+
scrollTop = this.virtualBodyHeight - bodyScrollHeight;
|
|
214
|
+
this.judgeFlse = true;
|
|
215
|
+
} else {
|
|
216
|
+
this.judgeFlse = false;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
this.scrollTop = scrollTop;
|
|
220
|
+
this.scrollLeft = scrollLeft;
|
|
221
|
+
// 当表格滚动暴露滚动事件
|
|
222
|
+
let copyTop = parseFloat(this.scrollTop <= 0) ? 0 : this.scrollTop;
|
|
223
|
+
const obj = { scrollTop: copyTop, scrollLeft: this.scrollLeft, table: this, judgeFlse: this.judgeFlse };
|
|
224
|
+
this.$emit("tableBodyScroll", obj, e);
|
|
225
|
+
},
|
|
226
|
+
// 设置表格数据
|
|
227
|
+
reloadData(data) {
|
|
228
|
+
if (this.rowId && this.useVirtual) {
|
|
229
|
+
return this.plTreeInit(data);
|
|
230
|
+
} else {
|
|
231
|
+
this.store.commit("setData", data);
|
|
232
|
+
}
|
|
233
|
+
if (this.dataChangesScrollTop) {
|
|
234
|
+
this.pagingScrollTop(0, this.scrollLeft);
|
|
235
|
+
}
|
|
236
|
+
return this.$nextTick();
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
activated() {
|
|
240
|
+
if (this.useVirtual) {
|
|
241
|
+
this.bindEvent("bind");
|
|
242
|
+
if (this.scrollTop || this.scrollLeft) {
|
|
243
|
+
if (this.judgeFlse) {
|
|
244
|
+
this.scrollBottom();
|
|
245
|
+
} else {
|
|
246
|
+
this.pagingScrollTop(this.scrollTop);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
deactivated() {
|
|
252
|
+
if (this.useVirtual) {
|
|
253
|
+
this.bindEvent("unbind");
|
|
254
|
+
}
|
|
255
|
+
},
|
|
256
|
+
beforeDestroy() {
|
|
257
|
+
if (this.useVirtual) {
|
|
258
|
+
this.bindEvent("unbind");
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
export default function render(h) {
|
|
2
|
+
const columnsHidden = this.columns.map((column, index) => this.isColumnHidden(index));
|
|
3
|
+
let rows = this.data;
|
|
4
|
+
if (this.store.states.lazy && Object.keys(this.store.states.lazyTreeNodeMap).length) {
|
|
5
|
+
rows = rows.reduce((prev, item) => {
|
|
6
|
+
prev.push(item);
|
|
7
|
+
const rowKey = this.store.table.getRowKey(item);
|
|
8
|
+
const parent = this.store.states.treeData[rowKey];
|
|
9
|
+
if (parent && parent.children && parent.hasChildren) {
|
|
10
|
+
const tmp = [];
|
|
11
|
+
const traverse = (children) => {
|
|
12
|
+
if (!children) return;
|
|
13
|
+
children.forEach((key) => {
|
|
14
|
+
tmp.push(this.store.states.lazyTreeNodeMap[key]);
|
|
15
|
+
if (this.store.states.treeData[key]) {
|
|
16
|
+
traverse(this.store.states.treeData[key].children);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
traverse(parent.children);
|
|
21
|
+
prev = prev.concat(tmp);
|
|
22
|
+
}
|
|
23
|
+
return prev;
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<div
|
|
28
|
+
style={[{ height: `${this.table.virtualBodyHeight}px` }]}
|
|
29
|
+
class={["el-table__virtual-wrapper", { "el-table--fixed__virtual-wrapper": this.fixed }]}
|
|
30
|
+
>
|
|
31
|
+
<div style={[{ transform: `translateY(${this.table.innerTop}px)` }]}>
|
|
32
|
+
<table class="el-table__body" cellspacing="0" cellpadding="0" border="0">
|
|
33
|
+
<colgroup>
|
|
34
|
+
{this._l(this.columns, (column, cellIndex) =>
|
|
35
|
+
columnsHidden[cellIndex] && this.fixed ? "" : <col name={column.id} />
|
|
36
|
+
)}
|
|
37
|
+
</colgroup>
|
|
38
|
+
<tbody>
|
|
39
|
+
{this._l(rows, (row, index) => {
|
|
40
|
+
const $index = this.getIndex(index);
|
|
41
|
+
const rowKey = this.table.rowKey ? this.getKeyOfRow(row, $index) : $index;
|
|
42
|
+
const treeNode = this.treeData && this.treeData[rowKey];
|
|
43
|
+
const rowClasses = this.getRowClass(row, $index);
|
|
44
|
+
if (treeNode) {
|
|
45
|
+
rowClasses.push("el-table__row--level-" + treeNode.level);
|
|
46
|
+
}
|
|
47
|
+
const tr = (
|
|
48
|
+
<tr
|
|
49
|
+
v-show={treeNode ? treeNode.display : true}
|
|
50
|
+
style={this.rowStyle ? this.getRowStyle(row, $index) : null}
|
|
51
|
+
key={rowKey}
|
|
52
|
+
on-dblclick={($event) => this.handleDoubleClick($event, row)}
|
|
53
|
+
on-click={($event) => this.handleClick($event, row)}
|
|
54
|
+
on-contextmenu={($event) => this.handleContextMenu($event, row)}
|
|
55
|
+
on-mouseenter={(_) => this.handleMouseEnter(index)}
|
|
56
|
+
on-mouseleave={(_) => this.handleMouseLeave()}
|
|
57
|
+
class={rowClasses}
|
|
58
|
+
>
|
|
59
|
+
{this._l(this.columns, (column, cellIndex) => {
|
|
60
|
+
const { rowspan, colspan } = this.getSpan(row, column, $index, cellIndex);
|
|
61
|
+
if (!rowspan || !colspan || (columnsHidden[cellIndex] && this.fixed)) {
|
|
62
|
+
return "";
|
|
63
|
+
} else {
|
|
64
|
+
const columnData = Object.assign({}, column);
|
|
65
|
+
if (colspan !== 1) {
|
|
66
|
+
columnData.realWidth = columnData.realWidth * colspan;
|
|
67
|
+
}
|
|
68
|
+
const data = {
|
|
69
|
+
store: this.store,
|
|
70
|
+
_self: this.context || this.table.$vnode.context,
|
|
71
|
+
column: columnData,
|
|
72
|
+
row,
|
|
73
|
+
$index,
|
|
74
|
+
};
|
|
75
|
+
if (cellIndex === this.firstDefaultColumnIndex && treeNode) {
|
|
76
|
+
data.treeNode = {
|
|
77
|
+
hasChildren: treeNode.hasChildren || (treeNode.children && treeNode.children.length),
|
|
78
|
+
expanded: treeNode.expanded,
|
|
79
|
+
indent: treeNode.level * this.treeIndent,
|
|
80
|
+
level: treeNode.level,
|
|
81
|
+
loaded: treeNode.loaded,
|
|
82
|
+
rowKey,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return (
|
|
86
|
+
<td
|
|
87
|
+
style={[
|
|
88
|
+
{ height: this.table.rowHeight + "px" },
|
|
89
|
+
this.getCellStyle($index, cellIndex, row, column),
|
|
90
|
+
]}
|
|
91
|
+
class={this.getCellClass($index, cellIndex, row, column)}
|
|
92
|
+
rowspan={rowspan}
|
|
93
|
+
colspan={colspan}
|
|
94
|
+
on-mouseenter={($event) => this.handleCellMouseEnter($event, row)}
|
|
95
|
+
on-mouseleave={this.handleCellMouseLeave}
|
|
96
|
+
>
|
|
97
|
+
{column.renderCell.call(this._renderProxy, h, data, columnsHidden[cellIndex])}
|
|
98
|
+
</td>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
})}
|
|
102
|
+
</tr>
|
|
103
|
+
);
|
|
104
|
+
if (this.hasExpandColumn && this.store.isRowExpanded(row)) {
|
|
105
|
+
return [
|
|
106
|
+
tr,
|
|
107
|
+
<tr>
|
|
108
|
+
<td colspan={this.columns.length} class="el-table__expanded-cell">
|
|
109
|
+
{this.table.renderExpanded
|
|
110
|
+
? this.table.renderExpanded(h, { row, $index, store: this.store })
|
|
111
|
+
: ""}
|
|
112
|
+
</td>
|
|
113
|
+
</tr>,
|
|
114
|
+
];
|
|
115
|
+
} else {
|
|
116
|
+
return tr;
|
|
117
|
+
}
|
|
118
|
+
}).concat(
|
|
119
|
+
<el-tooltip
|
|
120
|
+
effect={this.table.tooltipEffect}
|
|
121
|
+
popperClass="plTableTooltip"
|
|
122
|
+
placement={this.table.tooltipPlacement}
|
|
123
|
+
ref="tooltip"
|
|
124
|
+
content={this.tooltipContent}
|
|
125
|
+
></el-tooltip>
|
|
126
|
+
)}
|
|
127
|
+
</tbody>
|
|
128
|
+
</table>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
}
|