mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-20 18:47:55 +08:00
优化模块管理
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.App
|
||||
@@ -39,5 +40,25 @@ namespace OpenAuth.App
|
||||
}
|
||||
|
||||
#endregion 用户/角色分配模块
|
||||
|
||||
|
||||
#region 菜单操作
|
||||
/// <summary>
|
||||
/// 删除指定的菜单
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
public void DelMenu(string[] ids)
|
||||
{
|
||||
UnitWork.Delete<ModuleElement>(u => ids.Contains(u.Id));
|
||||
}
|
||||
|
||||
public void AddMenu(ModuleElement model)
|
||||
{
|
||||
UnitWork.Add(model);
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -119,16 +119,11 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
public string LoadModule()
|
||||
{
|
||||
var orgs = AuthUtil.GetCurrentUser().Modules.MapToList<ModuleView>();
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
#region 添加编辑模块
|
||||
|
||||
//添加或修改模块
|
||||
//添加模块
|
||||
[HttpPost]
|
||||
[ValidateInput(false)]
|
||||
public string Add(Module model)
|
||||
{
|
||||
try
|
||||
@@ -143,8 +138,9 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
//添加或修改模块
|
||||
//修改模块
|
||||
[HttpPost]
|
||||
[ValidateInput(false)]
|
||||
public string Update(Module model)
|
||||
{
|
||||
try
|
||||
@@ -178,7 +174,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
#endregion 添加编辑模块
|
||||
|
||||
/// <summary>
|
||||
/// 加载模块的菜单
|
||||
/// 加载当前用户可访问模块的菜单
|
||||
/// </summary>
|
||||
/// <param name="moduleId">The module identifier.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
@@ -195,5 +191,41 @@ namespace OpenAuth.Mvc.Controllers
|
||||
};
|
||||
return JsonHelper.Instance.Serialize(data);
|
||||
}
|
||||
|
||||
//添加菜单
|
||||
[HttpPost]
|
||||
[ValidateInput(false)]
|
||||
public string AddMenu(ModuleElement model)
|
||||
{
|
||||
try
|
||||
{
|
||||
App.AddMenu(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = ex.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除菜单
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
public string DelMenu(params string[] ids)
|
||||
{
|
||||
try
|
||||
{
|
||||
App.DelMenu(ids);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
}
|
||||
}
|
@@ -21,6 +21,11 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return JsonHelper.Instance.Serialize(moduleTree);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// datatable结构的模块列表
|
||||
/// </summary>
|
||||
/// <param name="pId"></param>
|
||||
/// <returns></returns>
|
||||
public string GetModules(string pId)
|
||||
{
|
||||
var query = user.Modules;
|
||||
@@ -36,6 +41,15 @@ namespace OpenAuth.Mvc.Controllers
|
||||
return JsonHelper.Instance.Serialize(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 普通的List
|
||||
/// </summary>
|
||||
public string QueryModuleList()
|
||||
{
|
||||
var orgs = user.Modules.MapToList<ModuleView>();
|
||||
return JsonHelper.Instance.Serialize(orgs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取登录用户可访问的所有部门
|
||||
/// </summary>
|
||||
|
@@ -381,8 +381,6 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\ModuleManager\Index.cshtml" />
|
||||
<Content Include="Views\ModuleElementManager\Index.cshtml" />
|
||||
<Content Include="Views\ModuleElementManager\AssignModuleElement.cshtml" />
|
||||
<Content Include="Views\UserManager\Index.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
|
@@ -1,25 +0,0 @@
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<link href="~/Content/scripts/layui/css/layui.css" rel="stylesheet" />
|
||||
<link href="~/Content/mylayer.css" rel="stylesheet" />
|
||||
<script src="~/Content/scripts/layui/layui.js"></script>
|
||||
<script src="~/Content/scripts/jquery/jQuery-2.1.4.min.js"></script>
|
||||
<script src="~/Content/scripts/zTree/js/jquery.ztree.core.js"></script>
|
||||
<link href="/Content/scripts/zTree/css/metroStyle/metroStyle.css" rel="stylesheet" />
|
||||
|
||||
<div style="display: inline-block; width: 180px; height: 210px; padding: 10px; border: 1px solid #ddd; overflow: auto;">
|
||||
<input style="display: none" id="firstId" value="@ViewBag.FirstId" />
|
||||
<input style="display: none" id="moduleType" , value="@ViewBag.ModuleType" />
|
||||
<ul id="orgtree" class="ztree" style="width: 100%"></ul>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="site-tips" style="display: inline-block; height: 210px; width: 340px; padding: 10px; vertical-align: top;" id="demo2-view">
|
||||
<form class="layui-form " action="" id="moduleElements">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/assignModuleElement.js"></script>
|
@@ -1,113 +0,0 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/_LayoutNoHeader.cshtml";
|
||||
}
|
||||
|
||||
<!-- /section:basics/content.breadcrumbs -->
|
||||
<div class="page-content">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="widget-box widget-color-blue">
|
||||
<div class="widget-header">
|
||||
<div class="btn-group pull-right">
|
||||
<button type="button" class="btn btn-sm btn-success" id="btnAddElement">
|
||||
添加
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-success" id="btnEditElement">
|
||||
编辑
|
||||
</button>
|
||||
<button type="button" class="btn btn-sm btn-danger" id="btnDelElement">
|
||||
删除
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="widget-body gridwidth">
|
||||
<div class="widget-main">
|
||||
<div class="row">
|
||||
<div class="col-md-12 ">
|
||||
<input id="selectedModuleId" value="@ViewBag.ModuleId" style="display: none" />
|
||||
<table id="maingrid"></table>
|
||||
<div id="grid-pager"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div><!-- /.page-content -->
|
||||
<!--编辑对话框-->
|
||||
<div id="editDlg" style="display: none">
|
||||
<input type="hidden" id="ModuleId" v-model="ModuleId" />
|
||||
|
||||
<div class="col-xs-12">
|
||||
<form class="form-horizontal" id="editForm">
|
||||
<div class="form-group">
|
||||
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> DOM ID </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="DomId" check-type="required" v-model="DomId" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 名称 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Name" check-type="required" v-model="Name" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 脚本 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Script" check-type="required" v-model="Script" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 排序号 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Sort" check-type="required" v-model="Sort" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 描述 </label>
|
||||
<div class="col-sm-9">
|
||||
<input type="text" id="Remark" check-type="required" v-model="Remark" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 元素样式 </label>
|
||||
<div class="col-sm-9">
|
||||
<select id="Class" name="Class" v-model="Class">
|
||||
<option value="btn-success" selected>绿色</option>
|
||||
<option value="btn-red">红色</option>
|
||||
<option value="btn-primary">默认</option>
|
||||
<option value="btn-danger">警告</option>
|
||||
<option value="btn-pink">粉红</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label no-padding-right" for=""> 图标 </label>
|
||||
<div class="col-sm-9">
|
||||
<select id="Icon" name="Icon" v-model="Icon">
|
||||
<option value="pencil" selected>pencil</option>
|
||||
<option value="plus">plus</option>
|
||||
<option value="trash">trash</option>
|
||||
<option value="bank">bank</option>
|
||||
<option value="bar">bar</option>
|
||||
<option value="refresh">refresh</option>
|
||||
<option value="user">user</option>
|
||||
<option value="key">key</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<script src="~/BllScripts/grid.js"></script>
|
||||
<script src="~/BllScripts/moduleElementMan.js"></script>
|
||||
<script src="~/BllScripts/jqEvent.js"></script>
|
@@ -9,7 +9,7 @@
|
||||
<div style="display: flex;">
|
||||
<ul id="tree" class="ztree" style="display: inline-block; width: 180px; padding: 10px; border: 1px solid #ddd; overflow: auto;"></ul>
|
||||
<table class="layui-table"
|
||||
lay-data="{height: 'full-80', page:true, id:'mainList'}"
|
||||
lay-data="{height: 'full-80', id:'mainList'}"
|
||||
lay-filter="list" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
@@ -46,7 +46,7 @@
|
||||
<th lay-data="{field:'Name', width:120, sort: true, fixed: true}">名称</th>
|
||||
<th lay-data="{field:'DomId', width:80}">DomId</th>
|
||||
<th lay-data="{field:'Class', width:80}">样式</th>
|
||||
<th lay-data="{field:'IconName', width:60,templet: '#iconTpl'}">图标</th>
|
||||
<th lay-data="{field:'Icon', width:60,templet: '#miconTpl'}">图标</th>
|
||||
<th lay-data="{field:'SortNo', width:80}">排序号</th>
|
||||
<th lay-data="{fixed: 'right', width:80, align:'center', toolbar: '#menuBar'}"></th>
|
||||
</tr>
|
||||
@@ -56,11 +56,18 @@
|
||||
<script type="text/html" id="menuBar">
|
||||
<a class="layui-btn layui-btn-primary layui-btn-mini" lay-event="del">删除</a>
|
||||
</script>
|
||||
<script type="text/html" id="miconTpl">
|
||||
{{# if( d.Icon != null && d.Icon != ''){ }}
|
||||
<i class="layui-icon">{{ d.Icon }}</i>
|
||||
{{# } else { }}
|
||||
{{ d.Icon }}
|
||||
{{# } }}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<!--用户添加/编辑窗口-->
|
||||
<!--模块添加/编辑窗口-->
|
||||
<div id="divEdit" style="display: none">
|
||||
<form class="layui-form" action="" id="formEdit">
|
||||
|
||||
@@ -116,5 +123,51 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!--添加菜单窗口-->
|
||||
<div id="divMenuEdit" style="display: none">
|
||||
<form class="layui-form" action="" id="mfromEdit">
|
||||
|
||||
<input type="hidden" name="Id" v-model="Id" />
|
||||
<input type="hidden" name="ModuleId" v-model="ModuleId" />
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">菜单名称</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="Name" v-model="Name" required lay-verify="required"
|
||||
placeholder="请输入名称" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">DomId</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="DomId" v-model="DomId" required lay-verify="required"
|
||||
placeholder="请输入DomId" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">图标</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="Icon" v-model="Icon"
|
||||
placeholder="请选择图标" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">排序号</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="SortNo" v-model="SortNo" required lay-verify="required"
|
||||
placeholder="请输入排序号" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="mformSubmit">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/js/modules.js"></script>
|
@@ -7,7 +7,7 @@ layui.config({
|
||||
$ = layui.jquery;
|
||||
var table = layui.table;
|
||||
var openauth = layui.openauth;
|
||||
layui.droptree("/moduleManager/LoadModule", "#ParentName", "#ParentId", false);
|
||||
layui.droptree("/UserSession/QueryModuleList", "#ParentName", "#ParentId", false);
|
||||
|
||||
//主列表加载,可反复调用进行刷新
|
||||
var config= {}; //table的参数,如搜索key,点击tree的id
|
||||
@@ -35,7 +35,7 @@ layui.config({
|
||||
|
||||
//左边树状机构列表
|
||||
var ztree = function () {
|
||||
var url = '/ModuleManager/LoadModule';
|
||||
var url = '/UserSession/QueryModuleList';
|
||||
var zTreeObj;
|
||||
var setting = {
|
||||
view: { selectedMulti: false },
|
||||
@@ -73,7 +73,7 @@ layui.config({
|
||||
}
|
||||
}();
|
||||
|
||||
//添加(编辑)对话框
|
||||
//添加(编辑)模块对话框
|
||||
var editDlg = function() {
|
||||
var vm = new Vue({
|
||||
el: "#formEdit"
|
||||
@@ -122,7 +122,57 @@ layui.config({
|
||||
};
|
||||
}();
|
||||
|
||||
//监听表格内部按钮
|
||||
//添加菜单对话框
|
||||
var meditDlg = function () {
|
||||
var vm = new Vue({
|
||||
el: "#mfromEdit"
|
||||
});
|
||||
var update = false; //是否为更新
|
||||
var show = function (data) {
|
||||
var title = update ? "编辑信息" : "添加";
|
||||
layer.open({
|
||||
title: title,
|
||||
area: ["500px", "400px"],
|
||||
type: 1,
|
||||
content: $('#divMenuEdit'),
|
||||
success: function () {
|
||||
vm.$set('$data', data);
|
||||
},
|
||||
end: menuList
|
||||
});
|
||||
var url = "/moduleManager/AddMenu";
|
||||
if (update) {
|
||||
url = "/moduleManager/UpdateMenu";
|
||||
}
|
||||
//提交数据
|
||||
form.on('submit(mformSubmit)',
|
||||
function (data) {
|
||||
$.post(url,
|
||||
data.field,
|
||||
function (data) {
|
||||
layer.msg(data.Message);
|
||||
},
|
||||
"json");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
return {
|
||||
add: function (moduleId) { //弹出添加
|
||||
update = false;
|
||||
show({
|
||||
Id: "",
|
||||
ModuleId:moduleId,
|
||||
SortNo: 1
|
||||
});
|
||||
},
|
||||
update: function (data) { //弹出编辑框
|
||||
update = true;
|
||||
show(data);
|
||||
}
|
||||
};
|
||||
}();
|
||||
|
||||
//监听模块表格内部按钮
|
||||
table.on('tool(list)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'detail') { //查看
|
||||
@@ -131,6 +181,15 @@ layui.config({
|
||||
}
|
||||
});
|
||||
|
||||
//监听菜单表格内部按钮
|
||||
table.on('tool(menulist)', function (obj) {
|
||||
var data = obj.data;
|
||||
if (obj.event === 'del') { //删除菜单
|
||||
openauth.del("/moduleManager/delMenu",
|
||||
data.Id,menuList);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
//监听页面主按钮操作
|
||||
var active = {
|
||||
@@ -141,8 +200,17 @@ layui.config({
|
||||
data.map(function (e) { return e.Id; }),
|
||||
mainList);
|
||||
}
|
||||
, btnAdd: function () { //添加
|
||||
, btnAdd: function () { //添加模块
|
||||
editDlg.add();
|
||||
}
|
||||
, btnAddMenu: function () { //添加菜单
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
layer.msg("请选择一个要添加菜单的模块");
|
||||
return;
|
||||
}
|
||||
meditDlg.add(data[0]);
|
||||
}
|
||||
, btnEdit: function () { //编辑
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
|
Reference in New Issue
Block a user