调整数据库菜单表结构,可以动态加载按钮,注意更新数据库结构并重新初始化数据库

This commit is contained in:
yubaolee 2015-12-05 16:07:53 +08:00
parent 135723f563
commit af5e04d62f
16 changed files with 805 additions and 1090 deletions

View File

@ -6,12 +6,12 @@ using System.Linq;
namespace OpenAuth.Domain
{
/// <summary>
/// 系统模块
/// 用户ID
/// </summary>
public partial class Module
{
/// <summary>
/// 模块ID
/// 用户ID
/// </summary>
/// <returns></returns>
public int Id { get; set; }

View File

@ -29,10 +29,10 @@ namespace OpenAuth.Domain
public string Name { get; set; }
/// <summary>
/// 组织类型
/// 元素的类型(如button/a
/// </summary>
/// <returns></returns>
public int Type { get; set; }
public string Type { get; set; }
/// <summary>
/// 功能模块Id
@ -40,6 +40,30 @@ namespace OpenAuth.Domain
/// <returns></returns>
public int ModuleId { get; set; }
/// <summary>
/// 元素附加属性
/// </summary>
/// <returns></returns>
public string Attr { get; set; }
/// <summary>
/// 元素调用脚本
/// </summary>
/// <returns></returns>
public string Script { get; set; }
/// <summary>
/// 元素图标
/// </summary>
/// <returns></returns>
public string Icon { get; set; }
/// <summary>
/// 元素样式
/// </summary>
/// <returns></returns>
public string Class { get; set; }
/// <summary>
/// 备注
/// </summary>
@ -52,8 +76,12 @@ namespace OpenAuth.Domain
this.Id= 0;
this.DomId= string.Empty;
this.Name= string.Empty;
this.Type= 0;
this.Type = string.Empty;
this.ModuleId= 0;
this.Attr= string.Empty;
this.Script= string.Empty;
this.Icon= string.Empty;
this.Class= string.Empty;
this.Remark= string.Empty;
}

View File

@ -1,56 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace OpenAuth.Domain
{
/// <summary>
/// 用户ID
/// </summary>
public partial class ModuleElementGrant
{
/// <summary>
/// 用户ID
/// </summary>
/// <returns></returns>
public int Id { get; set; }
/// <summary>
/// 元素流水号
/// </summary>
/// <returns></returns>
public int ElementId { get; set; }
/// <summary>
/// 用户流水号
/// </summary>
/// <returns></returns>
public int UserId { get; set; }
/// <summary>
/// 角色流水号
/// </summary>
/// <returns></returns>
public int RoleId { get; set; }
/// <summary>
/// 权限类型
/// </summary>
/// <returns></returns>
public int GrantType { get; set; }
public ModuleElementGrant()
{
this.Id= 0;
this.ElementId= 0;
this.UserId= 0;
this.RoleId= 0;
this.GrantType= 0;
}
}
}

View File

@ -51,7 +51,6 @@
<Compile Include="Interface\IUserRepository.cs" />
<Compile Include="Module.cs" />
<Compile Include="ModuleElement.cs" />
<Compile Include="ModuleElementGrant.cs" />
<Compile Include="Org.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Relevance.cs" />

View File

@ -13,6 +13,7 @@
// ***********************************************************************
using System;
using System.Data.Entity.Validation;
using System.Web.Mvc;
using Infrastructure;
using OpenAuth.App;
@ -42,9 +43,11 @@ namespace OpenAuth.Mvc.Controllers
{
try
{
_app.AddOrUpdate(button);
var newbtn = new ModuleElement();
button.CopyTo(newbtn);
_app.AddOrUpdate(newbtn);
}
catch (Exception e)
catch (DbEntityValidationException e)
{
_bjuiResponse.statusCode = "300";
_bjuiResponse.message = e.Message;

View File

@ -22,10 +22,15 @@ $('#tableButtons').on('afterdelete.bjui.tabledit', function(e) {
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 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 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>
@ -36,10 +41,13 @@ $('#tableButtons').on('afterdelete.bjui.tabledit', function(e) {
@foreach (var element in Model)
{
<tr data-id="@element.Id">
<td>@element.Type</td>
<td>@element.DomId</td>
<td>@element.Name</td>
<td>@element.Remark</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"/>

View File

@ -186,6 +186,9 @@
$(this).dialog({
id: 'editDialog',
width: 820,
height: 500,
mask:true,
url: '/ModuleElementManager/Index?id=' + selected,
title: '为模块分配按钮'
});

View File

@ -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',

View File

@ -1,24 +0,0 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using OpenAuth.Domain;
namespace OpenAuth.Repository.Models.Mapping
{
public class ModuleElementGrantMap : EntityTypeConfiguration<ModuleElementGrant>
{
public ModuleElementGrantMap()
{
// Primary Key
this.HasKey(t => t.Id);
// Properties
// Table & Column Mappings
this.ToTable("ModuleElementGrant");
this.Property(t => t.Id).HasColumnName("Id");
this.Property(t => t.ElementId).HasColumnName("ElementId");
this.Property(t => t.UserId).HasColumnName("UserId");
this.Property(t => t.RoleId).HasColumnName("RoleId");
this.Property(t => t.GrantType).HasColumnName("GrantType");
}
}
}

View File

@ -20,9 +20,25 @@ namespace OpenAuth.Repository.Models.Mapping
.IsRequired()
.HasMaxLength(255);
this.Property(t => t.Attr)
.IsRequired()
.HasMaxLength(500);
this.Property(t => t.Script)
.IsRequired()
.HasMaxLength(500);
this.Property(t => t.Icon)
.IsRequired()
.HasMaxLength(255);
this.Property(t => t.Class)
.IsRequired()
.HasMaxLength(255);
this.Property(t => t.Remark)
.IsRequired()
.HasMaxLength(4000);
.HasMaxLength(200);
// Table & Column Mappings
this.ToTable("ModuleElement");
@ -31,6 +47,10 @@ namespace OpenAuth.Repository.Models.Mapping
this.Property(t => t.Name).HasColumnName("Name");
this.Property(t => t.Type).HasColumnName("Type");
this.Property(t => t.ModuleId).HasColumnName("ModuleId");
this.Property(t => t.Attr).HasColumnName("Attr");
this.Property(t => t.Script).HasColumnName("Script");
this.Property(t => t.Icon).HasColumnName("Icon");
this.Property(t => t.Class).HasColumnName("Class");
this.Property(t => t.Remark).HasColumnName("Remark");
}
}

View File

@ -19,7 +19,6 @@ namespace OpenAuth.Repository.Models
public DbSet<Module> Modules { get; set; }
public DbSet<ModuleElement> ModuleElements { get; set; }
public DbSet<ModuleElementGrant> ModuleElementGrants { get; set; }
public DbSet<Org> Orgs { get; set; }
public DbSet<Relevance> Relevances { get; set; }
public DbSet<Role> Roles { get; set; }
@ -31,7 +30,6 @@ namespace OpenAuth.Repository.Models
{
modelBuilder.Configurations.Add(new ModuleMap());
modelBuilder.Configurations.Add(new ModuleElementMap());
modelBuilder.Configurations.Add(new ModuleElementGrantMap());
modelBuilder.Configurations.Add(new OrgMap());
modelBuilder.Configurations.Add(new RelevanceMap());
modelBuilder.Configurations.Add(new RoleMap());

View File

@ -54,7 +54,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BaseRepository.cs" />
<Compile Include="Models\Mapping\ModuleElementGrantMap.cs" />
<Compile Include="Models\Mapping\ModuleElementMap.cs" />
<Compile Include="Models\Mapping\ModuleMap.cs" />
<Compile Include="Models\Mapping\OrgMap.cs" />

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff