function initTreeView() {
$("#jsTreeUnit").jstree({
plugins: ["wholerow"],
core: {
data: {
url: function (node) {
return node.id === "#" ? "${base}/platform/sys/role/tree" : "${base}/platform/sys/role/tree?pid=" + node.id
}
},
multiple: false
}
}).on("select_node.jstree", function (node, selected) {
var id = selected.selected;
$("#unitid").val(id);
$("#add").attr("href","${base}/platform/sys/role/add?unitid="+id);
$("#searchForm").find("input[type='text']").val("");
if (datatable) {
$(".cd-panel-content").find("input").val("");
datatable.ajax.reload();
} else {
initDatatable();
}
}).on("loaded.jstree", function (node, jstree) {
$(node.target).find("li:first div").addClass("jstree-wholerow-clicked");
});
}
@At
@Ok("json")
@RequiresPermissions("sys.manager.role")
public Object tree(@Param("pid") String pid) {
List<Sys_unit> list = unitService.query(Cnd.where("parentId", "=", Strings.sBlank(pid)).asc("path"));
List<Map<String, Object>> tree = new ArrayList<>();
Map<String, Object> obj = new HashMap<>();
if (Strings.isBlank(pid)) {
obj.put("id", "root");
obj.put("text", "系统角色");
obj.put("children", false);
tree.add(obj);
}
for (Sys_unit unit : list) {
obj = new HashMap<>();
obj.put("id", unit.getId());
obj.put("text", unit.getName());
obj.put("children", unit.isHasChildren());
tree.add(obj);
}
return tree;
}