mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-02-05 00:49:49 +08:00
【优化】优化新版treeTable下【菜单管理】使用简单数据模式可能导致数据混乱的问题,改为后台进行递归后返回数据到前端展示树。
This commit is contained in:
75
CoreCms.Net.Utility/Helper/SysMenuHelper.cs
Normal file
75
CoreCms.Net.Utility/Helper/SysMenuHelper.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using CoreCms.Net.Model.Entities;
|
||||||
|
using CoreCms.Net.Model.ViewModels.UI;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CoreCms.Net.Utility.Helper
|
||||||
|
{
|
||||||
|
public static class SysMenuHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
#region 获取商品分类下来Dtree============================================================
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取导航下拉上级树
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Description("获取导航下拉上级树")]
|
||||||
|
public static DTree GetTree(List<SysMenu> categories, bool isHaveTop = true)
|
||||||
|
{
|
||||||
|
|
||||||
|
var model = new DTree();
|
||||||
|
model.status = new dtreeStatus() { code = 200, message = "操作成功" };
|
||||||
|
|
||||||
|
var list = GetMenus(categories, 0);
|
||||||
|
|
||||||
|
if (isHaveTop)
|
||||||
|
{
|
||||||
|
list.Insert(0, new dtreeChild()
|
||||||
|
{
|
||||||
|
id = "0",
|
||||||
|
last = true,
|
||||||
|
parentId = "0",
|
||||||
|
title = "无父级",
|
||||||
|
children = new List<dtreeChild>()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
model.data = list;
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 迭代方法
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="oldNavs"></param>
|
||||||
|
/// <param name="parentId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static List<dtreeChild> GetMenus(List<SysMenu> oldNavs, int parentId)
|
||||||
|
{
|
||||||
|
List<dtreeChild> childTree = new List<dtreeChild>();
|
||||||
|
var model = oldNavs.Where(p => p.parentId == parentId).ToList();
|
||||||
|
foreach (var item in model)
|
||||||
|
{
|
||||||
|
var parentTree = new dtreeChild();
|
||||||
|
parentTree.id = item.id.ToString();
|
||||||
|
parentTree.title = item.menuName;
|
||||||
|
parentTree.parentId = item.parentId.ToString();
|
||||||
|
parentTree.last = !oldNavs.Exists(p => p.parentId == item.id);
|
||||||
|
parentTree.isParent = !parentTree.last;
|
||||||
|
parentTree.otherData = item;
|
||||||
|
|
||||||
|
childTree.Add(parentTree);
|
||||||
|
parentTree.children = GetMenus(oldNavs, item.id);
|
||||||
|
}
|
||||||
|
return childTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -67,35 +67,11 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
|||||||
public async Task<AdminUiCallBack> GetPageList()
|
public async Task<AdminUiCallBack> GetPageList()
|
||||||
{
|
{
|
||||||
var jm = new AdminUiCallBack();
|
var jm = new AdminUiCallBack();
|
||||||
var where = PredicateBuilder.True<SysMenu>();
|
|
||||||
where = where.And(p => p.deleted == false);
|
|
||||||
//查询筛选
|
|
||||||
|
|
||||||
////菜单名称 nvarchar
|
|
||||||
//var menuName = Request.Form["menuName"].FirstOrDefault();
|
|
||||||
//if (!string.IsNullOrEmpty(menuName))
|
|
||||||
//{
|
|
||||||
// where = where.And(p => p.menuName.Contains(menuName));
|
|
||||||
//}
|
|
||||||
|
|
||||||
////菜单组件地址 nvarchar
|
|
||||||
//var component = Request.Form["component"].FirstOrDefault();
|
|
||||||
//if (!string.IsNullOrEmpty(component))
|
|
||||||
//{
|
|
||||||
// where = where.And(p => p.component.Contains(component));
|
|
||||||
//}
|
|
||||||
|
|
||||||
////权限标识 nvarchar
|
|
||||||
//var authority = Request.Form["authority"].FirstOrDefault();
|
|
||||||
//if (!string.IsNullOrEmpty(authority))
|
|
||||||
//{
|
|
||||||
// where = where.And(p => p.authority.Contains(authority));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//获取数据
|
//获取数据
|
||||||
var list = await _sysMenuServices.QueryListByClauseAsync(where, p => p.sortNumber, OrderByType.Asc);
|
var list = await _sysMenuServices.QueryListByClauseAsync(p => p.deleted == false, p => p.sortNumber, OrderByType.Asc);
|
||||||
//返回数据
|
//返回数据
|
||||||
jm.data = list;
|
jm.data = SysMenuHelper.GetTree(list, false).data;
|
||||||
jm.code = 0;
|
jm.code = 0;
|
||||||
jm.count = list.Count;
|
jm.count = list.Count;
|
||||||
jm.msg = "数据调用成功!";
|
jm.msg = "数据调用成功!";
|
||||||
@@ -260,7 +236,7 @@ namespace CoreCms.Net.Web.Admin.Controllers
|
|||||||
|
|
||||||
var bl = await _sysMenuServices.InsertAsync(list, true) > 0;
|
var bl = await _sysMenuServices.InsertAsync(list, true) > 0;
|
||||||
jm.code = bl ? 0 : 1;
|
jm.code = bl ? 0 : 1;
|
||||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
jm.msg = bl ? "数据导入成功" : "数据导入失败";
|
||||||
|
|
||||||
return jm;
|
return jm;
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@
|
|||||||
|
|
||||||
var list = [];
|
var list = [];
|
||||||
let item = {
|
let item = {
|
||||||
menuName: "无上级",
|
title: "无上级",
|
||||||
id: 0
|
id: 0
|
||||||
}
|
}
|
||||||
list.push(item);
|
list.push(item);
|
||||||
@@ -153,7 +153,7 @@
|
|||||||
model: { label: { type: 'text' } },
|
model: { label: { type: 'text' } },
|
||||||
name: 'parentId',
|
name: 'parentId',
|
||||||
prop: {
|
prop: {
|
||||||
name: 'menuName',
|
name: 'title',
|
||||||
value: 'id'
|
value: 'id'
|
||||||
},
|
},
|
||||||
radio: true,
|
radio: true,
|
||||||
|
|||||||
@@ -134,7 +134,7 @@
|
|||||||
|
|
||||||
var list = [];
|
var list = [];
|
||||||
let item = {
|
let item = {
|
||||||
menuName: "无上级",
|
title: "无上级",
|
||||||
id: 0
|
id: 0
|
||||||
}
|
}
|
||||||
list.push(item);
|
list.push(item);
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
model: { label: { type: 'text' } },
|
model: { label: { type: 'text' } },
|
||||||
name: 'parentId',
|
name: 'parentId',
|
||||||
prop: {
|
prop: {
|
||||||
name: 'menuName',
|
name: 'title',
|
||||||
value: 'id'
|
value: 'id'
|
||||||
},
|
},
|
||||||
radio: true,
|
radio: true,
|
||||||
|
|||||||
@@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<script type="text/html" id="LAY-app-SysMenu-tableBox-bar">
|
<script type="text/html" id="LAY-app-SysMenu-tableBox-bar">
|
||||||
|
|
||||||
{{# if(d.path != '' && d.path != null && d.menuType===0){ }}
|
{{# if(d.otherData.path != '' && d.otherData.path != null && d.otherData.menuType===0){ }}
|
||||||
<a class="layui-btn layui-btn-xs" lay-event="importButton">导入按钮</a>
|
<a class="layui-btn layui-btn-xs" lay-event="importButton">导入按钮</a>
|
||||||
{{# } }}
|
{{# } }}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@
|
|||||||
<div class="dropdown-anchor"></div>
|
<div class="dropdown-anchor"></div>
|
||||||
<div class="dropdown-popconfirm-title">
|
<div class="dropdown-popconfirm-title">
|
||||||
<i class="layui-icon layui-icon-help"></i>
|
<i class="layui-icon layui-icon-help"></i>
|
||||||
确定要删除【{{d.menuName}}】吗?
|
确定要删除【{{d.otherData.menuName}}】吗?
|
||||||
</div>
|
</div>
|
||||||
<div class="dropdown-popconfirm-btn">
|
<div class="dropdown-popconfirm-btn">
|
||||||
<a class="layui-btn layui-btn-primary cursor" btn-cancel>取消</a>
|
<a class="layui-btn layui-btn-primary cursor" btn-cancel>取消</a>
|
||||||
@@ -90,44 +90,40 @@
|
|||||||
indent:25
|
indent:25
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
isSimpleData: true,
|
isSimpleData: false,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
height: 'full-127',//无面包屑127,搜索框189,1行62
|
height: 'full-127',//无面包屑127,搜索框189,1行62
|
||||||
toolbar: '#LAY-app-SysMenu-tableBox-toolbar',
|
toolbar: '#LAY-app-SysMenu-tableBox-toolbar',
|
||||||
cols: [[
|
cols: [[
|
||||||
{field: 'id', title: '序列', width: 60},
|
{field: 'id', title: '序列', width: 60},
|
||||||
{field: 'menuName', title: '菜单名称', minWidth: 110},
|
{ field: 'menuName', title: '菜单名称', minWidth: 110, templet: function (d) { return d.otherData.menuName } },
|
||||||
{
|
{
|
||||||
title: '图标', templet: '<p><i class="layui-icon {{d.menuIcon}}"></i></p>',
|
title: '图标', templet: '<p><i class="layui-icon {{d.otherData.menuIcon}}"></i></p>',
|
||||||
align: 'center', width: 60, minWidth: 60
|
align: 'center', width: 60, minWidth: 60
|
||||||
},
|
},
|
||||||
{field: 'path', title: '菜单Url'},
|
{ field: 'path', title: '菜单Url', templet: function (d) { return d.otherData.path == null || d.otherData.path == '' ? '' : d.otherData.path } },
|
||||||
{field: 'identificationCode', title: '文件夹标识'},
|
{ field: 'identificationCode', title: '文件夹标识', templet: function (d) { return d.otherData.identificationCode } },
|
||||||
{field: 'component', title: 'API请求地址'},
|
{ field: 'component', title: 'API请求地址', templet: function (d) { return d.otherData.component } },
|
||||||
{field: 'authority', title: '权限标识'},
|
{ field: 'authority', title: '权限标识', templet: function (d) { return d.otherData.authority } },
|
||||||
{
|
{
|
||||||
field: 'sortNumber', title: '排序', align: 'center',
|
field: 'sortNumber', title: '排序', align: 'center', width: 60, minWidth: 60, templet: function (d) { return d.otherData.sortNumber }
|
||||||
width: 60, minWidth: 60
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '隐藏', templet: function (d) {
|
title: '隐藏', templet: function (d) {
|
||||||
return d.hide ? '<span class="text-danger">隐藏</span>' : '显示';
|
return d.otherData.hide ? '<span class="text-danger">隐藏</span>' : '显示';
|
||||||
}, align: 'center', width: 60, minWidth: 60
|
}, align: 'center', width: 60, minWidth: 60
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '类型', templet: function (d) {
|
title: '类型', templet: function (d) {
|
||||||
var strs = ['<span class="layui-badge layui-badge-green">菜单</span>', '<span class="layui-badge layui-badge-gray">按钮</span>'];
|
var strs = ['<span class="layui-badge layui-badge-green">菜单</span>', '<span class="layui-badge layui-badge-gray">按钮</span>'];
|
||||||
return strs[d.menuType];
|
return strs[d.otherData.menuType];
|
||||||
}, align: 'center', width: 70, minWidth: 70
|
}, align: 'center', width: 70, minWidth: 70
|
||||||
},
|
},
|
||||||
//{field: 'createTime', title: '创建时间'},
|
//{field: 'createTime', title: '创建时间'},
|
||||||
{title: '操作', toolbar: '#LAY-app-SysMenu-tableBox-bar', align: 'center', width: 180}
|
{title: '操作', toolbar: '#LAY-app-SysMenu-tableBox-bar', align: 'center', width: 180}
|
||||||
]],
|
]],
|
||||||
initSort: {
|
|
||||||
field: 'sortNumber',
|
|
||||||
type: 'asc'
|
|
||||||
},
|
|
||||||
//autoSort: false,
|
//autoSort: false,
|
||||||
page: false
|
page: false
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user