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.
Files changed (142) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +111 -0
  3. package/lib/button.js +1 -0
  4. package/lib/icon.js +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/locale/format.js +56 -0
  7. package/lib/locale/index.js +72 -0
  8. package/lib/locale/lang/en.js +123 -0
  9. package/lib/locale/lang/zh-CN.js +119 -0
  10. package/lib/mixins/locale.js +17 -0
  11. package/lib/theme-chalk/base.css +0 -0
  12. package/lib/theme-chalk/button.css +1 -0
  13. package/lib/theme-chalk/fonts/element-icons.ttf +0 -0
  14. package/lib/theme-chalk/fonts/element-icons.woff +0 -0
  15. package/lib/theme-chalk/fonts/iconfont.1785562768224.ttf +0 -0
  16. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff +0 -0
  17. package/lib/theme-chalk/fonts/iconfont.1785562768224.woff2 +0 -0
  18. package/lib/theme-chalk/icon.css +1 -0
  19. package/lib/theme-chalk/index.css +1 -0
  20. package/lib/theme-chalk/u-table-column.css +0 -0
  21. package/lib/theme-chalk/u-table.css +1 -0
  22. package/lib/theme-chalk/ux-grid.css +1 -0
  23. package/lib/theme-chalk/ux-table-column.css +0 -0
  24. package/lib/u-table-column.js +1 -0
  25. package/lib/u-table.js +1 -0
  26. package/lib/umd/locale/en.js +139 -0
  27. package/lib/umd/locale/zh-CN.js +135 -0
  28. package/lib/umy-ui.common.js +1 -0
  29. package/lib/utils/svg.js +33 -0
  30. package/lib/utils/types.js +35 -0
  31. package/lib/utils/util.js +268 -0
  32. package/lib/ux-grid.js +1 -0
  33. package/lib/ux-table-column.js +1 -0
  34. package/package.json +117 -0
  35. package/packages/button/index.js +7 -0
  36. package/packages/button/src/button-group.vue +10 -0
  37. package/packages/button/src/button.vue +166 -0
  38. package/packages/checkbox/index.js +8 -0
  39. package/packages/checkbox/src/checkbox-button.vue +199 -0
  40. package/packages/checkbox/src/checkbox-group.vue +48 -0
  41. package/packages/checkbox/src/checkbox.vue +222 -0
  42. package/packages/checkbox-button/index.js +8 -0
  43. package/packages/checkbox-group/index.js +8 -0
  44. package/packages/icon/index.js +7 -0
  45. package/packages/icon/src/icon.vue +40 -0
  46. package/packages/input/index.js +2 -0
  47. package/packages/input/src/calcTextareaHeight.js +104 -0
  48. package/packages/input/src/input.vue +424 -0
  49. package/packages/option/index.js +2 -0
  50. package/packages/pagination/index.js +2 -0
  51. package/packages/pagination/src/pager.vue +163 -0
  52. package/packages/pagination/src/pagination.js +386 -0
  53. package/packages/scrollbar/index.js +8 -0
  54. package/packages/scrollbar/src/bar.js +92 -0
  55. package/packages/scrollbar/src/main.js +130 -0
  56. package/packages/scrollbar/src/util.js +34 -0
  57. package/packages/select/index.js +2 -0
  58. package/packages/select/src/navigation-mixin.js +54 -0
  59. package/packages/select/src/option-group.vue +60 -0
  60. package/packages/select/src/option.vue +163 -0
  61. package/packages/select/src/select-dropdown.vue +74 -0
  62. package/packages/select/src/select.vue +889 -0
  63. package/packages/table/index.js +8 -0
  64. package/packages/table/src/config.js +123 -0
  65. package/packages/table/src/dropdown.js +28 -0
  66. package/packages/table/src/filter-panel.vue +194 -0
  67. package/packages/table/src/layout-observer.js +68 -0
  68. package/packages/table/src/store/current.js +71 -0
  69. package/packages/table/src/store/expand.js +65 -0
  70. package/packages/table/src/store/helper.js +37 -0
  71. package/packages/table/src/store/index.js +145 -0
  72. package/packages/table/src/store/tree.js +208 -0
  73. package/packages/table/src/store/watcher.js +448 -0
  74. package/packages/table/src/table-body.js +493 -0
  75. package/packages/table/src/table-column.js +381 -0
  76. package/packages/table/src/table-footer.js +174 -0
  77. package/packages/table/src/table-header.js +537 -0
  78. package/packages/table/src/table-layout.js +231 -0
  79. package/packages/table/src/table.vue +741 -0
  80. package/packages/table/src/util.js +256 -0
  81. package/packages/tag/index.js +8 -0
  82. package/packages/tag/src/tag.vue +58 -0
  83. package/packages/tools/directives/mousewheel.js +18 -0
  84. package/packages/tools/directives/repeat-click.js +24 -0
  85. package/packages/tools/locale/format.js +46 -0
  86. package/packages/tools/locale/index.js +48 -0
  87. package/packages/tools/locale/lang/en.js +120 -0
  88. package/packages/tools/locale/lang/zh-CN.js +116 -0
  89. package/packages/tools/mixins/emitter.js +33 -0
  90. package/packages/tools/mixins/focus.js +9 -0
  91. package/packages/tools/mixins/locale.js +9 -0
  92. package/packages/tools/mixins/migrating.js +54 -0
  93. package/packages/tools/transitions/collapse-transition.js +77 -0
  94. package/packages/tools/utils/after-leave.js +27 -0
  95. package/packages/tools/utils/aria-dialog.js +90 -0
  96. package/packages/tools/utils/aria-utils.js +122 -0
  97. package/packages/tools/utils/clickoutside.js +76 -0
  98. package/packages/tools/utils/date-util.js +292 -0
  99. package/packages/tools/utils/date.js +368 -0
  100. package/packages/tools/utils/dom.js +227 -0
  101. package/packages/tools/utils/menu/aria-menubar.js +14 -0
  102. package/packages/tools/utils/menu/aria-menuitem.js +49 -0
  103. package/packages/tools/utils/menu/aria-submenu.js +59 -0
  104. package/packages/tools/utils/merge.js +15 -0
  105. package/packages/tools/utils/popper.js +1276 -0
  106. package/packages/tools/utils/popup/index.js +218 -0
  107. package/packages/tools/utils/popup/popup-manager.js +194 -0
  108. package/packages/tools/utils/resize-event.js +35 -0
  109. package/packages/tools/utils/scroll-into-view.js +27 -0
  110. package/packages/tools/utils/scrollbar-width.js +29 -0
  111. package/packages/tools/utils/shared.js +7 -0
  112. package/packages/tools/utils/svg.js +1 -0
  113. package/packages/tools/utils/types.js +28 -0
  114. package/packages/tools/utils/util.js +241 -0
  115. package/packages/tools/utils/vdom.js +5 -0
  116. package/packages/tools/utils/vue-popper.js +198 -0
  117. package/packages/tooltip/index.js +8 -0
  118. package/packages/tooltip/src/main.js +241 -0
  119. package/packages/u-table/index.js +4 -0
  120. package/packages/u-table/revise-el-table-mixins/index.js +10 -0
  121. package/packages/u-table/revise-el-table-mixins/table-extend.js +60 -0
  122. package/packages/u-table/revise-el-table-mixins/table.mixins.js +261 -0
  123. package/packages/u-table/revise-el-table-mixins/virtual-table-body-render.js +132 -0
  124. package/packages/u-table/src/u-table.vue +248 -0
  125. package/packages/u-table/u-table-mixins/index.js +483 -0
  126. package/packages/u-table/u-table-tree-mixins/methods.js +120 -0
  127. package/packages/u-table/u-table-tree-mixins/u-table-tree-mixins.js +161 -0
  128. package/packages/u-table-column/index.js +8 -0
  129. package/packages/utils/common.js +27 -0
  130. package/packages/ux-grid/index.js +6 -0
  131. package/packages/ux-grid/mixins/index.js +707 -0
  132. package/packages/ux-grid/src/interceptor.js +6 -0
  133. package/packages/ux-grid/src/ux-grid.vue +301 -0
  134. package/packages/ux-table-column/index.js +10 -0
  135. package/tools/locale/format.js +46 -0
  136. package/tools/locale/index.js +54 -0
  137. package/tools/locale/lang/en.js +120 -0
  138. package/tools/locale/lang/zh-CN.js +116 -0
  139. package/tools/mixins/locale.js +9 -0
  140. package/tools/utils/svg.js +1 -0
  141. package/tools/utils/types.js +28 -0
  142. package/tools/utils/util.js +241 -0
@@ -0,0 +1,741 @@
1
+ <template>
2
+ <div class="el-table"
3
+ :class="[{
4
+ 'fixed-columns-roll-style': fixedColumnsRoll, // 修改源码, 导致固定列部分的横向滚动条不可拖动
5
+ 'el-table--fit': fit,
6
+ 'el-table--striped': stripe,
7
+ 'el-table--border': border || isGroup,
8
+ 'el-table--hidden': isHidden,
9
+ 'el-table--group': isGroup,
10
+ 'el-table--fluid-height': maxHeight,
11
+ 'el-table--scrollable-x': layout.scrollX,
12
+ 'el-table--scrollable-y': layout.scrollY,
13
+ 'el-table--enable-row-hover': !store.states.isComplex,
14
+ 'el-table--enable-row-transition': (store.states.data || []).length !== 0 && (store.states.data || []).length < 100
15
+ }, tableSize ? `el-table--${ tableSize }` : '']"
16
+ @mouseleave="handleMouseLeave($event)">
17
+ <div class="hidden-columns" ref="hiddenColumns"><slot></slot></div>
18
+ <div
19
+ v-if="showHeader"
20
+ v-mousewheel="handleHeaderFooterMousewheel"
21
+ class="el-table__header-wrapper"
22
+ ref="headerWrapper">
23
+ <table-header
24
+ ref="tableHeader"
25
+ :store="store"
26
+ :border="border"
27
+ :default-sort="defaultSort"
28
+ :style="{
29
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
30
+ }">
31
+ </table-header>
32
+ </div>
33
+ <div
34
+ class="el-table__body-wrapper"
35
+ ref="bodyWrapper"
36
+ :class="[layout.scrollX ? `is-scrolling-${scrollPosition}` : 'is-scrolling-none']"
37
+ :style="[bodyHeight]">
38
+ <table-body
39
+ :context="context"
40
+ :store="store"
41
+ :stripe="stripe"
42
+ :row-class-name="rowClassName"
43
+ :row-style="rowStyle"
44
+ :highlight="highlightCurrentRow"
45
+ :style="{
46
+ width: bodyWidth
47
+ }">
48
+ </table-body>
49
+ <div
50
+ v-if="!store.states.data || store.states.data.length === 0"
51
+ class="el-table__empty-block"
52
+ ref="emptyBlock"
53
+ :style="{
54
+ width: bodyWidth
55
+ }">
56
+ <span class="el-table__empty-text">
57
+ <slot name="empty">{{ emptyText || t('el.table.emptyText') }}</slot>
58
+ </span>
59
+ </div>
60
+ <div
61
+ v-if="$slots.append"
62
+ class="el-table__append-wrapper"
63
+ ref="appendWrapper">
64
+ <slot name="append"></slot>
65
+ </div>
66
+ </div>
67
+ <div
68
+ v-if="showSummary"
69
+ v-show="store.states.data && store.states.data.length > 0"
70
+ v-mousewheel="handleHeaderFooterMousewheel"
71
+ class="el-table__footer-wrapper"
72
+ ref="footerWrapper">
73
+ <table-footer
74
+ :store="store"
75
+ :border="border"
76
+ :sum-text="sumText || t('el.table.sumText')"
77
+ :summary-method="summaryMethod"
78
+ :default-sort="defaultSort"
79
+ :style="{
80
+ width: layout.bodyWidth ? layout.bodyWidth + 'px' : ''
81
+ }">
82
+ </table-footer>
83
+ </div>
84
+ <div
85
+ v-if="fixedColumns.length > 0"
86
+ v-mousewheel="handleFixedMousewheel"
87
+ class="el-table__fixed"
88
+ ref="fixedWrapper"
89
+ :style="[{
90
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : ''
91
+ },
92
+ fixedHeight]">
93
+ <div
94
+ v-if="showHeader"
95
+ class="el-table__fixed-header-wrapper"
96
+ ref="fixedHeaderWrapper" >
97
+ <table-header
98
+ ref="fixedTableHeader"
99
+ fixed="left"
100
+ :border="border"
101
+ :store="store"
102
+ :style="{
103
+ width: bodyWidth
104
+ }"></table-header>
105
+ </div>
106
+ <div
107
+ class="el-table__fixed-body-wrapper"
108
+ ref="fixedBodyWrapper"
109
+ :style="[{
110
+ top: layout.headerHeight + 'px'
111
+ },
112
+ fixedBodyHeight]">
113
+ <table-body
114
+ fixed="left"
115
+ :store="store"
116
+ :stripe="stripe"
117
+ :highlight="highlightCurrentRow"
118
+ :row-class-name="rowClassName"
119
+ :row-style="rowStyle"
120
+ :style="{
121
+ width: bodyWidth
122
+ }">
123
+ </table-body>
124
+ <div
125
+ v-if="$slots.append"
126
+ class="el-table__append-gutter"
127
+ :style="{ height: layout.appendHeight + 'px'}"></div>
128
+ </div>
129
+ <div
130
+ v-if="showSummary"
131
+ v-show="store.states.data && store.states.data.length > 0"
132
+ class="el-table__fixed-footer-wrapper"
133
+ ref="fixedFooterWrapper">
134
+ <table-footer
135
+ fixed="left"
136
+ :border="border"
137
+ :sum-text="sumText || t('el.table.sumText')"
138
+ :summary-method="summaryMethod"
139
+ :store="store"
140
+ :style="{
141
+ width: bodyWidth
142
+ }"></table-footer>
143
+ </div>
144
+ </div>
145
+ <div
146
+ v-if="rightFixedColumns.length > 0"
147
+ v-mousewheel="handleFixedMousewheel"
148
+ class="el-table__fixed-right"
149
+ ref="rightFixedWrapper"
150
+ :style="[{
151
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
152
+ right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : ''
153
+ },
154
+ fixedHeight]">
155
+ <div v-if="showHeader"
156
+ class="el-table__fixed-header-wrapper"
157
+ ref="rightFixedHeaderWrapper">
158
+ <table-header
159
+ ref="rightFixedTableHeader"
160
+ fixed="right"
161
+ :border="border"
162
+ :store="store"
163
+ :style="{
164
+ width: bodyWidth
165
+ }"></table-header>
166
+ </div>
167
+ <div
168
+ class="el-table__fixed-body-wrapper"
169
+ ref="rightFixedBodyWrapper"
170
+ :style="[{
171
+ top: layout.headerHeight + 'px'
172
+ },
173
+ fixedBodyHeight]">
174
+ <table-body
175
+ fixed="right"
176
+ :store="store"
177
+ :stripe="stripe"
178
+ :row-class-name="rowClassName"
179
+ :row-style="rowStyle"
180
+ :highlight="highlightCurrentRow"
181
+ :style="{
182
+ width: bodyWidth
183
+ }">
184
+ </table-body>
185
+ <div
186
+ v-if="$slots.append"
187
+ class="el-table__append-gutter"
188
+ :style="{ height: layout.appendHeight + 'px' }"></div>
189
+ </div>
190
+ <div
191
+ v-if="showSummary"
192
+ v-show="store.states.data && store.states.data.length > 0"
193
+ class="el-table__fixed-footer-wrapper"
194
+ ref="rightFixedFooterWrapper">
195
+ <table-footer
196
+ fixed="right"
197
+ :border="border"
198
+ :sum-text="sumText || t('el.table.sumText')"
199
+ :summary-method="summaryMethod"
200
+ :store="store"
201
+ :style="{
202
+ width: bodyWidth
203
+ }"></table-footer>
204
+ </div>
205
+ </div>
206
+ <div
207
+ v-if="rightFixedColumns.length > 0"
208
+ class="el-table__fixed-right-patch"
209
+ ref="rightFixedPatch"
210
+ :style="{
211
+ width: layout.scrollY ? layout.gutterWidth + 'px' : '0',
212
+ height: layout.headerHeight + 'px'
213
+ }"></div>
214
+ <div class="el-table__column-resize-proxy" ref="resizeProxy" v-show="resizeProxyVisible"></div>
215
+ <!--修改源码,解决合计时,固定列不可拖动,加上这个主要是解决修改层级导致阴影消失,为了给固定列加个阴影效果-->
216
+ <div v-if="fixedColumns.length > 0 && fixedColumnsRoll"
217
+ class="el-table__fixed pltableFixedWrapper"
218
+ ref="leftFixed"
219
+ :style="[{
220
+ width: layout.fixedWidth ? layout.fixedWidth + 'px' : '',
221
+ top: layout.headerHeight + 'px'
222
+ },
223
+ fixedColumnsRollHeight]">
224
+ </div>
225
+ <!--修改源码,解决合计时,固定列不可拖动,加上这个主要是解决修改层级导致阴影消失,为了给固定列加个阴影效果-->
226
+ <div v-if="rightFixedColumns.length > 0 && fixedColumnsRoll"
227
+ class="el-table__fixed-right pltableFixedWrapper"
228
+ ref="rightFixed"
229
+ :style="[{
230
+ width: layout.rightFixedWidth ? layout.rightFixedWidth + 'px' : '',
231
+ top: layout.headerHeight + 'px',
232
+ right: layout.scrollY ? (border ? layout.gutterWidth : (layout.gutterWidth || 0)) + 'px' : ''
233
+ },
234
+ fixedColumnsRollHeight]">
235
+ </div>
236
+ </div>
237
+ </template>
238
+
239
+ <script>
240
+ import ElCheckbox from '../../checkbox';
241
+ import { debounce, throttle } from 'throttle-debounce';
242
+ import { addResizeListener, removeResizeListener } from '../../tools/utils/resize-event';
243
+ import Mousewheel from '../../tools/directives/mousewheel';
244
+ import Locale from '../../tools/mixins/locale';
245
+ import Migrating from '../../tools/mixins/migrating';
246
+ import { createStore, mapStates } from './store/helper';
247
+ import TableLayout from './table-layout';
248
+ import TableBody from './table-body';
249
+ import TableHeader from './table-header';
250
+ import TableFooter from './table-footer';
251
+ import { parseHeight } from './util';
252
+
253
+ let tableIdSeed = 1;
254
+
255
+ export default {
256
+ name: 'ElTable',
257
+
258
+ mixins: [Locale, Migrating],
259
+
260
+ directives: {
261
+ Mousewheel
262
+ },
263
+
264
+ props: {
265
+ data: {
266
+ type: Array,
267
+ default: function() {
268
+ return [];
269
+ }
270
+ },
271
+
272
+ size: String,
273
+
274
+ width: [String, Number],
275
+
276
+ height: [String, Number],
277
+
278
+ maxHeight: [String, Number],
279
+
280
+ fit: {
281
+ type: Boolean,
282
+ default: true
283
+ },
284
+
285
+ stripe: Boolean,
286
+
287
+ border: Boolean,
288
+
289
+ rowKey: [String, Function],
290
+
291
+ context: {},
292
+
293
+ showHeader: {
294
+ type: Boolean,
295
+ default: true
296
+ },
297
+
298
+ showSummary: Boolean,
299
+
300
+ sumText: String,
301
+
302
+ summaryMethod: Function,
303
+
304
+ rowClassName: [String, Function],
305
+
306
+ rowStyle: [Object, Function],
307
+
308
+ cellClassName: [String, Function],
309
+
310
+ cellStyle: [Object, Function],
311
+
312
+ headerRowClassName: [String, Function],
313
+
314
+ headerRowStyle: [Object, Function],
315
+
316
+ headerCellClassName: [String, Function],
317
+
318
+ headerCellStyle: [Object, Function],
319
+
320
+ highlightCurrentRow: Boolean,
321
+
322
+ currentRowKey: [String, Number],
323
+
324
+ emptyText: String,
325
+
326
+ expandRowKeys: Array,
327
+
328
+ defaultExpandAll: Boolean,
329
+
330
+ defaultSort: Object,
331
+
332
+ tooltipEffect: String,
333
+
334
+ spanMethod: Function,
335
+
336
+ selectOnIndeterminate: {
337
+ type: Boolean,
338
+ default: true
339
+ },
340
+
341
+ indent: {
342
+ type: Number,
343
+ default: 16
344
+ },
345
+
346
+ treeProps: {
347
+ type: Object,
348
+ default() {
349
+ return {
350
+ hasChildren: 'hasChildren',
351
+ children: 'children'
352
+ };
353
+ }
354
+ },
355
+
356
+ lazy: Boolean,
357
+
358
+ load: Function,
359
+ },
360
+
361
+ components: {
362
+ TableHeader,
363
+ TableFooter,
364
+ TableBody,
365
+ ElCheckbox
366
+ },
367
+
368
+ methods: {
369
+ getMigratingConfig() {
370
+ return {
371
+ events: {
372
+ expand: 'expand is renamed to expand-change'
373
+ }
374
+ };
375
+ },
376
+
377
+ setCurrentRow(row) {
378
+ this.store.commit('setCurrentRow', row);
379
+ },
380
+
381
+ toggleRowSelection(row, selected, recordTableSelect) {
382
+ // 修改源码 需要记录id
383
+ if (recordTableSelect) {
384
+ this.store.toggleRowSelection(row, selected, true);
385
+ } else {
386
+ this.store.toggleRowSelection(row, selected, false);
387
+ }
388
+ this.store.updateAllSelected();
389
+ },
390
+
391
+ // 修改源码,切换选中状态,适用于选中很多,取消很多
392
+ partRowSelections (datas, state) {
393
+ this.store.partRowSelections(datas, state);
394
+ this.store.updateAllSelected();
395
+ },
396
+
397
+ toggleRowExpansion(row, expanded) {
398
+ this.store.toggleRowExpansionAdapter(row, expanded);
399
+ },
400
+
401
+ clearSelection() {
402
+ this.store.clearSelection();
403
+ },
404
+
405
+ clearFilter(columnKeys) {
406
+ this.store.clearFilter(columnKeys);
407
+ },
408
+
409
+ clearSort() {
410
+ this.store.clearSort();
411
+ },
412
+
413
+ handleMouseLeave() {
414
+ this.store.commit('setHoverRow', null);
415
+ if (this.hoverState) this.hoverState = null;
416
+ },
417
+
418
+ updateScrollY() {
419
+ const changed = this.layout.updateScrollY();
420
+ if (changed) {
421
+ this.layout.updateColumnsWidth();
422
+ }
423
+ },
424
+
425
+ handleFixedMousewheel(event, data) {
426
+ const bodyWrapper = this.bodyWrapper;
427
+ if (Math.abs(data.spinY) > 0) {
428
+ const currentScrollTop = bodyWrapper.scrollTop;
429
+ if (data.pixelY < 0 && currentScrollTop !== 0) {
430
+ event.preventDefault();
431
+ }
432
+ if (data.pixelY > 0 && bodyWrapper.scrollHeight - bodyWrapper.clientHeight > currentScrollTop) {
433
+ event.preventDefault();
434
+ }
435
+ bodyWrapper.scrollTop += Math.ceil(data.pixelY / 5);
436
+ } else {
437
+ bodyWrapper.scrollLeft += Math.ceil(data.pixelX / 5);
438
+ }
439
+ },
440
+
441
+ handleHeaderFooterMousewheel(event, data) {
442
+ const { pixelX, pixelY } = data;
443
+ if (Math.abs(pixelX) >= Math.abs(pixelY)) {
444
+ this.bodyWrapper.scrollLeft += data.pixelX / 5;
445
+ }
446
+ },
447
+
448
+ // TODO 使用 CSS transform
449
+ syncPostion: throttle(20, function() {
450
+ const { scrollLeft, scrollTop, offsetWidth, scrollWidth } = this.bodyWrapper;
451
+ const { headerWrapper, footerWrapper, fixedBodyWrapper, rightFixedBodyWrapper } = this.$refs;
452
+ if (headerWrapper) headerWrapper.scrollLeft = scrollLeft;
453
+ if (footerWrapper) footerWrapper.scrollLeft = scrollLeft;
454
+ if (fixedBodyWrapper) fixedBodyWrapper.scrollTop = scrollTop;
455
+ if (rightFixedBodyWrapper) rightFixedBodyWrapper.scrollTop = scrollTop;
456
+ const maxScrollLeftPosition = scrollWidth - offsetWidth - 1;
457
+ if (scrollLeft >= maxScrollLeftPosition) {
458
+ this.scrollPosition = 'right';
459
+ } else if (scrollLeft === 0) {
460
+ this.scrollPosition = 'left';
461
+ } else {
462
+ this.scrollPosition = 'middle';
463
+ }
464
+ }),
465
+
466
+ bindEvents() {
467
+ this.bodyWrapper.addEventListener('scroll', this.syncPostion, { passive: true });
468
+ if (this.fit) {
469
+ addResizeListener(this.$el, this.resizeListener);
470
+ }
471
+ },
472
+
473
+ unbindEvents() {
474
+ this.bodyWrapper.removeEventListener('scroll', this.syncPostion, { passive: true });
475
+ if (this.fit) {
476
+ removeResizeListener(this.$el, this.resizeListener);
477
+ }
478
+ },
479
+
480
+ resizeListener() {
481
+ if (!this.$ready) return;
482
+ let shouldUpdateLayout = false;
483
+ const el = this.$el;
484
+ const { width: oldWidth, height: oldHeight } = this.resizeState;
485
+
486
+ const width = el.offsetWidth;
487
+ if (oldWidth !== width) {
488
+ shouldUpdateLayout = true;
489
+ }
490
+
491
+ const height = el.offsetHeight;
492
+ if ((this.height || this.shouldUpdateHeight) && oldHeight !== height) {
493
+ shouldUpdateLayout = true;
494
+ }
495
+
496
+ if (shouldUpdateLayout) {
497
+ this.resizeState.width = width;
498
+ this.resizeState.height = height;
499
+ this.doLayout();
500
+ }
501
+ },
502
+
503
+ doLayout() {
504
+ if (this.shouldUpdateHeight) {
505
+ this.layout.updateElsHeight();
506
+ }
507
+ this.layout.updateColumnsWidth();
508
+ },
509
+
510
+ sort(prop, order) {
511
+ this.store.commit('sort', { prop, order });
512
+ },
513
+
514
+ toggleAllSelection() {
515
+ this.store.commit('toggleAllSelection');
516
+ }
517
+
518
+ },
519
+
520
+ computed: {
521
+ tableSize() {
522
+ return this.size || (this.$ELEMENT || {}).size;
523
+ },
524
+
525
+ bodyWrapper() {
526
+ return this.$refs.bodyWrapper;
527
+ },
528
+
529
+ shouldUpdateHeight() {
530
+ return this.height ||
531
+ this.maxHeight ||
532
+ this.fixedColumns.length > 0 ||
533
+ this.rightFixedColumns.length > 0;
534
+ },
535
+
536
+ bodyWidth() {
537
+ const { bodyWidth, scrollY, gutterWidth } = this.layout;
538
+ return bodyWidth ? bodyWidth - (scrollY ? gutterWidth : 0) + 'px' : '';
539
+ },
540
+
541
+ bodyHeight() {
542
+ const { headerHeight = 0, bodyHeight, footerHeight = 0} = this.layout;
543
+ if (this.height) {
544
+ return {
545
+ height: bodyHeight ? bodyHeight + 'px' : ''
546
+ };
547
+ } else if (this.maxHeight) {
548
+ const maxHeight = parseHeight(this.maxHeight);
549
+ if (typeof maxHeight === 'number') {
550
+ return {
551
+ 'max-height': (maxHeight - footerHeight - (this.showHeader ? headerHeight : 0)) + 'px'
552
+ };
553
+ }
554
+ }
555
+ return {};
556
+ },
557
+
558
+ // 修改源码解决滚动条问题
559
+ fixedColumnsRollHeight () {
560
+ if (this.height) {
561
+ return {
562
+ height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : ''
563
+ };
564
+ } else if (this.maxHeight){
565
+ setTimeout(() => {
566
+ let data = ['rightFixed', 'leftFixed']
567
+ data.forEach(item => {
568
+ if (this.$refs[item]) {
569
+ const bodyWrapper = this.bodyWrapper;
570
+ this.$refs[item].style.height = bodyWrapper ? bodyWrapper.clientHeight + 'px' : ''
571
+ }
572
+ })
573
+ })
574
+ }
575
+ },
576
+
577
+ fixedBodyHeight() {
578
+ if (this.height) {
579
+ return {
580
+ height: this.layout.fixedBodyHeight ? this.layout.fixedBodyHeight + 'px' : ''
581
+ };
582
+ } else if (this.maxHeight) {
583
+ let maxHeight = parseHeight(this.maxHeight);
584
+ if (typeof maxHeight === 'number') {
585
+ maxHeight = this.layout.scrollX ? maxHeight - this.layout.gutterWidth : maxHeight;
586
+ if (this.showHeader) {
587
+ maxHeight -= this.layout.headerHeight;
588
+ }
589
+ maxHeight -= this.layout.footerHeight;
590
+ return {
591
+ 'max-height': maxHeight + 'px'
592
+ };
593
+ }
594
+ }
595
+ return {};
596
+ },
597
+
598
+ fixedHeight() {
599
+ if (this.maxHeight) {
600
+ if (this.showSummary) {
601
+ return {
602
+ bottom: 0
603
+ };
604
+ }
605
+ return {
606
+ bottom: (this.layout.scrollX && this.data.length) ? this.layout.gutterWidth + 'px' : ''
607
+ };
608
+ } else {
609
+ if (this.showSummary) {
610
+ return {
611
+ height: this.layout.tableHeight ? this.layout.tableHeight + 'px' : ''
612
+ };
613
+ }
614
+ return {
615
+ height: this.layout.viewportHeight ? this.layout.viewportHeight + 'px' : ''
616
+ };
617
+ }
618
+ },
619
+
620
+ ...mapStates({
621
+ selection: 'selection',
622
+ columns: 'columns',
623
+ tableData: 'data',
624
+ fixedColumns: 'fixedColumns',
625
+ rightFixedColumns: 'rightFixedColumns'
626
+ })
627
+ },
628
+
629
+ watch: {
630
+ height: {
631
+ immediate: true,
632
+ handler(value) {
633
+ if (!this.useVirtual) {
634
+ this.layout.setHeight(value);
635
+ }
636
+ }
637
+ },
638
+
639
+ maxHeight: {
640
+ immediate: true,
641
+ handler(value) {
642
+ if (!this.useVirtual) {
643
+ this.layout.setMaxHeight(value);
644
+ }
645
+ }
646
+ },
647
+
648
+ currentRowKey: {
649
+ immediate: true,
650
+ handler(value) {
651
+ if (!this.rowKey) return;
652
+ this.store.setCurrentRowKey(value);
653
+ }
654
+ },
655
+
656
+ data: {
657
+ immediate: true,
658
+ handler(value) {
659
+ if (!this.useVirtual) {
660
+ this.store.commit('setData', value);
661
+ }
662
+ }
663
+ },
664
+
665
+ expandRowKeys: {
666
+ immediate: true,
667
+ handler(newVal) {
668
+ if (newVal) {
669
+ this.store.setExpandRowKeysAdapter(newVal);
670
+ }
671
+ }
672
+ }
673
+ },
674
+
675
+ created() {
676
+ this.tableId = 'el-table_' + tableIdSeed++;
677
+ this.debouncedUpdateLayout = debounce(50, () => this.doLayout());
678
+ },
679
+
680
+ mounted() {
681
+ this.bindEvents();
682
+ this.store.updateColumns();
683
+ this.doLayout();
684
+
685
+ this.resizeState = {
686
+ width: this.$el.offsetWidth,
687
+ height: this.$el.offsetHeight
688
+ };
689
+
690
+ // init filters
691
+ this.store.states.columns.forEach(column => {
692
+ if (column.filteredValue && column.filteredValue.length) {
693
+ this.store.commit('filterChange', {
694
+ column,
695
+ values: column.filteredValue,
696
+ silent: true
697
+ });
698
+ }
699
+ });
700
+
701
+ this.$ready = true;
702
+ },
703
+
704
+ destroyed() {
705
+ this.unbindEvents();
706
+ },
707
+
708
+ data() {
709
+ const { hasChildren = 'hasChildren', children = 'children' } = this.treeProps;
710
+ this.store = createStore(this, {
711
+ rowKey: this.rowKey,
712
+ defaultExpandAll: this.defaultExpandAll,
713
+ selectOnIndeterminate: this.selectOnIndeterminate,
714
+ // TreeTable 的相关配置
715
+ indent: this.indent,
716
+ lazy: this.lazy,
717
+ lazyColumnIdentifier: hasChildren,
718
+ childrenColumnName: children
719
+ });
720
+ const layout = new TableLayout({
721
+ store: this.store,
722
+ table: this,
723
+ fit: this.fit,
724
+ showHeader: this.showHeader
725
+ });
726
+ return {
727
+ layout,
728
+ isHidden: false,
729
+ renderExpanded: null,
730
+ resizeProxyVisible: false,
731
+ resizeState: {
732
+ width: null,
733
+ height: null
734
+ },
735
+ // 是否拥有多级表头
736
+ isGroup: false,
737
+ scrollPosition: 'left'
738
+ };
739
+ }
740
+ };
741
+ </script>