mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-09-19 10:08:04 +08:00
调整数据库菜单表结构,可以动态加载按钮,注意更新数据库结构并重新初始化数据库
This commit is contained in:
@@ -1,69 +1,72 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.Mvc
|
||||
// Author : Yubao Li
|
||||
// Created : 12-02-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-02-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleElementManagerController.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>模块元素管理,无需权限控制</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ModuleElementManagerController : Controller
|
||||
{
|
||||
private readonly BjuiResponse _bjuiResponse = new BjuiResponse();
|
||||
private ModuleElementManagerApp _app;
|
||||
|
||||
public ModuleElementManagerController()
|
||||
{
|
||||
_app = (ModuleElementManagerApp) DependencyResolver.Current.GetService(typeof (ModuleElementManagerApp));
|
||||
}
|
||||
|
||||
public ActionResult Index(int id = 0)
|
||||
{
|
||||
ViewBag.ModuleId = id;
|
||||
return View(_app.LoadByModuleId(id));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public string AddOrEditButton(ModuleElement button)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.AddOrUpdate(button);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
|
||||
public string DelButton(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
}
|
||||
// ***********************************************************************
|
||||
// Assembly : OpenAuth.Mvc
|
||||
// Author : Yubao Li
|
||||
// Created : 12-02-2015
|
||||
//
|
||||
// Last Modified By : Yubao Li
|
||||
// Last Modified On : 12-02-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="ModuleElementManagerController.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>模块元素管理,无需权限控制</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class ModuleElementManagerController : Controller
|
||||
{
|
||||
private readonly BjuiResponse _bjuiResponse = new BjuiResponse();
|
||||
private ModuleElementManagerApp _app;
|
||||
|
||||
public ModuleElementManagerController()
|
||||
{
|
||||
_app = (ModuleElementManagerApp) DependencyResolver.Current.GetService(typeof (ModuleElementManagerApp));
|
||||
}
|
||||
|
||||
public ActionResult Index(int id = 0)
|
||||
{
|
||||
ViewBag.ModuleId = id;
|
||||
return View(_app.LoadByModuleId(id));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public string AddOrEditButton(ModuleElement button)
|
||||
{
|
||||
try
|
||||
{
|
||||
var newbtn = new ModuleElement();
|
||||
button.CopyTo(newbtn);
|
||||
_app.AddOrUpdate(newbtn);
|
||||
}
|
||||
catch (DbEntityValidationException e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
|
||||
public string DelButton(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_app.Delete(id);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_bjuiResponse.statusCode = "300";
|
||||
_bjuiResponse.message = e.Message;
|
||||
}
|
||||
return JsonHelper.Instance.Serialize(_bjuiResponse);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,61 +1,69 @@
|
||||
@model IEnumerable<OpenAuth.Domain.ModuleElement>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
//删除回调
|
||||
$('#tableButtons').on('afterdelete.bjui.tabledit', function(e) {
|
||||
var $tbody = $(e.relatedTarget);
|
||||
console.log('你删除了一条数据,还有['+ $tbody.find('> tr').length +']条数据!');
|
||||
})
|
||||
</script>
|
||||
<div class="bjui-pageHeader">
|
||||
<div class="bjui-searchBar">
|
||||
<div class="alert alert-info search-inline"><i class="fa fa-info-circle"></i> 双击行可编辑</div>
|
||||
<button type="button" class="btn-green" data-toggle="tableditadd" data-target="#tableButtons" data-num="1" data-icon="plus">
|
||||
添加新按钮
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<form id="j_custom_form" class="pageForm" data-toggle="validate" method="post">
|
||||
<table id="tableButtons" class="table table-bordered table-hover table-striped table-top"
|
||||
data-toggle="tabledit" data-initnum="0" data-action="/ModuleElementManager/AddOrEditButton" data-single-noindex="true">
|
||||
<thead>
|
||||
<tr data-idname="Id">
|
||||
<th width="80" title="按钮标识"><input type="text" name="DomId" data-rule="required" value="" size="5"></th>
|
||||
<th width="80" title="按钮显示"><input type="text" name="Name" data-rule="required" value="" size="5"></th>
|
||||
<th title="备注"><textarea name="Remark" data-toggle="autoheight"></textarea></th>
|
||||
<th width="80" title="所属模块ID"><input readonly="readonly" type="text" value="@ViewBag.ModuleId" name="ModuleId"/></th>
|
||||
<th title="操作" width="100">
|
||||
<a href="javascript:;" class="btn btn-green" data-toggle="dosave">增加</a>
|
||||
<a href="javascript:;" class="btn btn-red row-del">取消</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var element in Model)
|
||||
{
|
||||
<tr data-id="@element.Id">
|
||||
|
||||
<td>@element.DomId</td>
|
||||
<td>@element.Name</td>
|
||||
<td>@element.Remark</td>
|
||||
<td>@ViewBag.ModuleId</td>
|
||||
<td data-noedit="true">
|
||||
<input type="text" style="display: none" value="@element.Id" id="element_@element.Id" />
|
||||
<button type="button" class="btn-green" data-toggle="doedit">编辑</button>
|
||||
<a href="/ModuleElementManager/DelButton?id={#element_@element.Id}" class="btn btn-red row-del"
|
||||
data-confirm-msg="确定要删除该行信息吗?">删</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
|
||||
</ul>
|
||||
@model IEnumerable<OpenAuth.Domain.ModuleElement>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
//删除回调
|
||||
$('#tableButtons').on('afterdelete.bjui.tabledit', function(e) {
|
||||
var $tbody = $(e.relatedTarget);
|
||||
console.log('你删除了一条数据,还有['+ $tbody.find('> tr').length +']条数据!');
|
||||
})
|
||||
</script>
|
||||
<div class="bjui-pageHeader">
|
||||
<div class="bjui-searchBar">
|
||||
<div class="alert alert-info search-inline"><i class="fa fa-info-circle"></i> 双击行可编辑</div>
|
||||
<button type="button" class="btn-green" data-toggle="tableditadd" data-target="#tableButtons" data-num="1" data-icon="plus">
|
||||
添加新按钮
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="bjui-pageContent tableContent">
|
||||
<form id="j_custom_form" class="pageForm" data-toggle="validate" method="post">
|
||||
<table id="tableButtons" class="table table-bordered table-hover table-striped table-top"
|
||||
data-toggle="tabledit" data-initnum="0" data-action="/ModuleElementManager/AddOrEditButton" data-single-noindex="true">
|
||||
<thead>
|
||||
<tr data-idname="Id">
|
||||
<th width="80" title="元素类型"><input type="text" name="Type" data-rule="required" value="button" size="5"></th>
|
||||
<th width="80" title="按钮标识"><input type="text" name="DomId" data-rule="required" value="" size="5"></th>
|
||||
<th width="80" title="按钮显示"><input type="text" name="Name" data-rule="required" value="" size="5"></th>
|
||||
<th width="120" title="按钮样式"><input type="text" name="Class" data-rule="required" value="btn-green btn-nm" size="5"></th>
|
||||
<th width="80" title="按钮图标"><input type="text" name="Icon" data-rule="required" value="pencil" size="5"></th>
|
||||
<th width="120" title="按钮脚本"><textarea name="Script" data-toggle="autoheight" value="javascript:;"></textarea></th>
|
||||
<th width="120" title="附加属性"><textarea name="Attr" data-toggle="autoheight"></textarea></th>
|
||||
<th width="80" title="所属模块ID"><input readonly="readonly" type="text" value="@ViewBag.ModuleId"
|
||||
name="ModuleId"/></th>
|
||||
<th title="操作" width="100">
|
||||
<a href="javascript:;" class="btn btn-green" data-toggle="dosave">增加</a>
|
||||
<a href="javascript:;" class="btn btn-red row-del">取消</a>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var element in Model)
|
||||
{
|
||||
<tr data-id="@element.Id">
|
||||
<td>@element.Type</td>
|
||||
<td>@element.DomId</td>
|
||||
<td>@element.Name</td>
|
||||
<td>@element.Class</td>
|
||||
<td>@element.Icon</td>
|
||||
<td>@element.Script</td>
|
||||
<td>@element.Attr</td>
|
||||
<td>@ViewBag.ModuleId</td>
|
||||
<td data-noedit="true">
|
||||
<input type="text" style="display: none" value="@element.Id" id="element_@element.Id"/>
|
||||
<button type="button" class="btn-green" data-toggle="doedit">编辑</button>
|
||||
<a href="/ModuleElementManager/DelButton?id={#element_@element.Id}" class="btn btn-red row-del"
|
||||
data-confirm-msg="确定要删除该行信息吗?">删</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
<div class="bjui-pageFooter">
|
||||
<ul>
|
||||
<li><button type="button" class="btn-close" data-icon="close">关闭</button></li>
|
||||
</ul>
|
||||
</div>
|
@@ -186,6 +186,9 @@
|
||||
|
||||
$(this).dialog({
|
||||
id: 'editDialog',
|
||||
width: 820,
|
||||
height: 500,
|
||||
mask:true,
|
||||
url: '/ModuleElementManager/Index?id=' + selected,
|
||||
title: '为模块分配按钮'
|
||||
});
|
||||
|
@@ -1,15 +1,37 @@
|
||||
@{
|
||||
@using System.Text
|
||||
@{
|
||||
string _prefix = "user";
|
||||
var _treeId = _prefix + "Tree";
|
||||
var _gridId = _prefix + "Grid";
|
||||
var _treeDetail = _prefix + "Detail";
|
||||
}
|
||||
|
||||
<div class="bjui-pageContent">
|
||||
<div class="clearfix">
|
||||
<div style="float: left; width: 220px; overflow: auto;" class="table table-bordered">
|
||||
<ul id="@_treeId" class="ztree"></ul>
|
||||
</div>
|
||||
|
||||
<div class="bjui-pageHeader" style="margin-left: 225px">
|
||||
<div class="bjui-searchBar">
|
||||
<div class="bjui-searchBar">
|
||||
@{
|
||||
var sb = new StringBuilder();
|
||||
foreach (var element in ViewBag.Module.Elements)
|
||||
{
|
||||
sb.Append("<" + element.Type
|
||||
+" data-icon='" + element.Icon+"' "
|
||||
+" class='" + element.Class+"' "
|
||||
+" onclick='" + element.Script+"' " + element.Attr
|
||||
+ ">"+element.Name +"</" + element.Type +">");
|
||||
}
|
||||
@Html.Raw(sb.ToString())
|
||||
}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="@_treeDetail" style="margin-left: 225px;">
|
||||
</div>
|
||||
</div>
|
||||
@@ -29,25 +51,15 @@
|
||||
$('#@_treeDetail').empty()
|
||||
.append('<table id="@_gridId" class="table table-bordered"></table>');
|
||||
|
||||
@{
|
||||
string strBtns = string.Empty;
|
||||
foreach (var element in ViewBag.Module.Elements)
|
||||
{
|
||||
strBtns +="<button type=\"button\" class =\"btn btn-green\">"+element.Name +"</button>";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
grid = $(gridid).datagrid({
|
||||
gridTitle: '用户列表',
|
||||
showToolbar: true,
|
||||
showToolbar: false,
|
||||
filterThead: false,
|
||||
toolbarItem: 'refresh, |, del',
|
||||
toolbarCustom: '<a href="/UserManager/Add" class="btn btn-green" data-icon ="plus" ' +
|
||||
'data-toggle="dialog" data-id="dialog-mask" data-mask="true" data-on-close="refreshGrid">添加</a>' +
|
||||
'<button class=" btn-green" onclick="editOrg()" data-icon="pencil" type="button">编辑</button>' +
|
||||
'<button type="button" class="btn btn-green" onclick="openModuleAccess(this)">为用户分配模块</button>' +
|
||||
'<button type="button" class ="btn btn-green" onclick="openRoleAccess(this)">为用户分配角色</button>' + '@strBtns',
|
||||
'<button type="button" class ="btn btn-green" onclick="openRoleAccess(this)">为用户分配角色</button>',
|
||||
columns: [
|
||||
{
|
||||
name: 'Id',
|
||||
|
Reference in New Issue
Block a user