解决数据量少时,出现滚动条的问题
This commit is contained in:
parent
8524f03c82
commit
2b9457cb17
|
@ -1164,6 +1164,9 @@ var _initialiseProps = function _initialiseProps() {
|
||||||
|
|
||||||
this.getSumHeight = function (start, end) {
|
this.getSumHeight = function (start, end) {
|
||||||
var sumHeight = 0;
|
var sumHeight = 0;
|
||||||
|
if (start > end) {
|
||||||
|
return sumHeight;
|
||||||
|
}
|
||||||
var span = Math.abs(end - start);
|
var span = Math.abs(end - start);
|
||||||
if (span) {
|
if (span) {
|
||||||
sumHeight = span * _config2["default"].defaultHeight;
|
sumHeight = span * _config2["default"].defaultHeight;
|
||||||
|
|
|
@ -131,6 +131,7 @@ var InfiniteScroll = function (_Component) {
|
||||||
// "**endIndex**" + endIndex
|
// "**endIndex**" + endIndex
|
||||||
// );
|
// );
|
||||||
newTreeList = _this.treeList.slice(startIndex, endIndex);
|
newTreeList = _this.treeList.slice(startIndex, endIndex);
|
||||||
|
// console.log(JSON.stringify(newTreeList))
|
||||||
_this.props.handleTreeListChange && _this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
_this.props.handleTreeListChange && _this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -390,10 +390,12 @@ function warnOnlyTreeNode() {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
var tree = [];
|
var tree = []; //存储所有一级节点
|
||||||
var resData = treeData,
|
var resData = treeData,
|
||||||
resKeysMap = {},
|
//resData 存储截取的节点 + 父节点(除一级节点外)
|
||||||
treeKeysMap = {};
|
resKeysMap = {},
|
||||||
|
//resData 的Map映射
|
||||||
|
treeKeysMap = {}; //tree 的Map映射
|
||||||
resData.map(function (element) {
|
resData.map(function (element) {
|
||||||
var key = attr.id;
|
var key = attr.id;
|
||||||
resKeysMap[element[key]] = element;
|
resKeysMap[element[key]] = element;
|
||||||
|
@ -416,21 +418,20 @@ function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
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']);
|
||||||
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)));
|
||||||
treeKeysMap[key] = node;
|
treeKeysMap[key] = node;
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// 遍历 resData ,找到所有的一级节点
|
||||||
for (var i = 0; i < resData.length; i++) {
|
for (var i = 0; i < resData.length; i++) {
|
||||||
var item = resData[i];
|
var item = resData[i];
|
||||||
if (item[attr.parendId] === attr.rootId) {
|
if (item[attr.parendId] === attr.rootId) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ class DemoGroup extends Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
{DemoArray.map((child,index) => {
|
{[DemoArray[12]].map((child,index) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Demo example= {child.example} title= {child.title} code= {child.code} scss_code= {child.scss_code} desc= {child.desc} key= {index}/>
|
<Demo example= {child.example} title= {child.title} code= {child.code} scss_code= {child.scss_code} desc= {child.desc} key= {index}/>
|
||||||
|
|
|
@ -69,7 +69,7 @@ class DemoGroup extends Component {
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
{DemoArray.map((child,index) => {
|
{[DemoArray[12]].map((child,index) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Demo example= {child.example} title= {child.title} code= {child.code} scss_code= {child.scss_code} desc= {child.desc} key= {index}/>
|
<Demo example= {child.example} title= {child.title} code= {child.code} scss_code= {child.scss_code} desc= {child.desc} key= {index}/>
|
||||||
|
|
|
@ -197,7 +197,7 @@
|
||||||
return _react2['default'].createElement(
|
return _react2['default'].createElement(
|
||||||
_beeLayout.Row,
|
_beeLayout.Row,
|
||||||
null,
|
null,
|
||||||
DemoArray.map(function (child, index) {
|
[DemoArray[12]].map(function (child, index) {
|
||||||
|
|
||||||
return _react2['default'].createElement(Demo, { example: child.example, title: child.title, code: child.code, scss_code: child.scss_code, desc: child.desc, key: index });
|
return _react2['default'].createElement(Demo, { example: child.example, title: child.title, code: child.code, scss_code: child.scss_code, desc: child.desc, key: index });
|
||||||
})
|
})
|
||||||
|
@ -34446,6 +34446,7 @@
|
||||||
//启用懒加载,把 Tree 结构拍平,为后续动态截取数据做准备
|
//启用懒加载,把 Tree 结构拍平,为后续动态截取数据做准备
|
||||||
if (lazyLoad) {
|
if (lazyLoad) {
|
||||||
var flatTreeData = this.deepTraversal(treeData);
|
var flatTreeData = this.deepTraversal(treeData);
|
||||||
|
// console.log(JSON.stringify(flatTreeData))
|
||||||
flatTreeData.forEach(function (element) {
|
flatTreeData.forEach(function (element) {
|
||||||
if (sliceTreeList.length >= _this2.loadCount) return;
|
if (sliceTreeList.length >= _this2.loadCount) return;
|
||||||
sliceTreeList.push(element);
|
sliceTreeList.push(element);
|
||||||
|
@ -35314,6 +35315,10 @@
|
||||||
sufHeight = 0,
|
sufHeight = 0,
|
||||||
treeNode = [],
|
treeNode = [],
|
||||||
treeChildren = props.children; //最终渲染在 Tree 标签中的子节点
|
treeChildren = props.children; //最终渲染在 Tree 标签中的子节点
|
||||||
|
// console.log(
|
||||||
|
// "**startIndex**" + startIndex,
|
||||||
|
// "**endIndex**" + endIndex
|
||||||
|
// );
|
||||||
|
|
||||||
if (lazyLoad) {
|
if (lazyLoad) {
|
||||||
preHeight = this.getSumHeight(0, startIndex);
|
preHeight = this.getSumHeight(0, startIndex);
|
||||||
|
@ -35435,7 +35440,10 @@
|
||||||
isLeaf: 'isLeaf'
|
isLeaf: 'isLeaf'
|
||||||
};
|
};
|
||||||
var treeData = (0, _util.convertListToTree)(treeList, attr, _this7.flatTreeKeysMap);
|
var treeData = (0, _util.convertListToTree)(treeList, attr, _this7.flatTreeKeysMap);
|
||||||
|
// console.log(
|
||||||
|
// "**startIndex**" + startIndex,
|
||||||
|
// "**endIndex**" + endIndex
|
||||||
|
// );
|
||||||
_this7.startIndex = typeof startIndex !== "undefined" ? startIndex : _this7.startIndex;
|
_this7.startIndex = typeof startIndex !== "undefined" ? startIndex : _this7.startIndex;
|
||||||
_this7.endIndex = typeof endIndex !== "undefined" ? endIndex : _this7.endIndex;
|
_this7.endIndex = typeof endIndex !== "undefined" ? endIndex : _this7.endIndex;
|
||||||
|
|
||||||
|
@ -35510,6 +35518,9 @@
|
||||||
|
|
||||||
this.getSumHeight = function (start, end) {
|
this.getSumHeight = function (start, end) {
|
||||||
var sumHeight = 0;
|
var sumHeight = 0;
|
||||||
|
if (start > end) {
|
||||||
|
return sumHeight;
|
||||||
|
}
|
||||||
var span = Math.abs(end - start);
|
var span = Math.abs(end - start);
|
||||||
if (span) {
|
if (span) {
|
||||||
sumHeight = span * _config2['default'].defaultHeight;
|
sumHeight = span * _config2['default'].defaultHeight;
|
||||||
|
@ -36572,10 +36583,12 @@
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
var tree = [];
|
var tree = []; //存储所有一级节点
|
||||||
var resData = treeData,
|
var resData = treeData,
|
||||||
resKeysMap = {},
|
//resData 存储截取的节点 + 父节点(除一级节点外)
|
||||||
treeKeysMap = {};
|
resKeysMap = {},
|
||||||
|
//resData 的Map映射
|
||||||
|
treeKeysMap = {}; //tree 的Map映射
|
||||||
resData.map(function (element) {
|
resData.map(function (element) {
|
||||||
var key = attr.id;
|
var key = attr.id;
|
||||||
resKeysMap[element[key]] = element;
|
resKeysMap[element[key]] = element;
|
||||||
|
@ -36584,32 +36597,34 @@
|
||||||
var findParentNode = function findParentNode(node) {
|
var findParentNode = function findParentNode(node) {
|
||||||
var parentKey = node[attr.parendId];
|
var parentKey = node[attr.parendId];
|
||||||
if (parentKey !== attr.rootId) {
|
if (parentKey !== attr.rootId) {
|
||||||
|
//如果不是根节点,则继续递归
|
||||||
var item = flatTreeKeysMap[parentKey];
|
var item = flatTreeKeysMap[parentKey];
|
||||||
|
// 用 resKeysMap 判断,避免重复计算某节点的父节点
|
||||||
if (resKeysMap.hasOwnProperty(item[attr.id])) return;
|
if (resKeysMap.hasOwnProperty(item[attr.id])) return;
|
||||||
resData.push(item);
|
resData.push(item);
|
||||||
resKeysMap[item[attr.id]] = item;
|
resKeysMap[item[attr.id]] = item;
|
||||||
findParentNode(item);
|
findParentNode(item);
|
||||||
} else {
|
} else {
|
||||||
|
// 用 treeKeysMap 判断,避免重复累加
|
||||||
if (!treeKeysMap.hasOwnProperty(node[attr.id])) {
|
if (!treeKeysMap.hasOwnProperty(node[attr.id])) {
|
||||||
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']);
|
||||||
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)));
|
||||||
treeKeysMap[key] = node;
|
treeKeysMap[key] = node;
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// 遍历 resData ,找到所有的一级节点
|
||||||
for (var i = 0; i < resData.length; i++) {
|
for (var i = 0; i < resData.length; i++) {
|
||||||
var item = resData[i];
|
var item = resData[i];
|
||||||
if (item[attr.parendId] === attr.rootId) {
|
if (item[attr.parendId] === attr.rootId) {
|
||||||
|
@ -36629,9 +36644,8 @@
|
||||||
treeKeysMap[key] = item;
|
treeKeysMap[key] = item;
|
||||||
resData.splice(i, 1);
|
resData.splice(i, 1);
|
||||||
i--;
|
i--;
|
||||||
} else {
|
} else {//递归查找根节点信息
|
||||||
//找到根节点信息
|
// findParentNode(item);
|
||||||
findParentNode(item);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log('tree',tree);
|
// console.log('tree',tree);
|
||||||
|
@ -36862,6 +36876,7 @@
|
||||||
// "**endIndex**" + endIndex
|
// "**endIndex**" + endIndex
|
||||||
// );
|
// );
|
||||||
newTreeList = _this.treeList.slice(startIndex, endIndex);
|
newTreeList = _this.treeList.slice(startIndex, endIndex);
|
||||||
|
// console.log(JSON.stringify(newTreeList))
|
||||||
_this.props.handleTreeListChange && _this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
_this.props.handleTreeListChange && _this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "bee-tree",
|
"name": "bee-tree",
|
||||||
"version": "2.1.1",
|
"version": "2.1.2-beta.1",
|
||||||
"description": "Tree ui component for react",
|
"description": "Tree ui component for react",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"react",
|
"react",
|
||||||
|
|
13
src/Tree.js
13
src/Tree.js
|
@ -57,6 +57,7 @@ class Tree extends React.Component {
|
||||||
//启用懒加载,把 Tree 结构拍平,为后续动态截取数据做准备
|
//启用懒加载,把 Tree 结构拍平,为后续动态截取数据做准备
|
||||||
if(lazyLoad) {
|
if(lazyLoad) {
|
||||||
let flatTreeData = this.deepTraversal(treeData);
|
let flatTreeData = this.deepTraversal(treeData);
|
||||||
|
// console.log(JSON.stringify(flatTreeData))
|
||||||
flatTreeData.forEach((element) => {
|
flatTreeData.forEach((element) => {
|
||||||
if(sliceTreeList.length >= this.loadCount) return;
|
if(sliceTreeList.length >= this.loadCount) return;
|
||||||
sliceTreeList.push(element);
|
sliceTreeList.push(element);
|
||||||
|
@ -797,7 +798,10 @@ onExpand(treeNode,keyType) {
|
||||||
isLeaf: 'isLeaf'
|
isLeaf: 'isLeaf'
|
||||||
};
|
};
|
||||||
let treeData = convertListToTree(treeList, attr, this.flatTreeKeysMap);
|
let treeData = convertListToTree(treeList, attr, this.flatTreeKeysMap);
|
||||||
|
// console.log(
|
||||||
|
// "**startIndex**" + startIndex,
|
||||||
|
// "**endIndex**" + endIndex
|
||||||
|
// );
|
||||||
this.startIndex = typeof(startIndex) !== "undefined" ? startIndex : this.startIndex;
|
this.startIndex = typeof(startIndex) !== "undefined" ? startIndex : this.startIndex;
|
||||||
this.endIndex = typeof(endIndex) !== "undefined" ? endIndex : this.endIndex;
|
this.endIndex = typeof(endIndex) !== "undefined" ? endIndex : this.endIndex;
|
||||||
|
|
||||||
|
@ -877,6 +881,9 @@ onExpand(treeNode,keyType) {
|
||||||
*/
|
*/
|
||||||
getSumHeight = (start, end) => {
|
getSumHeight = (start, end) => {
|
||||||
let sumHeight = 0;
|
let sumHeight = 0;
|
||||||
|
if(start > end) {
|
||||||
|
return sumHeight;
|
||||||
|
}
|
||||||
let span = Math.abs(end - start);
|
let span = Math.abs(end - start);
|
||||||
if(span) {
|
if(span) {
|
||||||
sumHeight = span * CONFIG.defaultHeight;
|
sumHeight = span * CONFIG.defaultHeight;
|
||||||
|
@ -977,6 +984,10 @@ onExpand(treeNode,keyType) {
|
||||||
sufHeight = 0, //后置占位高度
|
sufHeight = 0, //后置占位高度
|
||||||
treeNode = [], //根据传入的 treeData 生成的 treeNode 节点数组
|
treeNode = [], //根据传入的 treeData 生成的 treeNode 节点数组
|
||||||
treeChildren = props.children; //最终渲染在 Tree 标签中的子节点
|
treeChildren = props.children; //最终渲染在 Tree 标签中的子节点
|
||||||
|
// console.log(
|
||||||
|
// "**startIndex**" + startIndex,
|
||||||
|
// "**endIndex**" + endIndex
|
||||||
|
// );
|
||||||
if(lazyLoad){
|
if(lazyLoad){
|
||||||
preHeight = this.getSumHeight(0, startIndex);
|
preHeight = this.getSumHeight(0, startIndex);
|
||||||
sufHeight = this.getSumHeight(endIndex, flatTreeData.length);
|
sufHeight = this.getSumHeight(endIndex, flatTreeData.length);
|
||||||
|
|
|
@ -254,6 +254,7 @@ export default class InfiniteScroll extends Component {
|
||||||
// "**endIndex**" + endIndex
|
// "**endIndex**" + endIndex
|
||||||
// );
|
// );
|
||||||
newTreeList = this.treeList.slice(startIndex,endIndex);
|
newTreeList = this.treeList.slice(startIndex,endIndex);
|
||||||
|
// console.log(JSON.stringify(newTreeList))
|
||||||
this.props.handleTreeListChange && this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
this.props.handleTreeListChange && this.props.handleTreeListChange(newTreeList, startIndex, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/util.js
17
src/util.js
|
@ -337,10 +337,10 @@ export function warnOnlyTreeNode() {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
export function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
export function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
let tree = [];
|
let tree = []; //存储所有一级节点
|
||||||
let resData = treeData,
|
let resData = treeData, //resData 存储截取的节点 + 父节点(除一级节点外)
|
||||||
resKeysMap = {},
|
resKeysMap = {}, //resData 的Map映射
|
||||||
treeKeysMap = {};
|
treeKeysMap = {}; //tree 的Map映射
|
||||||
resData.map((element) => {
|
resData.map((element) => {
|
||||||
let key = attr.id;
|
let key = attr.id;
|
||||||
resKeysMap[element[key]] = element;
|
resKeysMap[element[key]] = element;
|
||||||
|
@ -358,8 +358,8 @@ 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;
|
||||||
obj = {
|
let obj = {
|
||||||
key,
|
key,
|
||||||
title,
|
title,
|
||||||
isLeaf,
|
isLeaf,
|
||||||
|
@ -367,11 +367,10 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
}
|
}
|
||||||
tree.push(Object.assign(obj, {...otherProps}));
|
tree.push(Object.assign(obj, {...otherProps}));
|
||||||
treeKeysMap[key] = node;
|
treeKeysMap[key] = node;
|
||||||
return node;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 遍历 resData ,找到所有的一级节点
|
||||||
for (let i = 0; i < resData.length; i++) {
|
for (let i = 0; i < resData.length; i++) {
|
||||||
let item = resData[i];
|
let item = resData[i];
|
||||||
if (item[attr.parendId] === attr.rootId) { //如果是根节点,就存放进 tree 对象中
|
if (item[attr.parendId] === attr.rootId) { //如果是根节点,就存放进 tree 对象中
|
||||||
|
@ -387,7 +386,7 @@ export function convertListToTree(treeData, attr, flatTreeKeysMap) {
|
||||||
resData.splice(i, 1);
|
resData.splice(i, 1);
|
||||||
i--;
|
i--;
|
||||||
}else { //递归查找根节点信息
|
}else { //递归查找根节点信息
|
||||||
findParentNode(item);
|
// findParentNode(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// console.log('tree',tree);
|
// console.log('tree',tree);
|
||||||
|
|
Loading…
Reference in New Issue