Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
sts网站
Commits
6810243a
Commit
6810243a
authored
Apr 09, 2021
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复树表数据显示不全&加载慢问题
parent
b56b8846
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
20 deletions
+43
-20
ruoyi.js
ruoyi-ui/src/utils/ruoyi.js
+43
-20
No files found.
ruoyi-ui/src/utils/ruoyi.js
View file @
6810243a
...
...
@@ -58,7 +58,7 @@ export function addDateRange(params, dateRange, propName) {
var
search
=
params
;
search
.
params
=
{};
if
(
null
!=
dateRange
&&
''
!=
dateRange
)
{
if
(
typeof
(
propName
)
===
"undefined"
)
{
if
(
typeof
(
propName
)
===
"undefined"
)
{
search
.
params
[
"beginTime"
]
=
dateRange
[
0
];
search
.
params
[
"endTime"
]
=
dateRange
[
1
];
}
else
{
...
...
@@ -129,24 +129,47 @@ export function praseStrEmpty(str) {
* @param {*} id id字段 默认 'id'
* @param {*} parentId 父节点字段 默认 'parentId'
* @param {*} children 孩子节点字段 默认 'children'
* @param {*} rootId 根Id 默认 0
*/
export
function
handleTree
(
data
,
id
,
parentId
,
children
,
rootId
)
{
id
=
id
||
'id'
parentId
=
parentId
||
'parentId'
children
=
children
||
'children'
rootId
=
rootId
||
Math
.
min
.
apply
(
Math
,
data
.
map
(
item
=>
{
return
item
[
parentId
]
}))
||
0
//对源数据深度克隆
const
cloneData
=
JSON
.
parse
(
JSON
.
stringify
(
data
))
//循环所有项
const
treeData
=
cloneData
.
filter
(
father
=>
{
let
branchArr
=
cloneData
.
filter
(
child
=>
{
//返回每一项的子级数组
return
father
[
id
]
===
child
[
parentId
]
});
branchArr
.
length
>
0
?
father
.
children
=
branchArr
:
''
;
//返回第一层
return
father
[
parentId
]
===
rootId
;
});
return
treeData
!=
''
?
treeData
:
data
;
export
function
handleTree
(
data
,
id
,
parentId
,
children
)
{
let
config
=
{
id
:
id
||
'id'
,
parentId
:
parentId
||
'parentId'
,
childrenList
:
children
||
'children'
};
var
childrenListMap
=
{};
var
nodeIds
=
{};
var
tree
=
[];
for
(
let
d
of
data
)
{
let
parentId
=
d
[
config
.
parentId
];
if
(
childrenListMap
[
parentId
]
==
null
)
{
childrenListMap
[
parentId
]
=
[];
}
nodeIds
[
d
[
config
.
id
]]
=
d
;
childrenListMap
[
parentId
].
push
(
d
);
}
for
(
let
d
of
data
)
{
let
parentId
=
d
[
config
.
parentId
];
if
(
nodeIds
[
parentId
]
==
null
)
{
tree
.
push
(
d
);
}
}
for
(
let
t
of
tree
)
{
adaptToChildrenList
(
t
);
}
function
adaptToChildrenList
(
o
)
{
if
(
childrenListMap
[
o
[
config
.
id
]]
!==
null
)
{
o
[
config
.
childrenList
]
=
childrenListMap
[
o
[
config
.
id
]];
}
if
(
o
[
config
.
childrenList
])
{
for
(
let
c
of
o
[
config
.
childrenList
])
{
adaptToChildrenList
(
c
);
}
}
}
return
tree
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment