Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zui
提交
41ef1d9a
Z
zui
项目概览
易企天创
/
zui
9 个月 前同步成功
通知
6
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
37
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
37
Issue
37
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
41ef1d9a
编写于
8月 11, 2023
作者:
C
catouse
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* tree: improve tree perf.
上级
ab070081
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
100 addition
and
90 deletion
+100
-90
src/js/tree.js
src/js/tree.js
+100
-90
未找到文件。
src/js/tree.js
浏览文件 @
41ef1d9a
...
...
@@ -12,15 +12,21 @@
var
name
=
'
zui.tree
'
;
// modal name
var
globalId
=
0
;
function
escape
(
unsafe
)
{
return
unsafe
.
replaceAll
(
'
&
'
,
'
&
'
).
replaceAll
(
'
<
'
,
'
<
'
).
replaceAll
(
'
>
'
,
'
>
'
).
replaceAll
(
'
"
'
,
'
"
'
).
replaceAll
(
"
'
"
,
'
'
'
);
}
// The tree modal class
var
Tree
=
function
(
element
,
options
)
{
this
.
name
=
name
;
this
.
$
=
$
(
element
);
this
.
$ulTmp
=
$
(
'
<ul/>
'
);
this
.
getOptions
(
options
);
this
.
_init
();
};
Tree
.
escape
=
escape
;
var
DETAULT_ACTIONS
=
{
sort
:
{
template
:
'
<a class="sort-handler" href="javascript:;"><i class="icon icon-move"></i></a>
'
...
...
@@ -86,55 +92,66 @@
itemConverter
:
null
,
// function(item) {}
};
Tree
.
prototype
.
add
=
function
(
rootEle
,
items
,
expand
,
disabledAnimate
,
notStore
)
{
var
$e
=
$
(
rootEle
),
$ul
,
options
=
this
.
options
;
if
(
$e
.
is
(
'
li
'
))
{
$ul
=
$e
.
children
(
'
ul
'
);
if
(
!
$ul
.
length
)
{
$ul
=
$
(
'
<ul/>
'
);
$e
.
append
(
$ul
);
this
.
_initList
(
$ul
,
$e
);
Tree
.
prototype
.
add
=
function
(
ele
,
items
,
parent
,
$ul
,
$parent
,
isRoot
)
{
var
gid
=
$
.
guid
++
;
var
that
=
this
;
var
$e
=
$
(
ele
),
options
=
that
.
options
,
needAppendUl
;
if
(
!
$ul
)
{
if
(
$e
.
prop
(
'
tagName
'
)
===
'
UL
'
)
{
$ul
=
$e
;
}
else
{
$ul
=
$e
.
children
(
'
ul
'
);
if
(
!
$ul
.
length
)
{
needAppendUl
=
true
;
$ul
=
that
.
$ulTmp
.
clone
();
}
$parent
=
$e
;
}
}
else
{
$ul
=
$e
;
}
if
(
!
$parent
&&
!
isRoot
)
{
$parent
=
$ul
.
parent
(
'
li
'
);
}
if
(
$ul
)
{
var
that
=
this
;
if
(
!
Array
.
isArray
(
items
))
{
items
=
[
items
];
if
(
!
Array
.
isArray
(
items
))
{
items
=
[
items
];
}
var
itemConverter
=
options
.
itemConverter
;
var
itemCreator
=
options
.
itemCreator
;
var
itemRender
=
options
.
itemRender
;
var
itemWrapper
=
options
.
itemWrapper
;
var
$itemWrapper
=
itemWrapper
?
$
(
itemWrapper
===
true
?
'
<div class="tree-item-wrapper"/>
'
:
itemWrapper
)
:
null
;
items
.
forEach
(
function
(
item
,
idx
)
{
if
(
itemConverter
)
item
=
itemConverter
(
item
);
if
(
item
.
id
===
undefined
)
item
.
id
=
(
parent
?
(
parent
.
id
+
'
_
'
)
:
''
)
+
idx
;
var
$li
=
$
(
'
<li/>
'
,
{
'
data-id
'
:
item
.
id
}).
data
(
item
);
var
$wrapper
=
$itemWrapper
?
$itemWrapper
.
clone
().
appendTo
(
$li
)
:
$li
;
var
html
=
''
;
if
(
item
.
html
)
{
html
=
item
.
html
;
}
else
if
(
itemCreator
)
{
var
itemContent
=
itemCreator
(
$li
,
item
);
if
(
typeof
itemContent
===
'
string
'
)
html
=
itemContent
;
}
else
if
(
item
.
url
)
{
html
=
'
<a href="
'
+
item
.
url
+
'
">
'
+
escape
(
item
.
title
||
item
.
name
)
+
'
</a>
'
;
}
else
{
html
=
'
<span>
'
+
escape
(
item
.
title
||
item
.
name
)
+
'
</span>
'
;
}
var
itemConverter
=
options
.
itemConverter
;
var
itemCreator
=
options
.
itemCreator
;
var
itemRender
=
options
.
itemRender
;
$
.
each
(
items
,
function
(
idx
,
item
)
{
if
(
itemConverter
)
item
=
itemConverter
(
item
);
var
$li
=
$
(
'
<li/>
'
).
data
(
item
).
appendTo
(
$ul
);
if
(
item
.
id
!==
undefined
)
$li
.
attr
(
'
data-id
'
,
item
.
id
);
var
$wrapper
=
options
.
itemWrapper
?
$
(
options
.
itemWrapper
===
true
?
'
<div class="tree-item-wrapper"/>
'
:
options
.
itemWrapper
).
appendTo
(
$li
)
:
$li
;
if
(
item
.
html
)
{
$wrapper
.
html
(
item
.
html
)
}
else
if
(
itemCreator
)
{
var
itemContent
=
itemCreator
(
$li
,
item
);
if
(
itemContent
!==
true
&&
itemContent
!==
false
)
$wrapper
.
html
(
itemContent
);
}
else
if
(
item
.
url
)
{
$wrapper
.
append
(
$
(
'
<a/>
'
,
{
href
:
item
.
url
}).
text
(
item
.
title
||
item
.
name
));
}
else
{
$wrapper
.
append
(
$
(
'
<span/>
'
).
text
(
item
.
title
||
item
.
name
));
}
that
.
_initItem
(
$li
,
item
.
idx
||
idx
,
$ul
,
item
);
if
(
item
.
children
&&
item
.
children
.
length
)
{
that
.
add
(
$li
,
item
.
children
);
}
if
(
itemRender
)
{
itemRender
(
$li
,
item
);
}
});
this
.
_initList
(
$ul
);
if
(
expand
&&
!
$ul
.
hasClass
(
'
tree
'
))
{
that
.
expand
(
$ul
.
parent
(
'
li
'
),
disabledAnimate
,
notStore
);
$wrapper
.
html
(
html
);
that
.
_initItem
(
$li
,
$ul
,
item
,
null
,
true
);
if
(
item
.
children
&&
item
.
children
.
length
)
{
var
$childUl
=
that
.
$ulTmp
.
clone
().
appendTo
(
$li
);
that
.
add
(
$li
,
item
.
children
,
item
,
$childUl
,
$li
);
}
if
(
itemRender
)
{
itemRender
(
$li
,
item
);
}
if
(
item
.
open
)
$li
.
addClass
(
'
open in
'
);
$ul
.
append
(
$li
);
});
if
(
needAppendUl
)
{
$e
.
append
(
$ul
);
}
this
.
_initList
(
$ul
,
$parent
,
parent
,
isRoot
,
true
);
};
Tree
.
prototype
.
reload
=
function
(
data
)
{
...
...
@@ -142,11 +159,8 @@
if
(
data
)
{
that
.
$
.
empty
();
that
.
add
(
that
.
$
,
data
);
}
if
(
that
.
isPreserve
)
{
that
.
add
(
that
.
$
,
data
,
null
,
that
.
$
,
null
,
true
);
}
else
if
(
that
.
isPreserve
)
{
if
(
that
.
store
.
time
)
{
that
.
$
.
find
(
'
li:not(.tree-action-item)
'
).
each
(
function
()
{
var
$li
=
$
(
this
);
...
...
@@ -156,28 +170,30 @@
}
};
Tree
.
prototype
.
_initList
=
function
(
$list
,
$parentItem
,
idx
,
data
)
{
Tree
.
prototype
.
_initList
=
function
(
$list
,
$parentItem
,
data
,
isRoot
,
skipCheckExists
)
{
var
that
=
this
;
if
(
!
$list
.
hasClass
(
'
tree
'
))
{
if
(
isRoot
===
undefined
)
isRoot
=
$list
.
hasClass
(
'
tree
'
);
if
(
!
isRoot
)
{
$parentItem
=
(
$parentItem
||
$list
.
closest
(
'
li
'
)).
addClass
(
'
has-list
'
);
if
(
!
$parentItem
.
find
(
'
.list-toggle
'
).
length
)
{
$parentItem
.
prepend
(
th
is
.
options
.
toggleTemplate
);
if
(
skipCheckExists
||
!
$parentItem
.
find
(
'
.list-toggle
'
).
length
)
{
$parentItem
.
prepend
(
th
at
.
options
.
toggleTemplate
);
}
idx
=
idx
||
$parentItem
.
data
(
'
idx
'
);
}
else
{
idx
=
0
;
$parentItem
=
null
;
}
$list
.
removeClass
(
'
has-active-item
'
);
var
$children
=
$list
.
attr
(
'
data-idx
'
,
idx
||
0
).
children
(
'
li:not(.tree-action-item)
'
).
each
(
function
(
index
)
{
that
.
_initItem
(
$
(
this
),
index
+
1
,
$list
);
});
if
(
$children
.
length
===
1
&&
!
$children
.
find
(
'
ul
'
).
length
)
{
$children
.
addClass
(
'
tree-single-item
'
);
data
=
data
||
(
$parentItem
?
$parentItem
.
data
()
:
{
id
:
0
});
if
(
!
skipCheckExists
)
{
$list
.
removeClass
(
'
has-active-item
'
);
var
$children
=
$list
.
attr
(
'
data-id
'
,
data
.
id
).
children
(
'
li:not(.tree-action-item)
'
).
each
(
function
(
index
)
{
var
$item
=
$
(
this
);
var
item
=
$item
.
data
();
if
(
item
.
id
===
undefined
)
item
.
id
=
data
.
id
+
'
_
'
+
index
;
that
.
_initItem
(
$item
,
$list
,
item
);
});
if
(
$children
.
length
===
1
&&
!
$children
.
find
(
'
ul
'
).
length
)
{
$children
.
addClass
(
'
tree-single-item
'
);
}
}
data
=
data
||
(
$parentItem
?
$parentItem
.
data
()
:
null
);
var
actions
=
formatActions
(
data
?
data
.
actions
:
null
,
this
.
actions
);
var
actions
=
formatActions
(
data
?
data
.
actions
:
null
,
that
.
actions
);
if
(
actions
)
{
if
(
actions
.
add
&&
actions
.
add
.
templateInList
!==
false
)
{
var
$actionItem
=
$list
.
children
(
'
li.tree-action-item
'
);
...
...
@@ -198,43 +214,37 @@
},
actions
.
sort
.
options
,
$
.
isPlainObject
(
this
.
options
.
sortable
)
?
this
.
options
.
sortable
:
null
));
}
}
if
(
$parentItem
&&
(
$parentItem
.
hasClass
(
'
open
'
)
||
(
data
&&
data
.
open
)))
{
if
(
!
skipCheckExists
&&
$parentItem
&&
(
$parentItem
.
hasClass
(
'
open
'
)
||
(
data
&&
data
.
open
)))
{
$parentItem
.
addClass
(
'
open in
'
);
}
};
Tree
.
prototype
.
_initItem
=
function
(
$item
,
idx
,
$parentList
,
data
)
{
if
(
idx
===
undefined
)
{
var
$pre
=
$item
.
prev
(
'
li
'
);
idx
=
$pre
.
length
?
(
$pre
.
data
(
'
idx
'
)
+
1
)
:
1
;
}
$parentList
=
$parentList
||
$item
.
closest
(
'
ul
'
);
$item
.
attr
(
'
data-idx
'
,
idx
).
removeClass
(
'
tree-single-item
'
);
if
(
!
$item
.
data
(
'
id
'
))
{
var
id
=
idx
;
if
(
!
$parentList
.
hasClass
(
'
tree
'
))
{
id
=
$parentList
.
parent
(
'
li
'
).
data
(
'
id
'
)
+
'
-
'
+
id
;
Tree
.
prototype
.
_initItem
=
function
(
$item
,
$parentUl
,
data
,
$childrenUl
,
skipCheckExists
)
{
var
that
=
this
;
data
=
data
||
$item
.
data
();
if
(
!
skipCheckExists
)
{
$parentUl
=
$parentUl
||
$item
.
closest
(
'
ul
'
);
$item
.
attr
(
'
data-id
'
,
data
.
id
).
removeClass
(
'
tree-single-item
'
);
if
(
$item
.
hasClass
(
'
active
'
))
{
$parentUl
.
parent
(
'
li
'
).
addClass
(
'
has-active-item
'
);
}
$item
.
attr
(
'
data-id
'
,
id
);
}
if
(
$item
.
hasClass
(
'
active
'
))
{
$parentList
.
parent
(
'
li
'
).
addClass
(
'
has-active-item
'
);
}
data
=
data
||
$item
.
data
();
var
actions
=
formatActions
(
data
.
actions
,
this
.
actions
);
var
actions
=
formatActions
(
data
.
actions
,
that
.
actions
);
if
(
actions
)
{
var
$actions
=
$item
.
find
(
'
.tree-actions
'
);
if
(
!
$actions
.
length
)
{
$actions
=
$
(
'
<div class="tree-actions"/>
'
).
appendTo
(
th
is
.
options
.
itemWrapper
?
$item
.
find
(
'
.tree-item-wrapper
'
)
:
$item
);
$actions
=
$
(
'
<div class="tree-actions"/>
'
).
appendTo
(
th
at
.
options
.
itemWrapper
?
$item
.
find
(
'
.tree-item-wrapper
'
)
:
$item
);
$
.
each
(
actions
,
function
(
actionName
,
action
)
{
if
(
action
)
$actions
.
append
(
createActionEle
(
action
,
actionName
));
});
}
}
var
$children
=
$item
.
children
(
'
ul
'
);
if
(
$children
.
length
)
{
this
.
_initList
(
$children
,
$item
,
idx
,
data
);
if
(
!
skipCheckExists
)
{
$childrenUl
=
$childrenUl
||
$item
.
children
(
'
ul
'
);
if
(
$childrenUl
.
length
)
{
that
.
_initList
(
$childrenUl
,
$item
,
data
,
false
,
skipCheckExists
);
}
}
};
...
...
@@ -245,10 +255,10 @@
this
.
$
.
addClass
(
'
tree
'
);
if
(
options
.
animate
)
this
.
$
.
addClass
(
'
tree-animate
'
);
this
.
_initList
(
this
.
$
);
this
.
_initList
(
this
.
$
,
null
,
null
,
true
);
var
initialState
=
options
.
initialState
;
var
isPreserveEnable
=
$
.
zui
&&
$
.
zui
.
store
&&
$
.
zui
.
store
.
enable
;
var
isPreserveEnable
=
options
.
preserve
!==
false
&&
$
.
zui
&&
$
.
zui
.
store
&&
$
.
zui
.
store
.
enable
;
if
(
isPreserveEnable
)
{
this
.
selector
=
name
+
'
::
'
+
(
options
.
name
||
''
)
+
'
#
'
+
(
this
.
$
.
attr
(
'
id
'
)
||
globalId
++
);
this
.
store
=
$
.
zui
.
store
[
options
.
name
?
'
get
'
:
'
pageGet
'
](
this
.
selector
,
{});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录