//从ImanageService获取部门树 然后 SetJsonData(rej); /// <summary> /// 是否为部门树 /// </summary> /// <returns></returns> public JsTree IsOrgDept() { IEnumerable <OrgDept> powerDepts = _rbacService.GetDeptInfoAuthority(_applicationContext.CurrentRoleUid); //将List<dynamic>转换成List<TreeDataView> List <TreeDataView> treeList = new List <TreeDataView>(); foreach (var data in powerDepts) { treeList.Add(new TreeDataView() { Id = data.Fid, Text = data.DeptName, Pid = data.Pid, Data = new { Code = data.DeptCode, Ext1 = data.HasPartPower, Ext2 = "" }, Icon = "icon-folder ace-icon fa fa-folder orange" }); } List <TreeDataView> tree = new List <TreeDataView>(); string parentID = "0"; var pt = powerDepts.FirstOrDefault <OrgDept>(t => t.Pid == "0" || t.Pid.IsMissing() || t.Pid == "#" || t.Pid == "~"); if (_rootText.IsMissing()) { if (pt != null) { _rootText = pt.DeptName; parentID = pt.Fid; } else { _rootText = "无权限"; } } TreeDataView treeRoot = new TreeDataView() { Id = parentID, Text = _rootText, State = new NodeState { Opened = true }, Icon = "icon-folder purple ace-icon fa fa-sitemap", }; if (parentID == "0") { treeRoot.Data = new { Code = "", Ext1 = false, Ext2 = "" }; } else { treeRoot.Data = new { Code = pt.DeptCode, Ext1 = pt.HasPartPower, Ext2 = "" }; } TreeViewHelper.MakeTree(treeRoot.Children, treeList, treeRoot.Id); tree.Add(treeRoot); string rej = tree.ToJsonIgnoreNullValue(); //设置tree的json数据 SetJsonData(rej); return(this); }
private void LoadTreeData() { Guard.Against.Null(_treeModel, nameof(_treeModel)); Guard.Against.NullOrEmpty(_treeModel.TableName, nameof(_treeModel.TableName)); Guard.Against.NullOrEmpty(_treeModel.DisplayField, nameof(_treeModel.DisplayField)); if (_treeModel != null && !_treeModel.NodeIcon.IsMissing()) { _nodeIcon = _treeModel.NodeIcon; } if (_treeModel != null && !_treeModel.RootNodeIcon.IsMissing()) { _rootNodeIcon = _treeModel.RootNodeIcon; } if (_treeModel != null && !_treeModel.RootText.IsMissing()) { _rootText = _treeModel.RootText; } string sql = string.Format("select Fid as Id,{0} as Text,Pid,'{1}' as Icon,{2} as Code,{3} as Ext1,{4} as Ext2 from {5} ", _treeModel.DisplayField, _nodeIcon, _treeModel.CodeField, _treeModel.Ext1Field, _treeModel.Ext2Field, _treeModel.TableName); if (!_treeModel.InitCondition.IsMissing()) { sql += " where " + _treeModel.InitCondition; } if (_treeModel.SortBy.IsPresent()) { sql += " order by " + _treeModel.SortBy; } var dataList = _dbContext.Query(sql); //将List<dynamic>转换成List<TreeDataView> List <TreeDataView> treeList = new List <TreeDataView>(); foreach (var data in dataList) { treeList.Add(new TreeDataView() { Id = data.Id, Text = data.Text, Pid = data.Pid, Data = new { Code = data.Code, Ext1 = data.Ext1, Ext2 = data.Ext2 }, Icon = data.Icon }); } List <TreeDataView> tree = new List <TreeDataView>(); string parentID = "0"; if (_rootText.IsMissing()) { var pt = treeList.FirstOrDefault <TreeDataView>(t => t.Pid == "0" || t.Pid.IsMissing() || t.Pid == "#" || t.Pid == "~"); if (pt != null) { _rootText = pt.Text; parentID = pt.Id; } } TreeDataView treeRoot = new TreeDataView() { Id = parentID, Text = _rootText, State = new NodeState { Opened = true }, Icon = _rootNodeIcon, }; TreeViewHelper.MakeTree(treeRoot.Children, treeList, treeRoot.Id); tree.Add(treeRoot); string rej = tree.ToJsonIgnoreNullValue(); //设置tree的json数据 SetJsonData(rej); }