fix:记录 record 中的 children = [] 时,显示了多余的展开图标

This commit is contained in:
yangchch6 2019-12-05 16:27:38 +08:00
parent 1a84262dc0
commit e383ad4b7c
6 changed files with 25 additions and 72 deletions

View File

@ -877,26 +877,11 @@ var Table = function (_Component) {
var lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ? props.lazyLoad.endIndex : -1;
for (var i = 0; i < data.length; i++) {
var isHiddenExpandIcon = void 0;
// if ( props.showRowNum ){
// switch(props.showRowNum.type){
// case 'number':{
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// case 'ascii': {
// data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt());
// break;
// }
// default: {
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// }
// }
var record = data[i];
var key = this.getRowKey(record, i);
var isLeaf = typeof record['isLeaf'] === 'boolean' && record['isLeaf'] || false;
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null
var isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null;
var childrenColumn = isLeaf ? false : record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0;
@ -962,7 +947,7 @@ var Table = function (_Component) {
visible: visible,
expandRowByClick: expandRowByClick,
onExpand: this.onExpanded,
expandable: childrenColumn || expandedRowRender,
expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : isLeaf === false),
expanded: isRowExpanded,
clsPrefix: props.clsPrefix + '-row',
childrenColumnName: childrenColumnName,

View File

@ -376,11 +376,10 @@ function bigData(Table) {
this.getTreeData = function (expandedKeys) {
var startIndex = _this4.startIndex,
endIndex = _this4.endIndex,
cacheExpandedKeys = _this4.cacheExpandedKeys;
endIndex = _this4.endIndex;
var data = _this4.props.data;
cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
_this4.cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
// 深递归 data截取可视区 data 数组,再将扁平结构转换成嵌套结构
var sliceTreeList = [];
var flatTreeData = _this4.deepTraversal(data);
@ -388,7 +387,7 @@ function bigData(Table) {
sliceTreeList = flatTreeData.slice(startIndex, endIndex);
_this4.handleTreeListChange(sliceTreeList);
cacheExpandedKeys = expandedKeys && null;
_this4.cacheExpandedKeys = expandedKeys && null;
};
this.deepTraversal = function (treeData) {
@ -410,7 +409,7 @@ function bigData(Table) {
children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(),
isLeaf = children ? false : true,
isLeaf = children && children.length > 0 ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
dataCopyI = _extends(dataCopyI, {

32
dist/demo.js vendored
View File

@ -37896,26 +37896,11 @@
var lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ? props.lazyLoad.endIndex : -1;
for (var i = 0; i < data.length; i++) {
var isHiddenExpandIcon = void 0;
// if ( props.showRowNum ){
// switch(props.showRowNum.type){
// case 'number':{
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// case 'ascii': {
// data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt());
// break;
// }
// default: {
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// }
// }
var record = data[i];
var key = this.getRowKey(record, i);
var isLeaf = typeof record['isLeaf'] === 'boolean' && record['isLeaf'] || false;
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null
var isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null;
var childrenColumn = isLeaf ? false : record[childrenColumnName];
var isRowExpanded = this.isRowExpanded(record, i);
var expandedRowContent = void 0;
@ -37981,7 +37966,7 @@
visible: visible,
expandRowByClick: expandRowByClick,
onExpand: this.onExpanded,
expandable: childrenColumn || expandedRowRender,
expandable: expandedRowRender || (childrenColumn && childrenColumn.length > 0 ? true : isLeaf === false),
expanded: isRowExpanded,
clsPrefix: props.clsPrefix + '-row',
childrenColumnName: childrenColumnName,
@ -289961,11 +289946,10 @@
this.getTreeData = function (expandedKeys) {
var startIndex = _this4.startIndex,
endIndex = _this4.endIndex,
cacheExpandedKeys = _this4.cacheExpandedKeys;
endIndex = _this4.endIndex;
var data = _this4.props.data;
cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
_this4.cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
// 深递归 data截取可视区 data 数组,再将扁平结构转换成嵌套结构
var sliceTreeList = [];
var flatTreeData = _this4.deepTraversal(data);
@ -289973,7 +289957,7 @@
sliceTreeList = flatTreeData.slice(startIndex, endIndex);
_this4.handleTreeListChange(sliceTreeList);
cacheExpandedKeys = expandedKeys && null;
_this4.cacheExpandedKeys = expandedKeys && null;
};
this.deepTraversal = function (treeData) {
@ -289995,7 +289979,7 @@
children = _dataCopy$i.children,
props = _objectWithoutProperties(_dataCopy$i, ["key", "children"]),
dataCopyI = new Object(),
isLeaf = children ? false : true,
isLeaf = children && children.length > 0 ? false : true,
isExpanded = parentKey === null || expandedKeysSet.has(parentKey) ? expandedKeysSet.has(key) : false;
dataCopyI = _extends(dataCopyI, {

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -717,26 +717,11 @@ class Table extends Component {
const lazyEndIndex = props.lazyLoad && props.lazyLoad.endIndex ?props.lazyLoad.endIndex :-1;
for (let i = 0; i < data.length; i++) {
let isHiddenExpandIcon;
// if ( props.showRowNum ){
// switch(props.showRowNum.type){
// case 'number':{
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// case 'ascii': {
// data[i][props.showRowNum.key || '_index'] = String.fromCharCode(i + (props.showRowNum.base || '0').charCodeAt());
// break;
// }
// default: {
// data[i][props.showRowNum.key || '_index'] = (props.showRowNum.base || 0) + i;
// break;
// }
// }
// }
const record = data[i];
const key = this.getRowKey(record, i);
const isLeaf = typeof record['isLeaf'] === 'boolean' && record['isLeaf'] || false;
// isLeaf 字段是在 bigData 里添加的,只有层级树大数据场景需要该字段
// isLeaf 有三种取值情况true / false / null
const isLeaf = typeof record['isLeaf'] === 'boolean' ? record['isLeaf'] : null;
const childrenColumn = isLeaf ? false : record[childrenColumnName];
const isRowExpanded = this.isRowExpanded(record, i);
let expandedRowContent;
@ -805,7 +790,7 @@ class Table extends Component {
visible={visible}
expandRowByClick={expandRowByClick}
onExpand={this.onExpanded}
expandable={childrenColumn || expandedRowRender}
expandable={expandedRowRender || ((childrenColumn && childrenColumn.length > 0) ? true : isLeaf === false)}
expanded={isRowExpanded}
clsPrefix={`${props.clsPrefix}-row`}
childrenColumnName={childrenColumnName}

View File

@ -105,9 +105,9 @@ export default function bigData(Table) {
* @param expandedKeys: props 中传入的新 expandedRowKeys 属性值
*/
getTreeData = (expandedKeys) => {
let { startIndex, endIndex, cacheExpandedKeys } = this;
let { startIndex, endIndex } = this;
const { data } = this.props;
cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
this.cacheExpandedKeys = expandedKeys && new Set(expandedKeys);
// 深递归 data截取可视区 data 数组,再将扁平结构转换成嵌套结构
let sliceTreeList = [];
let flatTreeData = this.deepTraversal(data);
@ -115,7 +115,7 @@ export default function bigData(Table) {
sliceTreeList = flatTreeData.slice(startIndex, endIndex);
this.handleTreeListChange(sliceTreeList);
cacheExpandedKeys = expandedKeys && null;
this.cacheExpandedKeys = expandedKeys && null;
}
/**
@ -133,7 +133,7 @@ export default function bigData(Table) {
for (let i=0, l=dataCopy.length; i<l; i++) {
let { key, children, ...props } = dataCopy[i],
dataCopyI = new Object(),
isLeaf = children ? false : true,
isLeaf = (children && children.length > 0) ? false : true,
//如果父节点是收起状态,则子节点的展开状态无意义。(一级节点或根节点直接判断自身状态即可)
isExpanded = (parentKey === null || expandedKeysSet.has(parentKey)) ? expandedKeysSet.has(key) : false;
dataCopyI = Object.assign(dataCopyI,{