Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
h5
/
account
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b53ee7d5
authored
Aug 20, 2021
by
cwq0219
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
树默认选中
1 parent
ff2af6d4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
70 deletions
html/merchant/edit.html
html/role/add.html
js/gtree.js
js/helper.js
html/merchant/edit.html
View file @
b53ee7d
...
...
@@ -1341,6 +1341,7 @@
treeData
[
id
][
item
.
value
].
treeObj
=
tree
.
create
(
treedom
,
treeListData
,
{
checkedList
:
defaultList
})
helper
.
defaultChecked
(
treeData
[
id
][
item
.
value
].
treeObj
,
defaultList
)
}
}
}
...
...
html/role/add.html
View file @
b53ee7d
...
...
@@ -247,6 +247,7 @@
treeData
[
id
][
item
.
value
].
treeObj
.
checkAllNodes
(
true
)
}
else
{
treeData
[
id
][
item
.
value
].
treeObj
=
tree
.
create
(
treedom
,
treeListData
,
{
checkedList
:
defaultList
})
helper
.
defaultChecked
(
treeData
[
id
][
item
.
value
].
treeObj
,
defaultList
)
}
}
}
...
...
js/gtree.js
View file @
b53ee7d
...
...
@@ -23,32 +23,6 @@ layui.define(['ztree'], function (exports) {
$switchs
.
not
(
':eq(0)'
).
addClass
(
'op0'
)
}
}
if
(
gtree
.
opt
&&
gtree
.
opt
.
checkedList
)
{
var
p
=
gtree
.
opt
.
checkedList
if
(
p
.
indexOf
(
treeNode
.
id
)
!=
-
1
)
{
// treeNode.checked = true
// var i= setInterval(function(){
// if (inst) {
// inst.updateNode(treeNode)
// clearInterval(i)
// }
// },20)
// var time = setTimeout(function () {
// if (inst) {
// inst.updateNode(treeNode)
// clearTimeout(time)
// }
// }, 20)
// console.log(!treeNode.children)
// if (inst) {
// inst.updateNode(treeNode)
// }
//else if (!treeNode.children) {
// rootNoChildCheckedNode.push(treeNode)
// // console.log(rootNoChildCheckedNode, '==============')
// }
}
}
if
(
gtree
.
opt
&&
gtree
.
opt
.
chkDisabled
)
{
treeNode
.
chkDisabled
=
true
}
...
...
@@ -90,20 +64,6 @@ layui.define(['ztree'], function (exports) {
if
(
check
==
0
)
setting
.
check
.
enable
=
false
inst
=
tree
.
init
(
$treeDom
,
setting
,
nodes
)
inst
.
expandAll
(
true
)
setTimeout
(()
=>
{
if
(
opt
&&
opt
.
checkedList
)
{
var
nodesLevel1
=
inst
.
getNodes
()
var
checked
=
opt
.
checkedList
var
nodesAll
=
inst
.
transformToArray
(
nodesLevel1
)
$
.
each
(
nodesAll
,
function
(
index
,
node
)
{
if
(
checked
.
indexOf
(
node
.
id
)
!=
-
1
)
{
node
.
checked
=
true
inst
.
updateNode
(
node
)
}
})
}
},
20
);
// inst.refresh()
return
inst
}
}
...
...
js/helper.js
View file @
b53ee7d
...
...
@@ -42,45 +42,58 @@ layui.define(['store'], function (exports) {
function
debounce
(
fun
,
delay
)
{
return
function
(
args
)
{
//获取函数的作用域和变量
var
that
=
this
var
_args
=
args
//每次事件被触发,都会清除当前的timeer,然后重写设置超时调用
clearTimeout
(
fun
.
id
)
fun
.
id
=
setTimeout
(
function
()
{
fun
.
call
(
that
,
_args
)
},
delay
)
//获取函数的作用域和变量
var
that
=
this
var
_args
=
args
//每次事件被触发,都会清除当前的timeer,然后重写设置超时调用
clearTimeout
(
fun
.
id
)
fun
.
id
=
setTimeout
(
function
()
{
fun
.
call
(
that
,
_args
)
},
delay
)
}
}
//将后台返回数据中数值为空的字段全部替换为“-”
function
formateNullFieldData
(
initialData
)
{
const
isEmpty
=
function
(
val
)
{
if
(
!
String
(
val
)
||
String
(
val
)
===
'null'
)
{
return
'-'
;
}
return
val
;
}
//将后台返回数据中数值为空的字段全部替换为“-”
function
formateNullFieldData
(
initialData
)
{
const
isEmpty
=
function
(
val
)
{
if
(
!
String
(
val
)
||
String
(
val
)
===
'null'
)
{
return
'-'
;
}
if
(
initialData
instanceof
Array
)
{
initialData
.
forEach
(
function
(
val
,
key
,
array
)
{
array
[
key
]
=
formateNullFieldData
(
val
)
return
val
;
}
if
(
initialData
instanceof
Array
)
{
initialData
.
forEach
(
function
(
val
,
key
,
array
)
{
array
[
key
]
=
formateNullFieldData
(
val
)
})
}
else
if
(
initialData
instanceof
Object
)
{
for
(
let
pro
in
initialData
)
{
initialData
[
pro
]
=
formateNullFieldData
(
initialData
[
pro
])
}
}
else
{
//数据为基本类型时
initialData
=
isEmpty
(
initialData
)
})
}
else
if
(
initialData
instanceof
Object
)
{
for
(
let
pro
in
initialData
)
{
initialData
[
pro
]
=
formateNullFieldData
(
initialData
[
pro
])
}
return
initialData
;
}
else
{
//数据为基本类型时
initialData
=
isEmpty
(
initialData
)
}
return
initialData
;
}
function
defaultChecked
(
treeObj
,
checkedList
)
{
var
nodesLevel1
=
treeObj
.
getNodes
()
var
checked
=
checkedList
var
nodesAll
=
treeObj
.
transformToArray
(
nodesLevel1
)
for
(
var
i
=
0
;
i
<=
nodesAll
.
length
;
i
++
)
{
var
node
=
nodesAll
[
i
]
if
(
node
&&
checked
.
indexOf
(
node
.
id
)
!=
-
1
)
{
node
.
checked
=
true
treeObj
.
updateNode
(
node
)
}
}
}
exports
(
'helper'
,
{
clone
:
clone
,
store
:
layui
.
store
,
debounce
:
debounce
,
formateNullFieldData
:
formateNullFieldData
formateNullFieldData
:
formateNullFieldData
,
defaultChecked
:
defaultChecked
})
})
})
\ No newline at end of file
Write
Preview
Markdown
is supported
Attach a file
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 post a comment