vue动态路由测试

This commit is contained in:
陈淳
2022-09-08 18:18:34 +08:00
parent 49330536c7
commit 23dc82f042
5 changed files with 65 additions and 15 deletions

View File

@@ -14,8 +14,8 @@ namespace Yi.Framework.Common.Helper
if (list != null && list.Count > 0)
{
IList<T> result = new List<T>();
long pid = list.Min(m => (m as ITreeModel<T>).parentId);
IList<T> t = list.Where(m => (m as ITreeModel<T>).parentId == pid).ToList();
long pid = list.Min(m => (m as ITreeModel<T>).ParentId);
IList<T> t = list.Where(m => (m as ITreeModel<T>).ParentId == pid).ToList();
foreach (T model in t)
{
if (action != null)
@@ -24,35 +24,35 @@ namespace Yi.Framework.Common.Helper
}
result.Add(model);
var item = (model as ITreeModel<T>);
IList<T> children = list.Where(m => (m as ITreeModel<T>).parentId == item.id).ToList();
IList<T> children = list.Where(m => (m as ITreeModel<T>).ParentId == item.Id).ToList();
if (children.Count > 0)
{
SetTreeChildren(list, children, model, action);
}
}
return result.OrderBy(m => (m as ITreeModel<T>).sort).ToList();
return result.OrderBy(m => (m as ITreeModel<T>).Sort).ToList();
}
return null;
}
private static void SetTreeChildren<T>(IList<T> list, IList<T> children, T model, Action<T> action = null)
{
var mm = (model as ITreeModel<T>);
mm.children = new List<T>();
mm.Children = new List<T>();
foreach (T item in children)
{
if (action != null)
{
action(item);
}
mm.children.Add(item);
mm.Children.Add(item);
var _item = (item as ITreeModel<T>);
IList<T> _children = list.Where(m => (m as ITreeModel<T>).parentId == _item.id).ToList();
IList<T> _children = list.Where(m => (m as ITreeModel<T>).ParentId == _item.Id).ToList();
if (_children.Count > 0)
{
SetTreeChildren(list, _children, item, action);
}
}
mm.children = mm.children.OrderBy(m => (m as ITreeModel<T>).sort).ToList();
mm.Children = mm.Children.OrderBy(m => (m as ITreeModel<T>).Sort).ToList();
}
}
}

View File

@@ -8,10 +8,10 @@ namespace Yi.Framework.Common.Models
{
public interface ITreeModel<T>
{
public int id { get; set; }
public int parentId { get; set; }
public int sort { get; set; }
public int Id { get; set; }
public int ParentId { get; set; }
public int Sort { get; set; }
public IList<T> children { get; set; }
public IList<T> Children { get; set; }
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Common.Models
{
public class VueRouterModel : ITreeModel<VueRouterModel>
{
public int Id { get; set; }
public int ParentId { get; set; }
public int Sort { get; set; }
public string Name { get; set; }
public string Path { get; set; }
public bool Hidden { get; set; }
public string Redirect { get; set; }
public string Component { get; set; }
public bool AlwaysShow { get; set; }
public Meta Meta { get; set; }
public IList<VueRouterModel> Children { get; set; }
}
public class Meta
{
public string Title { get; set; }
public string Icon { get; set; }
public string NoCache { get; set; }
public string link { get; set; }
}
}