feat(bee-table): tableCell colSpan==0 return null & isLeaf 改为 _isLeaf

This commit is contained in:
liushaozhen 2020-03-11 13:52:12 +08:00
parent 792698025a
commit 4452dc6a69
11 changed files with 92 additions and 83 deletions

View File

@ -879,11 +879,11 @@ var Table = function (_Component) {
var record = data[i]; var record = data[i];
var key = this.getRowKey(record, i); var key = this.getRowKey(record, i);
// 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点 // 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点
record['isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['isLeaf']; record['_isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['_isLeaf'];
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段 // _isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null。Table内部字段 // _isLeaf 有三种取值情况true / false / null。Table内部字段
var isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null; var _isLeaf = typeof record['_isLeaf'] === 'boolean' ? record['_isLeaf'] : null;
var childrenColumn = isLeaf ? false : record[childrenColumnName]; var childrenColumn = _isLeaf ? false : record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i); var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0; var expandedRowContent = void 0;
var expandedContentHeight = 0; var expandedContentHeight = 0;
@ -948,7 +948,7 @@ var Table = function (_Component) {
visible: visible, visible: visible,
expandRowByClick: expandRowByClick, expandRowByClick: expandRowByClick,
onExpand: this.onExpanded, onExpand: this.onExpanded,
expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : isLeaf === false), expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : _isLeaf === false),
expanded: isRowExpanded, expanded: isRowExpanded,
clsPrefix: props.clsPrefix + '-row', clsPrefix: props.clsPrefix + '-row',
childrenColumnName: childrenColumnName, childrenColumnName: childrenColumnName,

View File

@ -429,19 +429,22 @@ var TableCell = function (_Component) {
className += ' u-table-inline-icon'; className += ' u-table-inline-icon';
} }
return _react2["default"].createElement( return _react2["default"].createElement(
'td', _react.Fragment,
{ null,
colSpan: colSpan, colSpan == 0 ? null : _react2["default"].createElement(
rowSpan: rowSpan, 'td',
className: className, {
onClick: this.handleClick, colSpan: colSpan,
title: title, rowSpan: rowSpan,
style: _extends({ maxWidth: column.width, color: fontColor, backgroundColor: bgColor }, column.style) className: className,
}, onClick: this.handleClick,
indentText, title: title,
expandIcon, style: _extends({ maxWidth: column.width, color: fontColor, backgroundColor: bgColor }, column.style) },
text, indentText,
colMenu expandIcon,
text,
colMenu
)
); );
}; };

View File

@ -410,14 +410,14 @@ function bigData(Table) {
children = _dataCopy$i.children, children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]), props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(), dataCopyI = new Object(),
isLeaf = children && children.length > 0 ? false : true, _isLeaf = children && children.length > 0 ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false; isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
dataCopyI = _extends(dataCopyI, { dataCopyI = _extends(dataCopyI, {
key: key, key: key,
isExpanded: isExpanded, isExpanded: isExpanded,
parentKey: parentKey, parentKey: parentKey,
isLeaf: isLeaf, _isLeaf: _isLeaf,
index: flatTreeData.length index: flatTreeData.length
}, _extends({}, props)); }, _extends({}, props));
@ -439,7 +439,7 @@ function bigData(Table) {
id: 'key', id: 'key',
parendId: 'parentKey', parendId: 'parentKey',
rootId: null, rootId: null,
isLeaf: 'isLeaf' _isLeaf: '_isLeaf'
}; };
var treeData = (0, _utils.convertListToTree)(treeList, attr, _this4.flatTreeKeysMap); var treeData = (0, _utils.convertListToTree)(treeList, attr, _this4.flatTreeKeysMap);

View File

@ -371,13 +371,13 @@ var Event = exports.Event = {
var key = node.key, var key = node.key,
title = node.title, title = node.title,
children = node.children, children = node.children,
isLeaf = node.isLeaf, _isLeaf = node._isLeaf,
otherProps = _objectWithoutProperties(node, ['key', 'title', 'children', 'isLeaf']); otherProps = _objectWithoutProperties(node, ['key', 'title', 'children', '_isLeaf']);
var obj = { var obj = {
key: key, key: key,
title: title, title: title,
isLeaf: isLeaf, _isLeaf: _isLeaf,
children: [] children: []
}; };
tree.push(_extends(obj, _extends({}, otherProps))); tree.push(_extends(obj, _extends({}, otherProps)));
@ -397,7 +397,7 @@ var Event = exports.Event = {
var obj = { var obj = {
key: item[attr.id], key: item[attr.id],
isLeaf: item[attr.isLeaf], _isLeaf: item[attr._isLeaf],
children: [] children: []
}; };
tree.push(_extends(obj, _extends({}, otherProps))); tree.push(_extends(obj, _extends({}, otherProps)));
@ -423,7 +423,7 @@ var Event = exports.Event = {
var _obj = { var _obj = {
key: _item[attr.id], key: _item[attr.id],
isLeaf: _item[attr.isLeaf], _isLeaf: _item[attr._isLeaf],
children: [] children: []
}; };
treeArrs[_i].children.push(_extends(_obj, _extends({}, _otherProps))); treeArrs[_i].children.push(_extends(_obj, _extends({}, _otherProps)));

57
dist/demo.js vendored
View File

@ -38073,11 +38073,11 @@
var record = data[i]; var record = data[i];
var key = this.getRowKey(record, i); var key = this.getRowKey(record, i);
// 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点 // 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点
record['isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['isLeaf']; record['_isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['_isLeaf'];
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段 // _isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null。Table内部字段 // _isLeaf 有三种取值情况true / false / null。Table内部字段
var isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null; var _isLeaf = typeof record['_isLeaf'] === 'boolean' ? record['_isLeaf'] : null;
var childrenColumn = isLeaf ? false : record[childrenColumnName]; var childrenColumn = _isLeaf ? false : record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i); var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0; var expandedRowContent = void 0;
var expandedContentHeight = 0; var expandedContentHeight = 0;
@ -38142,7 +38142,7 @@
visible: visible, visible: visible,
expandRowByClick: expandRowByClick, expandRowByClick: expandRowByClick,
onExpand: this.onExpanded, onExpand: this.onExpanded,
expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : isLeaf === false), expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : _isLeaf === false),
expanded: isRowExpanded, expanded: isRowExpanded,
clsPrefix: props.clsPrefix + '-row', clsPrefix: props.clsPrefix + '-row',
childrenColumnName: childrenColumnName, childrenColumnName: childrenColumnName,
@ -39911,13 +39911,13 @@
var key = node.key, var key = node.key,
title = node.title, title = node.title,
children = node.children, children = node.children,
isLeaf = node.isLeaf, _isLeaf = node._isLeaf,
otherProps = _objectWithoutProperties(node, ['key', 'title', 'children', 'isLeaf']); otherProps = _objectWithoutProperties(node, ['key', 'title', 'children', '_isLeaf']);
var obj = { var obj = {
key: key, key: key,
title: title, title: title,
isLeaf: isLeaf, _isLeaf: _isLeaf,
children: [] children: []
}; };
tree.push(_extends(obj, _extends({}, otherProps))); tree.push(_extends(obj, _extends({}, otherProps)));
@ -39937,7 +39937,7 @@
var obj = { var obj = {
key: item[attr.id], key: item[attr.id],
isLeaf: item[attr.isLeaf], _isLeaf: item[attr._isLeaf],
children: [] children: []
}; };
tree.push(_extends(obj, _extends({}, otherProps))); tree.push(_extends(obj, _extends({}, otherProps)));
@ -39963,7 +39963,7 @@
var _obj = { var _obj = {
key: _item[attr.id], key: _item[attr.id],
isLeaf: _item[attr.isLeaf], _isLeaf: _item[attr._isLeaf],
children: [] children: []
}; };
treeArrs[_i].children.push(_extends(_obj, _extends({}, _otherProps))); treeArrs[_i].children.push(_extends(_obj, _extends({}, _otherProps)));
@ -40821,19 +40821,22 @@
className += ' u-table-inline-icon'; className += ' u-table-inline-icon';
} }
return _react2['default'].createElement( return _react2['default'].createElement(
'td', _react.Fragment,
{ null,
colSpan: colSpan, colSpan == 0 ? null : _react2['default'].createElement(
rowSpan: rowSpan, 'td',
className: className, {
onClick: this.handleClick, colSpan: colSpan,
title: title, rowSpan: rowSpan,
style: _extends({ maxWidth: column.width, color: fontColor, backgroundColor: bgColor }, column.style) className: className,
}, onClick: this.handleClick,
indentText, title: title,
expandIcon, style: _extends({ maxWidth: column.width, color: fontColor, backgroundColor: bgColor }, column.style) },
text, indentText,
colMenu expandIcon,
text,
colMenu
)
); );
}; };
@ -264171,14 +264174,14 @@
children = _dataCopy$i.children, children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]), props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(), dataCopyI = new Object(),
isLeaf = children && children.length > 0 ? false : true, _isLeaf = children && children.length > 0 ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false; isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
dataCopyI = _extends(dataCopyI, { dataCopyI = _extends(dataCopyI, {
key: key, key: key,
isExpanded: isExpanded, isExpanded: isExpanded,
parentKey: parentKey, parentKey: parentKey,
isLeaf: isLeaf, _isLeaf: _isLeaf,
index: flatTreeData.length index: flatTreeData.length
}, _extends({}, props)); }, _extends({}, props));
@ -264200,7 +264203,7 @@
id: 'key', id: 'key',
parendId: 'parentKey', parendId: 'parentKey',
rootId: null, rootId: null,
isLeaf: 'isLeaf' _isLeaf: '_isLeaf'
}; };
var treeData = (0, _utils.convertListToTree)(treeList, attr, _this4.flatTreeKeysMap); var treeData = (0, _utils.convertListToTree)(treeList, attr, _this4.flatTreeKeysMap);

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "bee-table", "name": "bee-table",
"version": "2.2.39", "version": "2.2.40",
"description": "Table ui component for react", "description": "Table ui component for react",
"keywords": [ "keywords": [
"react", "react",

View File

@ -717,11 +717,11 @@ class Table extends Component {
const record = data[i]; const record = data[i];
const key = this.getRowKey(record, i); const key = this.getRowKey(record, i);
// 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点 // 兼容 NCC 以前的业务逻辑,支持外部通过 record 中的 isleaf 字段,判断是否为叶子节点
record['isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['isLeaf']; record['_isLeaf'] = typeof record['isleaf'] === 'boolean' ? record['isleaf'] : record['_isLeaf'];
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段 // _isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null。Table内部字段 // _isLeaf 有三种取值情况true / false / null。Table内部字段
const isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null; const _isLeaf = typeof record['_isLeaf'] === 'boolean' ? record['_isLeaf'] : null;
const childrenColumn = isLeaf ? false : record[childrenColumnName]; const childrenColumn = _isLeaf ? false : record[childrenColumnName];
const isRowExpanded = this.isRowExpanded(record, i); const isRowExpanded = this.isRowExpanded(record, i);
let expandedRowContent; let expandedRowContent;
let expandedContentHeight = 0; let expandedContentHeight = 0;
@ -789,7 +789,7 @@ class Table extends Component {
visible={visible} visible={visible}
expandRowByClick={expandRowByClick} expandRowByClick={expandRowByClick}
onExpand={this.onExpanded} onExpand={this.onExpanded}
expandable={expandedRowRender || ((childrenColumn && childrenColumn.length > 0) ? true : isLeaf === false)} expandable={expandedRowRender || ((childrenColumn && childrenColumn.length > 0) ? true : _isLeaf === false)}
expanded={isRowExpanded} expanded={isRowExpanded}
clsPrefix={`${props.clsPrefix}-row`} clsPrefix={`${props.clsPrefix}-row`}
childrenColumnName={childrenColumnName} childrenColumnName={childrenColumnName}

View File

@ -1,4 +1,4 @@
import React, { Component } from 'react'; import React, { Component,Fragment } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import objectPath from 'object-path'; import objectPath from 'object-path';
import i18n from './lib/i18n'; import i18n from './lib/i18n';
@ -281,19 +281,22 @@ class TableCell extends Component{
className += ' u-table-inline-icon' className += ' u-table-inline-icon'
} }
return ( return (
<td <Fragment>
colSpan={colSpan} {
rowSpan={rowSpan} colSpan==0?null:<td
className={className} colSpan={colSpan}
onClick={this.handleClick} rowSpan={rowSpan}
title={title} className={className}
style={{maxWidth:column.width, color:fontColor, backgroundColor:bgColor, ...column.style}} onClick={this.handleClick}
> title={title}
{indentText} style={{maxWidth:column.width, color:fontColor, backgroundColor:bgColor, ...column.style}}>
{expandIcon} {indentText}
{text} {expandIcon}
{colMenu} {text}
</td> {colMenu}
</td>
}
</Fragment>
); );
} }
}; };

View File

@ -134,14 +134,14 @@ export default function bigData(Table) {
for (let i=0, l=dataCopy.length; i<l; i++) { for (let i=0, l=dataCopy.length; i<l; i++) {
let { key, children, ...props } = dataCopy[i], let { key, children, ...props } = dataCopy[i],
dataCopyI = new Object(), dataCopyI = new Object(),
isLeaf = (children && children.length > 0) ? false : true, _isLeaf = (children && children.length > 0) ? false : true,
//如果父节点是收起状态,则子节点的展开状态无意义。(一级节点或根节点直接判断自身状态即可) //如果父节点是收起状态,则子节点的展开状态无意义。(一级节点或根节点直接判断自身状态即可)
isExpanded = (parentKey === null || expandedKeysSet.has(parentKey)) ? expandedKeysSet.has(key) : false; isExpanded = (parentKey === null || expandedKeysSet.has(parentKey)) ? expandedKeysSet.has(key) : false;
dataCopyI = Object.assign(dataCopyI,{ dataCopyI = Object.assign(dataCopyI,{
key, key,
isExpanded, isExpanded,
parentKey : parentKey, parentKey : parentKey,
isLeaf, _isLeaf,
index: flatTreeData.length index: flatTreeData.length
},{...props}); },{...props});
@ -166,7 +166,7 @@ export default function bigData(Table) {
id: 'key', id: 'key',
parendId: 'parentKey', parendId: 'parentKey',
rootId: null, rootId: null,
isLeaf: 'isLeaf' _isLeaf: '_isLeaf'
}; };
let treeData = convertListToTree(treeList, attr, this.flatTreeKeysMap); let treeData = convertListToTree(treeList, attr, this.flatTreeKeysMap);

View File

@ -347,11 +347,11 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
}else{ }else{
// 用 treeKeysMap 判断,避免重复累加 // 用 treeKeysMap 判断,避免重复累加
if (!treeKeysMap.hasOwnProperty(node[attr.id]) ) { if (!treeKeysMap.hasOwnProperty(node[attr.id]) ) {
let { key, title, children, isLeaf, ...otherProps } = node; let { key, title, children, _isLeaf, ...otherProps } = node;
let obj = { let obj = {
key, key,
title, title,
isLeaf, _isLeaf,
children: [] children: []
} }
tree.push(Object.assign(obj, {...otherProps})); tree.push(Object.assign(obj, {...otherProps}));
@ -366,7 +366,7 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
let { key, title, children, ...otherProps } = item; let { key, title, children, ...otherProps } = item;
let obj = { let obj = {
key: item[attr.id], key: item[attr.id],
isLeaf: item[attr.isLeaf], _isLeaf: item[attr._isLeaf],
children: [] children: []
}; };
tree.push(Object.assign(obj, {...otherProps})); tree.push(Object.assign(obj, {...otherProps}));
@ -387,7 +387,7 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
let { key, title, children, ...otherProps } = item; let { key, title, children, ...otherProps } = item;
let obj = { let obj = {
key: item[attr.id], key: item[attr.id],
isLeaf: item[attr.isLeaf], _isLeaf: item[attr._isLeaf],
children: [] children: []
}; };
treeArrs[i].children.push(Object.assign(obj, {...otherProps})); treeArrs[i].children.push(Object.assign(obj, {...otherProps}));