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,493 @@
|
|
|
1
|
+
import { arrayFindIndex } from '../../tools/utils/util';
|
|
2
|
+
import { getCell, getColumnByCell, getRowIdentity } from './util';
|
|
3
|
+
import { getStyle, hasClass, removeClass, addClass } from '../../tools/utils/dom';
|
|
4
|
+
import ElCheckbox from '../../checkbox';
|
|
5
|
+
import ElTooltip from '../../tooltip';
|
|
6
|
+
import debounce from 'throttle-debounce/debounce';
|
|
7
|
+
import LayoutObserver from './layout-observer';
|
|
8
|
+
import { mapStates } from './store/helper';
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
name: 'ElTableBody',
|
|
12
|
+
|
|
13
|
+
mixins: [LayoutObserver],
|
|
14
|
+
|
|
15
|
+
components: {
|
|
16
|
+
ElCheckbox,
|
|
17
|
+
ElTooltip
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
props: {
|
|
21
|
+
store: {
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
stripe: Boolean,
|
|
25
|
+
context: {},
|
|
26
|
+
rowClassName: [String, Function],
|
|
27
|
+
rowStyle: [Object, Function],
|
|
28
|
+
fixed: String,
|
|
29
|
+
highlight: Boolean
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
render(h) {
|
|
33
|
+
const data = this.data || [];
|
|
34
|
+
return (
|
|
35
|
+
<table
|
|
36
|
+
class="el-table__body"
|
|
37
|
+
cellspacing="0"
|
|
38
|
+
cellpadding="0"
|
|
39
|
+
border="0">
|
|
40
|
+
<colgroup>
|
|
41
|
+
{
|
|
42
|
+
this.columns.map(column => <col name={ column.id } key={column.id} />)
|
|
43
|
+
}
|
|
44
|
+
</colgroup>
|
|
45
|
+
<tbody>
|
|
46
|
+
{
|
|
47
|
+
data.reduce((acc, row) => {
|
|
48
|
+
return acc.concat(this.wrappedRowRender(row, acc.length));
|
|
49
|
+
}, [])
|
|
50
|
+
}
|
|
51
|
+
<el-tooltip effect={ this.table.tooltipEffect } popperClass="plTableTooltip" placement={ this.table.tooltipPlacement } ref="tooltip" content={ this.tooltipContent }></el-tooltip>
|
|
52
|
+
</tbody>
|
|
53
|
+
</table>
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
computed: {
|
|
58
|
+
table() {
|
|
59
|
+
return this.$parent;
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
...mapStates({
|
|
63
|
+
data: 'data',
|
|
64
|
+
columns: 'columns',
|
|
65
|
+
treeIndent: 'indent',
|
|
66
|
+
leftFixedLeafCount: 'fixedLeafColumnsLength',
|
|
67
|
+
rightFixedLeafCount: 'rightFixedLeafColumnsLength',
|
|
68
|
+
columnsCount: states => states.columns.length,
|
|
69
|
+
leftFixedCount: states => states.fixedColumns.length,
|
|
70
|
+
rightFixedCount: states => states.rightFixedColumns.length,
|
|
71
|
+
hasExpandColumn: states => states.columns.some(({ type }) => type === 'expand')
|
|
72
|
+
}),
|
|
73
|
+
|
|
74
|
+
firstDefaultColumnIndex() {
|
|
75
|
+
return arrayFindIndex(this.columns, ({ type }) => type === 'default');
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
watch: {
|
|
80
|
+
// don't trigger getter of currentRow in getCellClass. see https://jsfiddle.net/oe2b4hqt/
|
|
81
|
+
// update DOM manually. see https://github.com/ElemeFE/element/pull/13954/files#diff-9b450c00d0a9dec0ffad5a3176972e40
|
|
82
|
+
'store.states.hoverRow'(newVal, oldVal) {
|
|
83
|
+
if (!this.store.states.isComplex || this.$isServer) return;
|
|
84
|
+
let raf = window.requestAnimationFrame;
|
|
85
|
+
if (!raf) {
|
|
86
|
+
raf = (fn) => setTimeout(fn, 16);
|
|
87
|
+
}
|
|
88
|
+
raf(() => {
|
|
89
|
+
const rows = this.$el.querySelectorAll('.el-table__row');
|
|
90
|
+
const oldRow = rows[oldVal];
|
|
91
|
+
const newRow = rows[newVal];
|
|
92
|
+
if (oldRow) {
|
|
93
|
+
removeClass(oldRow, 'hover-row');
|
|
94
|
+
}
|
|
95
|
+
if (newRow) {
|
|
96
|
+
addClass(newRow, 'hover-row');
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
|
|
102
|
+
data() {
|
|
103
|
+
return {
|
|
104
|
+
tooltipContent: ''
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
created() {
|
|
109
|
+
this.activateTooltip = debounce(50, tooltip => tooltip.handleShowPopper());
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
methods: {
|
|
113
|
+
getKeyOfRow(row, index) {
|
|
114
|
+
const rowKey = this.table.rowKey;
|
|
115
|
+
if (rowKey) {
|
|
116
|
+
return getRowIdentity(row, rowKey);
|
|
117
|
+
}
|
|
118
|
+
return index;
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
isColumnHidden(index) {
|
|
122
|
+
if (this.fixed === true || this.fixed === 'left') {
|
|
123
|
+
return index >= this.leftFixedLeafCount;
|
|
124
|
+
} else if (this.fixed === 'right') {
|
|
125
|
+
return index < this.columnsCount - this.rightFixedLeafCount;
|
|
126
|
+
} else {
|
|
127
|
+
return (index < this.leftFixedLeafCount) || (index >= this.columnsCount - this.rightFixedLeafCount);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
getSpan(row, column, rowIndex, columnIndex) {
|
|
132
|
+
let rowspan = 1;
|
|
133
|
+
let colspan = 1;
|
|
134
|
+
const fn = this.table.spanMethod;
|
|
135
|
+
if (typeof fn === 'function') {
|
|
136
|
+
const result = fn({
|
|
137
|
+
row,
|
|
138
|
+
column,
|
|
139
|
+
rowIndex,
|
|
140
|
+
columnIndex
|
|
141
|
+
});
|
|
142
|
+
if (Array.isArray(result)) {
|
|
143
|
+
rowspan = result[0];
|
|
144
|
+
colspan = result[1];
|
|
145
|
+
} else if (typeof result === 'object') {
|
|
146
|
+
rowspan = result.rowspan;
|
|
147
|
+
colspan = result.colspan;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return { rowspan, colspan };
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
getRowStyle(row, rowIndex) {
|
|
154
|
+
const rowStyle = this.table.rowStyle;
|
|
155
|
+
if (typeof rowStyle === 'function') {
|
|
156
|
+
return rowStyle.call(null, {
|
|
157
|
+
row,
|
|
158
|
+
rowIndex
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return rowStyle || null;
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
getRowClass(row, rowIndex) {
|
|
165
|
+
const classes = ['el-table__row'];
|
|
166
|
+
// 修改源码,如果当前行被选中了 type类型为selection,就给当前行给个类样式,此样式类外面传递
|
|
167
|
+
const { selection = [] } = this.store.states;
|
|
168
|
+
if (selection.indexOf(row) > -1 && this.table.selectTrClass) {
|
|
169
|
+
classes.push(this.table.selectTrClass)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (this.table.highlightCurrentRow && row === this.store.states.currentRow) {
|
|
173
|
+
classes.push('current-row');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (this.stripe && rowIndex % 2 === 1) {
|
|
177
|
+
classes.push('el-table__row--striped');
|
|
178
|
+
}
|
|
179
|
+
const rowClassName = this.table.rowClassName;
|
|
180
|
+
if (typeof rowClassName === 'string') {
|
|
181
|
+
classes.push(rowClassName);
|
|
182
|
+
} else if (typeof rowClassName === 'function') {
|
|
183
|
+
classes.push(rowClassName.call(null, {
|
|
184
|
+
row,
|
|
185
|
+
rowIndex
|
|
186
|
+
}));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (this.store.states.expandRows.indexOf(row) > -1) {
|
|
190
|
+
classes.push('expanded');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return classes;
|
|
194
|
+
},
|
|
195
|
+
|
|
196
|
+
getCellStyle(rowIndex, columnIndex, row, column) {
|
|
197
|
+
const cellStyle = this.table.cellStyle;
|
|
198
|
+
if (typeof cellStyle === 'function') {
|
|
199
|
+
return cellStyle.call(null, {
|
|
200
|
+
rowIndex,
|
|
201
|
+
columnIndex,
|
|
202
|
+
row,
|
|
203
|
+
column
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return cellStyle;
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
getCellClass(rowIndex, columnIndex, row, column) {
|
|
210
|
+
const classes = [column.id, column.align, column.className];
|
|
211
|
+
|
|
212
|
+
if (this.isColumnHidden(columnIndex)) {
|
|
213
|
+
classes.push('is-hidden');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const cellClassName = this.table.cellClassName;
|
|
217
|
+
if (typeof cellClassName === 'string') {
|
|
218
|
+
classes.push(cellClassName);
|
|
219
|
+
} else if (typeof cellClassName === 'function') {
|
|
220
|
+
classes.push(cellClassName.call(null, {
|
|
221
|
+
rowIndex,
|
|
222
|
+
columnIndex,
|
|
223
|
+
row,
|
|
224
|
+
column
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return classes.join(' ');
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
getColspanRealWidth(columns, colspan, index) {
|
|
232
|
+
if (colspan < 1) {
|
|
233
|
+
return columns[index].realWidth;
|
|
234
|
+
}
|
|
235
|
+
const widthArr = columns.map(({ realWidth }) => realWidth).slice(index, index + colspan);
|
|
236
|
+
return widthArr.reduce((acc, width) => acc + width, -1);
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
handleCellMouseEnter(event, row) {
|
|
240
|
+
const table = this.table;
|
|
241
|
+
const cell = getCell(event);
|
|
242
|
+
|
|
243
|
+
if (cell) {
|
|
244
|
+
const column = getColumnByCell(table, cell);
|
|
245
|
+
const hoverState = table.hoverState = {cell, column, row};
|
|
246
|
+
table.$emit('cell-mouse-enter', hoverState.row, hoverState.column, hoverState.cell, event);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// 判断是否text-overflow, 如果是就显示tooltip
|
|
250
|
+
const cellChild = event.target.querySelector('.cell');
|
|
251
|
+
if (!(hasClass(cellChild, 'el-tooltip') && cellChild.childNodes.length)) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
// use range width instead of scrollWidth to determine whether the text is overflowing
|
|
255
|
+
// to address a potential FireFox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1074543#c3
|
|
256
|
+
const range = document.createRange();
|
|
257
|
+
range.setStart(cellChild, 0);
|
|
258
|
+
range.setEnd(cellChild, cellChild.childNodes.length);
|
|
259
|
+
const rangeWidth = range.getBoundingClientRect().width;
|
|
260
|
+
const padding = (parseInt(getStyle(cellChild, 'paddingLeft'), 10) || 0) +
|
|
261
|
+
(parseInt(getStyle(cellChild, 'paddingRight'), 10) || 0);
|
|
262
|
+
if ((rangeWidth + padding > cellChild.offsetWidth || cellChild.scrollWidth > cellChild.offsetWidth) && this.$refs.tooltip) {
|
|
263
|
+
const tooltip = this.$refs.tooltip;
|
|
264
|
+
// TODO 会引起整个 Table 的重新渲染,需要优化
|
|
265
|
+
this.tooltipContent = cell.innerText || cell.textContent;
|
|
266
|
+
tooltip.referenceElm = cell;
|
|
267
|
+
tooltip.$refs.popper && (tooltip.$refs.popper.style.display = 'none');
|
|
268
|
+
tooltip.doDestroy();
|
|
269
|
+
tooltip.setExpectedState(true);
|
|
270
|
+
this.activateTooltip(tooltip);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
handleCellMouseLeave(event) {
|
|
275
|
+
const tooltip = this.$refs.tooltip;
|
|
276
|
+
if (tooltip) {
|
|
277
|
+
tooltip.setExpectedState(false);
|
|
278
|
+
tooltip.handleClosePopper();
|
|
279
|
+
}
|
|
280
|
+
const cell = getCell(event);
|
|
281
|
+
if (!cell) return;
|
|
282
|
+
|
|
283
|
+
const oldHoverState = this.table.hoverState || {};
|
|
284
|
+
this.table.$emit('cell-mouse-leave', oldHoverState.row, oldHoverState.column, oldHoverState.cell, event);
|
|
285
|
+
},
|
|
286
|
+
|
|
287
|
+
handleMouseEnter: debounce(30, function(index) {
|
|
288
|
+
this.store.commit('setHoverRow', index);
|
|
289
|
+
}),
|
|
290
|
+
|
|
291
|
+
handleMouseLeave: debounce(30, function() {
|
|
292
|
+
this.store.commit('setHoverRow', null);
|
|
293
|
+
}),
|
|
294
|
+
|
|
295
|
+
handleContextMenu(event, row) {
|
|
296
|
+
this.handleEvent(event, row, 'contextmenu');
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
handleDoubleClick(event, row) {
|
|
300
|
+
this.handleEvent(event, row, 'dblclick');
|
|
301
|
+
},
|
|
302
|
+
|
|
303
|
+
handleClick(event, row) {
|
|
304
|
+
this.store.commit('setCurrentRow', row);
|
|
305
|
+
this.handleEvent(event, row, 'click');
|
|
306
|
+
},
|
|
307
|
+
|
|
308
|
+
handleEvent(event, row, name) {
|
|
309
|
+
const table = this.table;
|
|
310
|
+
const cell = getCell(event);
|
|
311
|
+
let column;
|
|
312
|
+
if (cell) {
|
|
313
|
+
column = getColumnByCell(table, cell);
|
|
314
|
+
if (column) {
|
|
315
|
+
table.$emit(`cell-${name}`, row, column, cell, event);
|
|
316
|
+
}
|
|
317
|
+
// 修改源码,点击单元格,去调用下树形节点展开方法,trigger是外面传递解决
|
|
318
|
+
if (table.treeOpts.trigger === 'cell' && column.treeNode) {
|
|
319
|
+
table.triggerTreeExpandEvent(row, 'cell', event)
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
// 修改源码,点击单元格,去调用下树形节点展开方法,trigger是外面传递解决
|
|
323
|
+
if (table.treeOpts.trigger === 'row') {
|
|
324
|
+
table.triggerTreeExpandEvent(row, 'row', event)
|
|
325
|
+
}
|
|
326
|
+
table.$emit(`row-${name}`, row, column, event);
|
|
327
|
+
},
|
|
328
|
+
|
|
329
|
+
rowRender(row, $index, treeRowData) {
|
|
330
|
+
const { treeIndent, columns, firstDefaultColumnIndex } = this;
|
|
331
|
+
const columnsHidden = columns.map((column, index) => this.isColumnHidden(index));
|
|
332
|
+
const rowClasses = this.getRowClass(row, $index);
|
|
333
|
+
let display = true;
|
|
334
|
+
if (treeRowData) {
|
|
335
|
+
rowClasses.push('el-table__row--level-' + treeRowData.level);
|
|
336
|
+
display = treeRowData.display;
|
|
337
|
+
}
|
|
338
|
+
return (<tr
|
|
339
|
+
v-show={display}
|
|
340
|
+
style={ this.getRowStyle(row, $index) }
|
|
341
|
+
class={ rowClasses }
|
|
342
|
+
key={ this.getKeyOfRow(row, $index) }
|
|
343
|
+
on-dblclick={ ($event) => this.handleDoubleClick($event, row) }
|
|
344
|
+
on-click={ ($event) => this.handleClick($event, row) }
|
|
345
|
+
on-contextmenu={ ($event) => this.handleContextMenu($event, row) }
|
|
346
|
+
on-mouseenter={ _ => this.handleMouseEnter($index) }
|
|
347
|
+
on-mouseleave={ this.handleMouseLeave }>
|
|
348
|
+
{
|
|
349
|
+
columns.map((column, cellIndex) => {
|
|
350
|
+
const { rowspan, colspan } = this.getSpan(row, column, $index, cellIndex);
|
|
351
|
+
if (!rowspan || !colspan) {
|
|
352
|
+
return null;
|
|
353
|
+
}
|
|
354
|
+
const columnData = { ...column };
|
|
355
|
+
columnData.realWidth = this.getColspanRealWidth(columns, colspan, cellIndex);
|
|
356
|
+
const data = {
|
|
357
|
+
store: this.store,
|
|
358
|
+
_self: this.context || this.table.$vnode.context,
|
|
359
|
+
column: columnData,
|
|
360
|
+
row,
|
|
361
|
+
$index
|
|
362
|
+
};
|
|
363
|
+
if (cellIndex === firstDefaultColumnIndex && treeRowData) {
|
|
364
|
+
data.treeNode = {
|
|
365
|
+
indent: treeRowData.level * treeIndent,
|
|
366
|
+
level: treeRowData.level
|
|
367
|
+
};
|
|
368
|
+
if (typeof treeRowData.expanded === 'boolean') {
|
|
369
|
+
data.treeNode.expanded = treeRowData.expanded;
|
|
370
|
+
// 表明是懒加载
|
|
371
|
+
if ('loading' in treeRowData) {
|
|
372
|
+
data.treeNode.loading = treeRowData.loading;
|
|
373
|
+
}
|
|
374
|
+
if ('noLazyChildren' in treeRowData) {
|
|
375
|
+
data.treeNode.noLazyChildren = treeRowData.noLazyChildren;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return (
|
|
380
|
+
<td
|
|
381
|
+
style={ this.getCellStyle($index, cellIndex, row, column) }
|
|
382
|
+
class={ this.getCellClass($index, cellIndex, row, column) }
|
|
383
|
+
rowspan={ rowspan }
|
|
384
|
+
colspan={ colspan }
|
|
385
|
+
on-mouseenter={ ($event) => this.handleCellMouseEnter($event, row) }
|
|
386
|
+
on-mouseleave={ this.handleCellMouseLeave }>
|
|
387
|
+
{
|
|
388
|
+
column.renderCell.call(
|
|
389
|
+
this._renderProxy,
|
|
390
|
+
this.$createElement,
|
|
391
|
+
data,
|
|
392
|
+
columnsHidden[cellIndex]
|
|
393
|
+
)
|
|
394
|
+
}
|
|
395
|
+
</td>
|
|
396
|
+
);
|
|
397
|
+
})
|
|
398
|
+
}
|
|
399
|
+
</tr>);
|
|
400
|
+
},
|
|
401
|
+
|
|
402
|
+
wrappedRowRender(row, $index) {
|
|
403
|
+
const store = this.store;
|
|
404
|
+
const { isRowExpanded, assertRowKey } = store;
|
|
405
|
+
const { treeData, lazyTreeNodeMap, childrenColumnName, rowKey } = store.states;
|
|
406
|
+
if (this.hasExpandColumn && isRowExpanded(row)) {
|
|
407
|
+
const renderExpanded = this.table.renderExpanded;
|
|
408
|
+
const tr = this.rowRender(row, $index);
|
|
409
|
+
if (!renderExpanded) {
|
|
410
|
+
console.error('[Element Error]renderExpanded is required.');
|
|
411
|
+
return tr;
|
|
412
|
+
}
|
|
413
|
+
// 使用二维数组,避免修改 $index
|
|
414
|
+
return [[
|
|
415
|
+
tr,
|
|
416
|
+
<tr key={'expanded-row__' + tr.key}>
|
|
417
|
+
<td colspan={ this.columnsCount } class="el-table__expanded-cell">
|
|
418
|
+
{ renderExpanded(this.$createElement, { row, $index, store: this.store }) }
|
|
419
|
+
</td>
|
|
420
|
+
</tr>]];
|
|
421
|
+
} else if (Object.keys(treeData).length) {
|
|
422
|
+
assertRowKey();
|
|
423
|
+
// TreeTable 时,rowKey 必须由用户设定,不使用 getKeyOfRow 计算
|
|
424
|
+
// 在调用 rowRender 函数时,仍然会计算 rowKey,不太好的操作
|
|
425
|
+
const key = getRowIdentity(row, rowKey);
|
|
426
|
+
let cur = treeData[key];
|
|
427
|
+
let treeRowData = null;
|
|
428
|
+
if (cur) {
|
|
429
|
+
treeRowData = {
|
|
430
|
+
expanded: cur.expanded,
|
|
431
|
+
level: cur.level,
|
|
432
|
+
display: true
|
|
433
|
+
};
|
|
434
|
+
if (typeof cur.lazy === 'boolean') {
|
|
435
|
+
if (typeof cur.loaded === 'boolean' && cur.loaded) {
|
|
436
|
+
treeRowData.noLazyChildren = !(cur.children && cur.children.length);
|
|
437
|
+
}
|
|
438
|
+
treeRowData.loading = cur.loading;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const tmp = [this.rowRender(row, $index, treeRowData)];
|
|
442
|
+
// 渲染嵌套数据
|
|
443
|
+
if (cur) {
|
|
444
|
+
// currentRow 记录的是 index,所以还需主动增加 TreeTable 的 index
|
|
445
|
+
let i = 0;
|
|
446
|
+
const traverse = (children, parent) => {
|
|
447
|
+
if (!(children && children.length && parent)) return;
|
|
448
|
+
children.forEach(node => {
|
|
449
|
+
// 父节点的 display 状态影响子节点的显示状态
|
|
450
|
+
const innerTreeRowData = {
|
|
451
|
+
display: parent.display && parent.expanded,
|
|
452
|
+
level: parent.level + 1
|
|
453
|
+
};
|
|
454
|
+
const childKey = getRowIdentity(node, rowKey);
|
|
455
|
+
if (childKey === undefined || childKey === null) {
|
|
456
|
+
throw new Error('for nested data item, row-key is required.');
|
|
457
|
+
}
|
|
458
|
+
cur = { ...treeData[childKey] };
|
|
459
|
+
// 对于当前节点,分成有无子节点两种情况。
|
|
460
|
+
// 如果包含子节点的,设置 expanded 属性。
|
|
461
|
+
// 对于它子节点的 display 属性由它本身的 expanded 与 display 共同决定。
|
|
462
|
+
if (cur) {
|
|
463
|
+
innerTreeRowData.expanded = cur.expanded;
|
|
464
|
+
// 懒加载的某些节点,level 未知
|
|
465
|
+
cur.level = cur.level || innerTreeRowData.level;
|
|
466
|
+
cur.display = !!(cur.expanded && innerTreeRowData.display);
|
|
467
|
+
if (typeof cur.lazy === 'boolean') {
|
|
468
|
+
if (typeof cur.loaded === 'boolean' && cur.loaded) {
|
|
469
|
+
innerTreeRowData.noLazyChildren = !(cur.children && cur.children.length);
|
|
470
|
+
}
|
|
471
|
+
innerTreeRowData.loading = cur.loading;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
i++;
|
|
475
|
+
tmp.push(this.rowRender(node, $index + i, innerTreeRowData));
|
|
476
|
+
if (cur) {
|
|
477
|
+
const nodes = lazyTreeNodeMap[childKey] || node[childrenColumnName];
|
|
478
|
+
traverse(nodes, cur);
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
};
|
|
482
|
+
// 对于 root 节点,display 一定为 true
|
|
483
|
+
cur.display = true;
|
|
484
|
+
const nodes = lazyTreeNodeMap[key] || row[childrenColumnName];
|
|
485
|
+
traverse(nodes, cur);
|
|
486
|
+
}
|
|
487
|
+
return tmp;
|
|
488
|
+
} else {
|
|
489
|
+
return this.rowRender(row, $index);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
};
|