1 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
2 | import _typeof from 'babel-runtime/helpers/typeof';
|
3 | import _extends from 'babel-runtime/helpers/extends';
|
4 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
5 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
6 | import _inherits from 'babel-runtime/helpers/inherits';
|
7 | import React, { Children } from 'react';
|
8 | import { findDOMNode } from 'react-dom';
|
9 | import PropTypes from 'prop-types';
|
10 | import classnames from 'classnames';
|
11 | import shallowElementEquals from 'shallow-element-equals';
|
12 | import { dom, log, obj, events, env } from '../util';
|
13 | import LockRow from './lock/row';
|
14 | import LockBody from './lock/body';
|
15 | import LockHeader from './lock/header';
|
16 | import LockWrapper from './fixed/wrapper';
|
17 | import { statics } from './util';
|
18 |
|
19 | var ieVersion = env.ieVersion;
|
20 |
|
21 | export default function lock(BaseComponent) {
|
22 | var _class, _temp;
|
23 |
|
24 |
|
25 | var LockTable = (_temp = _class = function (_React$Component) {
|
26 | _inherits(LockTable, _React$Component);
|
27 |
|
28 | function LockTable(props, context) {
|
29 | _classCallCheck(this, LockTable);
|
30 |
|
31 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context));
|
32 |
|
33 | _this.state = {};
|
34 |
|
35 | _this.getTableInstance = function (type, instance) {
|
36 | type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
|
37 | _this['table' + type + 'Inc'] = instance;
|
38 | };
|
39 |
|
40 | _this.getNode = function (type, node, lockType) {
|
41 | lockType = lockType ? lockType.charAt(0).toUpperCase() + lockType.substr(1) : '';
|
42 | _this['' + type + lockType + 'Node'] = node;
|
43 | if (type === 'header' && !_this.innerHeaderNode && !lockType) {
|
44 | _this.innerHeaderNode = _this.headerNode.querySelector('div');
|
45 | }
|
46 | };
|
47 |
|
48 | _this.onRowMouseEnter = function (record, index) {
|
49 | if (_this.isLock()) {
|
50 | var row = _this.getRowNode(index);
|
51 | var leftRow = _this.getRowNode(index, 'left');
|
52 | var rightRow = _this.getRowNode(index, 'right');
|
53 | [row, leftRow, rightRow].forEach(function (row) {
|
54 | row && dom.addClass(row, 'hovered');
|
55 | });
|
56 | }
|
57 | };
|
58 |
|
59 | _this.onRowMouseLeave = function (record, index) {
|
60 | if (_this.isLock()) {
|
61 | var row = _this.getRowNode(index);
|
62 | var leftRow = _this.getRowNode(index, 'left');
|
63 | var rightRow = _this.getRowNode(index, 'right');
|
64 | [row, leftRow, rightRow].forEach(function (row) {
|
65 | row && dom.removeClass(row, 'hovered');
|
66 | });
|
67 | }
|
68 | };
|
69 |
|
70 | _this.onLockBodyScrollTop = function (event) {
|
71 |
|
72 | var target = event.target;
|
73 | if (event.currentTarget !== target) {
|
74 | return;
|
75 | }
|
76 | var distScrollTop = target.scrollTop;
|
77 |
|
78 | if (_this.isLock() && distScrollTop !== _this.lastScrollTop) {
|
79 | var lockRightBody = _this.bodyRightNode,
|
80 | lockLeftBody = _this.bodyLeftNode,
|
81 | bodyNode = _this.bodyNode;
|
82 |
|
83 | var arr = [lockLeftBody, lockRightBody, bodyNode];
|
84 |
|
85 | arr.forEach(function (node) {
|
86 | if (node && node.scrollTop !== distScrollTop) {
|
87 | node.scrollTop = distScrollTop;
|
88 | }
|
89 | });
|
90 |
|
91 | _this.lastScrollTop = distScrollTop;
|
92 | }
|
93 | };
|
94 |
|
95 | _this.onLockBodyScrollLeft = function () {
|
96 |
|
97 | if (_this.isLock()) {
|
98 | var rtl = _this.props.rtl;
|
99 |
|
100 | var lockRightTable = rtl ? _this.getWrapperNode('left') : _this.getWrapperNode('right'),
|
101 | lockLeftTable = rtl ? _this.getWrapperNode('right') : _this.getWrapperNode('left'),
|
102 | shadowClassName = 'shadow';
|
103 |
|
104 | var x = _this.bodyNode.scrollLeft;
|
105 |
|
106 | if (x === 0) {
|
107 | lockLeftTable && dom.removeClass(lockLeftTable, shadowClassName);
|
108 | lockRightTable && dom.addClass(lockRightTable, shadowClassName);
|
109 | } else if (x === _this.bodyNode.scrollWidth - _this.bodyNode.clientWidth) {
|
110 | lockLeftTable && dom.addClass(lockLeftTable, shadowClassName);
|
111 | lockRightTable && dom.removeClass(lockRightTable, shadowClassName);
|
112 | } else {
|
113 | lockLeftTable && dom.addClass(lockLeftTable, shadowClassName);
|
114 | lockRightTable && dom.addClass(lockRightTable, shadowClassName);
|
115 | }
|
116 | }
|
117 | };
|
118 |
|
119 | _this.onLockBodyScroll = function (event) {
|
120 | _this.onLockBodyScrollTop(event);
|
121 | _this.onLockBodyScrollLeft();
|
122 | };
|
123 |
|
124 | _this.adjustSize = function () {
|
125 | if (!_this.adjustIfTableNotNeedLock()) {
|
126 | _this.adjustHeaderSize();
|
127 | _this.adjustBodySize();
|
128 | _this.adjustRowHeight();
|
129 | _this.onLockBodyScrollLeft();
|
130 | }
|
131 | };
|
132 |
|
133 | _this.getFlatenChildrenLength = function () {
|
134 | var children = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
135 |
|
136 | var loop = function loop(arr) {
|
137 | var newArray = [];
|
138 | arr.forEach(function (child) {
|
139 | if (child && child.children) {
|
140 | newArray.push.apply(newArray, loop(child.children));
|
141 | } else {
|
142 | newArray.push(child);
|
143 | }
|
144 | });
|
145 | return newArray;
|
146 | };
|
147 |
|
148 | return loop(children).length;
|
149 | };
|
150 |
|
151 | _this.saveLockLeftRef = function (ref) {
|
152 | _this.lockLeftEl = ref;
|
153 | };
|
154 |
|
155 | _this.saveLockRightRef = function (ref) {
|
156 | _this.lockRightEl = ref;
|
157 | };
|
158 |
|
159 | _this.lockLeftChildren = [];
|
160 | _this.lockRightChildren = [];
|
161 | return _this;
|
162 | }
|
163 |
|
164 | LockTable.prototype.getChildContext = function getChildContext() {
|
165 | return {
|
166 | getTableInstance: this.getTableInstance,
|
167 | getLockNode: this.getNode,
|
168 | onLockBodyScroll: this.onLockBodyScroll,
|
169 | onRowMouseEnter: this.onRowMouseEnter,
|
170 | onRowMouseLeave: this.onRowMouseLeave
|
171 | };
|
172 | };
|
173 |
|
174 | LockTable.prototype.componentDidMount = function componentDidMount() {
|
175 | events.on(window, 'resize', this.adjustSize);
|
176 |
|
177 | this.scroll();
|
178 | this.adjustSize();
|
179 | this.forceUpdate();
|
180 | };
|
181 |
|
182 | LockTable.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState, nextContext) {
|
183 | if (nextProps.pure) {
|
184 | var isEqual = shallowElementEquals(nextProps, this.props);
|
185 | return !(isEqual && obj.shallowEqual(nextContext, this.context));
|
186 | }
|
187 |
|
188 | return true;
|
189 | };
|
190 |
|
191 | LockTable.prototype.componentDidUpdate = function componentDidUpdate() {
|
192 | this.adjustSize();
|
193 | this._isLock = false;
|
194 | };
|
195 |
|
196 | LockTable.prototype.componentWillUnmount = function componentWillUnmount() {
|
197 | events.off(window, 'resize', this.adjustSize);
|
198 | };
|
199 |
|
200 | LockTable.prototype.normalizeChildrenState = function normalizeChildrenState(props) {
|
201 | var columns = this.normalizeChildren(props);
|
202 | var splitChildren = this.splitFromNormalizeChildren(columns);
|
203 | var lockLeftChildren = splitChildren.lockLeftChildren,
|
204 | lockRightChildren = splitChildren.lockRightChildren;
|
205 |
|
206 | return {
|
207 | lockLeftChildren: lockLeftChildren,
|
208 | lockRightChildren: lockRightChildren,
|
209 | children: this.mergeFromSplitLockChildren(splitChildren)
|
210 | };
|
211 | };
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | LockTable.prototype.normalizeChildren = function normalizeChildren(props) {
|
217 | var children = props.children,
|
218 | columns = props.columns;
|
219 |
|
220 | var isLock = false,
|
221 | ret = void 0;
|
222 | var checkLock = function checkLock(col) {
|
223 | if ([true, 'left', 'right'].indexOf(col.lock) > -1) {
|
224 | if (!('width' in col)) {
|
225 | log.warning('Should config width for lock column named [ ' + col.dataIndex + ' ].');
|
226 | }
|
227 | isLock = true;
|
228 | }
|
229 | };
|
230 | if (columns && !children) {
|
231 | ret = columns;
|
232 |
|
233 | var getColumns = function getColumns(cols) {
|
234 | cols.forEach(function () {
|
235 | var col = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
236 |
|
237 | checkLock(col);
|
238 |
|
239 | if (col.children) {
|
240 | getColumns(col.children);
|
241 | }
|
242 | });
|
243 | };
|
244 |
|
245 | getColumns(columns);
|
246 | } else {
|
247 | var getChildren = function getChildren(children) {
|
248 | var ret = [];
|
249 | Children.forEach(children, function (child) {
|
250 | if (child) {
|
251 | var _props = _extends({}, child.props);
|
252 | checkLock(_props);
|
253 | ret.push(_props);
|
254 | if (child.props.children) {
|
255 | _props.children = getChildren(child.props.children);
|
256 | }
|
257 | }
|
258 | });
|
259 | return ret;
|
260 | };
|
261 |
|
262 | ret = getChildren(children);
|
263 | }
|
264 |
|
265 | ret.forEach(function (child) {
|
266 |
|
267 | if (child.__normalized && isLock) {
|
268 |
|
269 | child.lock = child.lock || 'left';
|
270 | delete child.__normalized;
|
271 | }
|
272 | });
|
273 | this._isLock = isLock;
|
274 | return ret;
|
275 | };
|
276 |
|
277 |
|
278 |
|
279 |
|
280 | LockTable.prototype.splitFromNormalizeChildren = function splitFromNormalizeChildren(children) {
|
281 | var originChildren = deepCopy(children);
|
282 | var lockLeftChildren = deepCopy(children);
|
283 | var lockRightChildren = deepCopy(children);
|
284 | var loop = function loop(lockChildren, condition) {
|
285 | var ret = [];
|
286 | lockChildren.forEach(function (child) {
|
287 | if (child.children) {
|
288 | var res = loop(child.children, condition);
|
289 | if (!res.length) {
|
290 | ret.push(child);
|
291 | }
|
292 | } else {
|
293 | var order = condition(child);
|
294 | if (!order) {
|
295 | ret.push(child);
|
296 | }
|
297 | }
|
298 | });
|
299 | ret.forEach(function (res) {
|
300 | var index = lockChildren.indexOf(res);
|
301 | lockChildren.splice(index, 1);
|
302 | });
|
303 | return lockChildren;
|
304 | };
|
305 | loop(lockLeftChildren, function (child) {
|
306 | if (child.lock === true || child.lock === 'left') {
|
307 | return 'left';
|
308 | }
|
309 | });
|
310 | loop(lockRightChildren, function (child) {
|
311 | if (child.lock === 'right') {
|
312 | return 'right';
|
313 | }
|
314 | });
|
315 | loop(originChildren, function (child) {
|
316 | return child.lock !== true && child.lock !== 'left' && child.lock !== 'right';
|
317 | });
|
318 | return {
|
319 | lockLeftChildren: lockLeftChildren,
|
320 | lockRightChildren: lockRightChildren,
|
321 | originChildren: originChildren
|
322 | };
|
323 | };
|
324 |
|
325 |
|
326 |
|
327 |
|
328 | LockTable.prototype.mergeFromSplitLockChildren = function mergeFromSplitLockChildren(splitChildren) {
|
329 | var lockLeftChildren = splitChildren.lockLeftChildren,
|
330 | lockRightChildren = splitChildren.lockRightChildren;
|
331 | var originChildren = splitChildren.originChildren;
|
332 |
|
333 | Array.prototype.unshift.apply(originChildren, lockLeftChildren);
|
334 | originChildren = originChildren.concat(lockRightChildren);
|
335 | return originChildren;
|
336 | };
|
337 |
|
338 | LockTable.prototype.scroll = function scroll() {
|
339 | var _props2 = this.props,
|
340 | _props2$scrollToCol = _props2.scrollToCol,
|
341 | scrollToCol = _props2$scrollToCol === undefined ? 0 : _props2$scrollToCol,
|
342 | _props2$scrollToRow = _props2.scrollToRow,
|
343 | scrollToRow = _props2$scrollToRow === undefined ? 0 : _props2$scrollToRow;
|
344 |
|
345 | if (!scrollToCol && !scrollToRow || !this.bodyNode) {
|
346 | return;
|
347 | }
|
348 | var colCellNode = this.getCellNode(0, scrollToCol);
|
349 | var rowCellNode = this.getCellNode(scrollToRow, 0);
|
350 | var bodyNodeOffset = this.bodyNode.getBoundingClientRect() || {};
|
351 | if (colCellNode) {
|
352 | var cellNodeoffset = colCellNode.getBoundingClientRect();
|
353 | var scrollLeft = cellNodeoffset.left - bodyNodeOffset.left;
|
354 | this.bodyNode.scrollLeft = scrollLeft;
|
355 | }
|
356 | if (rowCellNode) {
|
357 | var _cellNodeoffset = rowCellNode.getBoundingClientRect();
|
358 | var scrollTop = _cellNodeoffset.top - bodyNodeOffset.top;
|
359 | this.bodyNode.scrollTop = scrollTop;
|
360 | }
|
361 | };
|
362 |
|
363 |
|
364 | LockTable.prototype.isLock = function isLock() {
|
365 | return this.lockLeftChildren.length || this.lockRightChildren.length;
|
366 | };
|
367 |
|
368 |
|
369 |
|
370 |
|
371 | LockTable.prototype.isOriginLock = function isOriginLock() {
|
372 | return this._isLock;
|
373 | };
|
374 |
|
375 | LockTable.prototype.removeLockTable = function removeLockTable() {
|
376 | var lockLeftLen = this.lockLeftChildren.length;
|
377 | var lockRightLen = this.lockRightChildren.length;
|
378 |
|
379 | if (lockLeftLen) {
|
380 | this._notNeedAdjustLockLeft = true;
|
381 | }
|
382 | if (lockRightLen) {
|
383 | this._notNeedAdjustLockRight = true;
|
384 | }
|
385 | if (lockRightLen || lockLeftLen) {
|
386 | this.forceUpdate();
|
387 | return true;
|
388 | }
|
389 | };
|
390 |
|
391 | LockTable.prototype.adjustIfTableNotNeedLock = function adjustIfTableNotNeedLock() {
|
392 | var _this2 = this;
|
393 |
|
394 | if (this.isOriginLock()) {
|
395 | var widthObj = this.tableInc.flatChildren.map(function (item, index) {
|
396 | var cell = _this2.getCellNode(0, index) || {};
|
397 | var headerCell = _this2.getHeaderCellNode(0, index) || {};
|
398 |
|
399 |
|
400 |
|
401 | try {
|
402 | return {
|
403 | cellWidths: parseFloat(getComputedStyle(cell).width) || 0,
|
404 | headerWidths: parseFloat(getComputedStyle(headerCell).width) || 0
|
405 | };
|
406 | } catch (error) {
|
407 | return {
|
408 | cellWidths: cell.clientWidth || 0,
|
409 | headerWidths: headerCell.clientWidth || 0
|
410 | };
|
411 | }
|
412 | }).reduce(function (a, b) {
|
413 | return {
|
414 | cellWidths: a.cellWidths + b.cellWidths,
|
415 | headerWidths: a.headerWidths + b.headerWidths
|
416 | };
|
417 | }, {
|
418 | cellWidths: 0,
|
419 | headerWidths: 0
|
420 | });
|
421 |
|
422 | var node = void 0,
|
423 | width = void 0;
|
424 |
|
425 | try {
|
426 | node = findDOMNode(this);
|
427 | width = node.clientWidth;
|
428 | } catch (err) {
|
429 | node = null;
|
430 | width = 0;
|
431 | }
|
432 |
|
433 |
|
434 | if (width === 0) {
|
435 | return true;
|
436 | }
|
437 |
|
438 | var configWidths = parseInt(widthObj.cellWidths) || parseInt(widthObj.headerWidths);
|
439 |
|
440 | if (configWidths <= width && configWidths > 0) {
|
441 | this.removeLockTable();
|
442 | } else if (this._notNeedAdjustLockLeft || this._notNeedAdjustLockRight) {
|
443 | this._notNeedAdjustLockLeft = this._notNeedAdjustLockRight = false;
|
444 | this.forceUpdate();
|
445 | } else {
|
446 | this._notNeedAdjustLockLeft = this._notNeedAdjustLockRight = false;
|
447 | return false;
|
448 | }
|
449 | }
|
450 |
|
451 | return false;
|
452 | };
|
453 |
|
454 | LockTable.prototype.adjustBodySize = function adjustBodySize() {
|
455 | var _style;
|
456 |
|
457 | var _props3 = this.props,
|
458 | rtl = _props3.rtl,
|
459 | hasHeader = _props3.hasHeader;
|
460 |
|
461 | var header = this.headerNode;
|
462 | var paddingName = rtl ? 'paddingLeft' : 'paddingRight';
|
463 | var marginName = rtl ? 'marginLeft' : 'marginRight';
|
464 | var scrollBarSize = +dom.scrollbar().width || 0;
|
465 | var style = (_style = {}, _style[paddingName] = scrollBarSize, _style[marginName] = scrollBarSize, _style);
|
466 | var body = this.bodyNode,
|
467 | hasVerScroll = body && body.scrollHeight > body.clientHeight;
|
468 |
|
469 | if (this.isLock()) {
|
470 | var lockLeftBody = this.bodyLeftNode,
|
471 | lockRightBody = this.bodyRightNode,
|
472 | lockRightBodyWrapper = this.getWrapperNode('right'),
|
473 | bodyHeight = body.offsetHeight,
|
474 | width = hasVerScroll ? scrollBarSize : 0,
|
475 | lockBodyHeight = bodyHeight - scrollBarSize;
|
476 |
|
477 | if (!hasVerScroll) {
|
478 | style[paddingName] = 0;
|
479 | style[marginName] = 0;
|
480 | }
|
481 | if (+scrollBarSize) {
|
482 | style.marginBottom = -scrollBarSize;
|
483 | style.paddingBottom = scrollBarSize;
|
484 | } else {
|
485 | style.marginBottom = -20;
|
486 | style.paddingBottom = 20;
|
487 | }
|
488 |
|
489 | var lockStyle = {
|
490 | 'max-height': lockBodyHeight
|
491 | };
|
492 | if (!hasHeader && !+scrollBarSize) {
|
493 | lockStyle[marginName] = 0;
|
494 | }
|
495 | if (+scrollBarSize) {
|
496 | lockStyle[marginName] = -scrollBarSize;
|
497 | }
|
498 | lockLeftBody && dom.setStyle(lockLeftBody, lockStyle);
|
499 | lockRightBody && dom.setStyle(lockRightBody, lockStyle);
|
500 | lockRightBodyWrapper && +scrollBarSize && dom.setStyle(lockRightBodyWrapper, rtl ? 'left' : 'right', width + 'px');
|
501 | } else {
|
502 | style.marginBottom = -scrollBarSize;
|
503 | style.paddingBottom = scrollBarSize;
|
504 | style[marginName] = 0;
|
505 | if (!hasVerScroll) {
|
506 | style[paddingName] = 0;
|
507 | }
|
508 | }
|
509 |
|
510 | header && dom.setStyle(header, style);
|
511 | };
|
512 |
|
513 | LockTable.prototype.adjustHeaderSize = function adjustHeaderSize() {
|
514 | var _this3 = this;
|
515 |
|
516 | if (this.isLock()) {
|
517 | this.tableInc.groupChildren.forEach(function (child, index) {
|
518 | var lastIndex = _this3.tableInc.groupChildren[index].length - 1;
|
519 | var headerRightRow = _this3.getHeaderCellNode(index, lastIndex),
|
520 | headerLeftRow = _this3.getHeaderCellNode(index, 0),
|
521 | headerRightLockRow = _this3.getHeaderCellNode(index, 0, 'right'),
|
522 | headerLeftLockRow = _this3.getHeaderCellNode(index, 0, 'left');
|
523 |
|
524 | if (headerRightRow && headerRightLockRow) {
|
525 | var maxRightRowHeight = headerRightRow.offsetHeight;
|
526 |
|
527 | dom.setStyle(headerRightLockRow, 'height', maxRightRowHeight);
|
528 |
|
529 | setTimeout(function () {
|
530 | var affixRef = _this3.tableRightInc.affixRef;
|
531 |
|
532 | return affixRef && affixRef.getInstance() && affixRef.getInstance().updatePosition();
|
533 | });
|
534 | }
|
535 |
|
536 | if (headerLeftRow && headerLeftLockRow) {
|
537 | var maxLeftRowHeight = headerLeftRow.offsetHeight;
|
538 |
|
539 | dom.setStyle(headerLeftLockRow, 'height', maxLeftRowHeight);
|
540 |
|
541 | setTimeout(function () {
|
542 | var affixRef = _this3.tableLeftInc.affixRef;
|
543 |
|
544 | return affixRef && affixRef.getInstance() && affixRef.getInstance().updatePosition();
|
545 | });
|
546 | }
|
547 | });
|
548 | }
|
549 | };
|
550 |
|
551 | LockTable.prototype.adjustRowHeight = function adjustRowHeight() {
|
552 | var _this4 = this;
|
553 |
|
554 | if (this.isLock()) {
|
555 | this.tableInc.props.dataSource.forEach(function (item, index) {
|
556 |
|
557 | var rowIndex = '' + ((typeof item === 'undefined' ? 'undefined' : _typeof(item)) === 'object' && '__rowIndex' in item ? item.__rowIndex : index) + (item.__expanded ? '_expanded' : '');
|
558 |
|
559 |
|
560 | _this4.setRowHeight(rowIndex, 'left');
|
561 |
|
562 | _this4.setRowHeight(rowIndex, 'right');
|
563 | });
|
564 | }
|
565 | };
|
566 |
|
567 | LockTable.prototype.setRowHeight = function setRowHeight(rowIndex, dir) {
|
568 | var lockRow = this.getRowNode(rowIndex, dir),
|
569 | row = this.getRowNode(rowIndex),
|
570 | rowHeight = (ieVersion ? row && row.offsetHeight : row && parseFloat(getComputedStyle(row).height)) || 'auto',
|
571 | lockHeight = (ieVersion ? lockRow && lockRow.offsetHeight : lockRow && parseFloat(getComputedStyle(lockRow).height)) || 'auto';
|
572 |
|
573 | if (lockRow && rowHeight !== lockHeight) {
|
574 | dom.setStyle(lockRow, 'height', rowHeight);
|
575 | }
|
576 | };
|
577 |
|
578 | LockTable.prototype.getWrapperNode = function getWrapperNode(type) {
|
579 | type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
|
580 | try {
|
581 |
|
582 |
|
583 |
|
584 | return findDOMNode(this['lock' + type + 'El']);
|
585 | } catch (error) {
|
586 | return null;
|
587 | }
|
588 | };
|
589 |
|
590 |
|
591 |
|
592 |
|
593 |
|
594 |
|
595 |
|
596 |
|
597 |
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 | LockTable.prototype.getRowNode = function getRowNode(index, type) {
|
606 | type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
|
607 | var table = this['table' + type + 'Inc'];
|
608 |
|
609 | try {
|
610 |
|
611 |
|
612 |
|
613 | return findDOMNode(table.getRowRef(index));
|
614 | } catch (error) {
|
615 | return null;
|
616 | }
|
617 | };
|
618 |
|
619 | LockTable.prototype.getHeaderCellNode = function getHeaderCellNode(index, i, type) {
|
620 | type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
|
621 | var table = this['table' + type + 'Inc'];
|
622 |
|
623 | try {
|
624 |
|
625 |
|
626 |
|
627 | return findDOMNode(table.getHeaderCellRef(index, i));
|
628 | } catch (error) {
|
629 | return null;
|
630 | }
|
631 | };
|
632 |
|
633 | LockTable.prototype.getCellNode = function getCellNode(index, i, type) {
|
634 | type = type ? type.charAt(0).toUpperCase() + type.substr(1) : '';
|
635 | var table = this['table' + type + 'Inc'];
|
636 |
|
637 | try {
|
638 |
|
639 |
|
640 |
|
641 | return findDOMNode(table.getCellRef(index, i));
|
642 | } catch (error) {
|
643 | return null;
|
644 | }
|
645 | };
|
646 |
|
647 | LockTable.prototype.render = function render() {
|
648 |
|
649 | var _props4 = this.props,
|
650 | children = _props4.children,
|
651 | columns = _props4.columns,
|
652 | prefix = _props4.prefix,
|
653 | components = _props4.components,
|
654 | className = _props4.className,
|
655 | dataSource = _props4.dataSource,
|
656 | tableWidth = _props4.tableWidth,
|
657 | others = _objectWithoutProperties(_props4, ['children', 'columns', 'prefix', 'components', 'className', 'dataSource', 'tableWidth']);
|
658 |
|
659 | var _normalizeChildrenSta = this.normalizeChildrenState(this.props),
|
660 | lockLeftChildren = _normalizeChildrenSta.lockLeftChildren,
|
661 | lockRightChildren = _normalizeChildrenSta.lockRightChildren,
|
662 | normalizedChildren = _normalizeChildrenSta.children;
|
663 |
|
664 | var leftLen = this.getFlatenChildrenLength(lockLeftChildren);
|
665 | var rightLen = this.getFlatenChildrenLength(lockRightChildren);
|
666 | var originLen = this.getFlatenChildrenLength(normalizedChildren);
|
667 |
|
668 | var lengths = {
|
669 | left: leftLen,
|
670 | right: rightLen,
|
671 | origin: originLen
|
672 | };
|
673 | if (this._notNeedAdjustLockLeft) {
|
674 | lockLeftChildren = [];
|
675 | }
|
676 | if (this._notNeedAdjustLockRight) {
|
677 | lockRightChildren = [];
|
678 | }
|
679 | this.lockLeftChildren = lockLeftChildren;
|
680 | this.lockRightChildren = lockRightChildren;
|
681 |
|
682 | if (this.isOriginLock()) {
|
683 | var _classnames;
|
684 |
|
685 | components = _extends({}, components);
|
686 | components.Body = components.Body || LockBody;
|
687 | components.Header = components.Header || LockHeader;
|
688 | components.Wrapper = components.Wrapper || LockWrapper;
|
689 | components.Row = components.Row || LockRow;
|
690 | className = classnames((_classnames = {}, _classnames[prefix + 'table-lock'] = true, _classnames[prefix + 'table-wrap-empty'] = !dataSource.length, _classnames[className] = className, _classnames));
|
691 | var content = [React.createElement(BaseComponent, _extends({}, others, {
|
692 | dataSource: dataSource,
|
693 | key: 'lock-left',
|
694 | columns: lockLeftChildren,
|
695 | className: prefix + 'table-lock-left',
|
696 | lengths: lengths,
|
697 | prefix: prefix,
|
698 | lockType: 'left',
|
699 | components: components,
|
700 | ref: this.saveLockLeftRef,
|
701 | loading: false,
|
702 | 'aria-hidden': true
|
703 | })), React.createElement(BaseComponent, _extends({}, others, {
|
704 | dataSource: dataSource,
|
705 | key: 'lock-right',
|
706 | columns: lockRightChildren,
|
707 | className: prefix + 'table-lock-right',
|
708 | lengths: lengths,
|
709 | prefix: prefix,
|
710 | lockType: 'right',
|
711 | components: components,
|
712 | ref: this.saveLockRightRef,
|
713 | loading: false,
|
714 | 'aria-hidden': true
|
715 | }))];
|
716 | return React.createElement(BaseComponent, _extends({}, others, {
|
717 | tableWidth: tableWidth,
|
718 | dataSource: dataSource,
|
719 | columns: normalizedChildren,
|
720 | prefix: prefix,
|
721 | lengths: lengths,
|
722 | wrapperContent: content,
|
723 | components: components,
|
724 | className: className
|
725 | }));
|
726 | }
|
727 | return React.createElement(BaseComponent, this.props);
|
728 | };
|
729 |
|
730 | return LockTable;
|
731 | }(React.Component), _class.LockRow = LockRow, _class.LockBody = LockBody, _class.LockHeader = LockHeader, _class.propTypes = _extends({
|
732 | scrollToCol: PropTypes.number,
|
733 | |
734 |
|
735 |
|
736 | scrollToRow: PropTypes.number
|
737 | }, BaseComponent.propTypes), _class.defaultProps = _extends({}, BaseComponent.defaultProps), _class.childContextTypes = {
|
738 | getTableInstance: PropTypes.func,
|
739 | getLockNode: PropTypes.func,
|
740 | onLockBodyScroll: PropTypes.func,
|
741 | onRowMouseEnter: PropTypes.func,
|
742 | onRowMouseLeave: PropTypes.func
|
743 | }, _temp);
|
744 | LockTable.displayName = 'LockTable';
|
745 |
|
746 | statics(LockTable, BaseComponent);
|
747 | return LockTable;
|
748 | }
|
749 |
|
750 | function deepCopy(arr) {
|
751 | var copy = function copy(arr) {
|
752 | return arr.map(function (item) {
|
753 | var newItem = _extends({}, item);
|
754 | if (item.children) {
|
755 | item.children = copy(item.children);
|
756 | }
|
757 | return newItem;
|
758 | });
|
759 | };
|
760 | return copy(arr);
|
761 | } |
\ | No newline at end of file |