mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-07-15 23:13:40 +08:00
完成用户/角色分配资源
This commit is contained in:
parent
6c05096138
commit
18cc60152b
@ -12,6 +12,7 @@ namespace OpenAuth.App
|
||||
/// </summary>
|
||||
public class ResourceApp:BaseApp<Resource>
|
||||
{
|
||||
public RevelanceManagerApp RevelanceManagerApp { get; set; }
|
||||
|
||||
public IEnumerable<Resource> Get(string type)
|
||||
{
|
||||
@ -32,6 +33,19 @@ namespace OpenAuth.App
|
||||
Repository.Update(u =>u.Id,resource);
|
||||
}
|
||||
|
||||
public IEnumerable<Resource> LoadForUser(string appId, string userId)
|
||||
{
|
||||
var elementIds = RevelanceManagerApp.Get(Define.USERRESOURCE, true, userId);
|
||||
return UnitWork.Find<Resource>(u => elementIds.Contains(u.Id) && (appId == "" || u.AppId == appId));
|
||||
}
|
||||
|
||||
public IEnumerable<Resource> LoadForRole(string appId, string userId)
|
||||
{
|
||||
var elementIds = RevelanceManagerApp.Get(Define.ROLERESOURCE, true, userId);
|
||||
return UnitWork.Find<Resource>(u => elementIds.Contains(u.Id) && (appId =="" || u.AppId == appId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public TableData Load(QueryResourcesReq request)
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载用户模块
|
||||
/// 加载特定用户的模块
|
||||
/// </summary>
|
||||
/// <param name="firstId">The user identifier.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
|
@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.App.Request;
|
||||
using OpenAuth.App.Response;
|
||||
using OpenAuth.Repository.Domain;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
@ -19,6 +20,61 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public ActionResult Assign()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载特定用户的资源
|
||||
/// </summary>
|
||||
/// <param name="appId">应用appId</param>
|
||||
/// <param name="firstId">用户ID</param>
|
||||
/// <returns>System.String.</returns>
|
||||
public string LoadForUser(string appId, string firstId)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
var result = new Response<List<string>>
|
||||
{
|
||||
Result = App.LoadForUser(appId, firstId).Select(u =>u.Id).ToList()
|
||||
};
|
||||
return JsonHelper.Instance.Serialize(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载角色资源
|
||||
/// </summary>
|
||||
/// <param name="appId">应用ID</param>
|
||||
/// <param name="firstId">角色ID</param>
|
||||
public string LoadForRole(string appId, string firstId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = new Response<List<string>>
|
||||
{
|
||||
Result = App.LoadForRole(appId, firstId).Select(u => u.Id).ToList()
|
||||
};
|
||||
return JsonHelper.Instance.Serialize(result);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Result.Code = 500;
|
||||
Result.Message = e.Message;
|
||||
}
|
||||
|
||||
return JsonHelper.Instance.Serialize(Result);
|
||||
}
|
||||
|
||||
|
||||
public string Load([FromUri]QueryResourcesReq request)
|
||||
{
|
||||
|
@ -201,6 +201,7 @@
|
||||
<Content Include="js\slimscroll.js" />
|
||||
<Content Include="js\utils.js" />
|
||||
<Content Include="layui\css\modules\laydate\default\font.css" />
|
||||
<Content Include="userJs\assignResource.js" />
|
||||
<Content Include="userJs\assignRole.js" />
|
||||
<Content Include="userJs\flowinstanceDetail.js" />
|
||||
<Content Include="userJs\resources.js" />
|
||||
@ -650,6 +651,7 @@
|
||||
<Content Include="Views\RoleManager\Assign.cshtml" />
|
||||
<Content Include="Views\FlowInstances\Detail.cshtml" />
|
||||
<Content Include="Views\Resources\Index.cshtml" />
|
||||
<Content Include="Views\Resources\Assign.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="layui\lay\modules\mobile\" />
|
||||
|
31
OpenAuth.Mvc/Views/Resources/Assign.cshtml
Normal file
31
OpenAuth.Mvc/Views/Resources/Assign.cshtml
Normal file
@ -0,0 +1,31 @@
|
||||
@section header
|
||||
{
|
||||
<link rel="stylesheet" href="/css/treetable.css" />
|
||||
}
|
||||
|
||||
|
||||
<table class="layui-table"
|
||||
lay-data="{height: 'full-5', page:true, id:'mainList'}"
|
||||
lay-filter="list" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th lay-data="{checkbox:true, fixed: true}"></th>
|
||||
<th lay-data="{field:'Id', width:200}">资源标识</th>
|
||||
<th lay-data="{field:'Name', width:150}">名称</th>
|
||||
<th lay-data="{field:'Disable', width:150, templet:'#Disable'}">是否可用</th>
|
||||
<th lay-data="{field:'Description', width:200}">描述</th>
|
||||
<th lay-data="{field:'AppName', width:150}">所属应用</th>
|
||||
<th lay-data="{field:'TypeName', width:150}">分类名称</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<script type="text/html" id="Disable">
|
||||
{{# if(d.Disable){ }}
|
||||
<span class="layui-badge">已禁用</span>
|
||||
{{# } else{}}
|
||||
<span class="layui-badge layui-bg-green">正常</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="/layui/layui.js"></script>
|
||||
<script type="text/javascript" src="/userJs/assignResource.js"></script>
|
@ -6,36 +6,44 @@
|
||||
|
||||
<div class="layui-card">
|
||||
|
||||
<table class="layui-table"
|
||||
lay-data="{height: 'full-80', page:true, id:'mainList'}"
|
||||
lay-filter="list" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th lay-data="{checkbox:true, fixed: true}"></th>
|
||||
<th lay-data="{field:'Key', width:150}">资源标识</th>
|
||||
<th lay-data="{field:'Name', width:150}">名称</th>
|
||||
<th lay-data="{field:'Status', width:150}">当前状态</th>
|
||||
<th lay-data="{field:'SortNo', width:150}">排序号</th>
|
||||
<th lay-data="{field:'Description', width:150}">描述</th>
|
||||
<th lay-data="{field:'TypeName', width:150}">分类名称</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<table class="layui-table"
|
||||
lay-data="{height: 'full-80', page:true, id:'mainList'}"
|
||||
lay-filter="list" lay-size="sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th lay-data="{checkbox:true, fixed: true}"></th>
|
||||
<th lay-data="{field:'Id', width:200}">资源标识</th>
|
||||
<th lay-data="{field:'Name', width:150}">名称</th>
|
||||
<th lay-data="{field:'Disable', width:150, templet:'#Disable'}">是否可用</th>
|
||||
<th lay-data="{field:'SortNo', width:50}">排序</th>
|
||||
<th lay-data="{field:'Description', width:200}">描述</th>
|
||||
<th lay-data="{field:'AppName', width:150}">所属应用</th>
|
||||
<th lay-data="{field:'TypeName', width:150}">分类名称</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
<script type="text/html" id="Disable">
|
||||
{{# if(d.Disable){ }}
|
||||
<span class="layui-badge">已禁用</span>
|
||||
{{# } else{}}
|
||||
<span class="layui-badge layui-bg-green">正常</span>
|
||||
{{# } }}
|
||||
</script>
|
||||
|
||||
</div>
|
||||
|
||||
<!--添加/编辑窗口-->
|
||||
<div id="divEdit" style="display: none">
|
||||
<form class="layui-form layui-form-pane" action="" id="formEdit">
|
||||
<input type="hidden" name="Id" v-model="Id" />
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">资源标识</label>
|
||||
<div class="layui-input-block">
|
||||
<input type="text" name="Key" v-model="Key" required lay-verify="required"
|
||||
placeholder="资源英文唯一标识" autocomplete="off" class="layui-input">
|
||||
<input type="text" name="Id" v-model="Id" required lay-verify="required"
|
||||
placeholder="名称" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label">名称</label>
|
||||
<div class="layui-input-block">
|
||||
@ -57,7 +65,7 @@
|
||||
<div class="layui-input-block">
|
||||
|
||||
<input id="AppName" name="AppName" v-model="AppName" class="layui-input" />
|
||||
<input id="AppId" name="AppId" v-model="AppId" type="hidden" />
|
||||
<input id="AppId" name="AppId" v-model="AppId" type="hidden" />
|
||||
<div id="menuContent" class="menuContent" style="display: none;">
|
||||
<ul id="org" class="ztree"></ul>
|
||||
</div>
|
||||
|
93
OpenAuth.Mvc/userJs/assignResource.js
Normal file
93
OpenAuth.Mvc/userJs/assignResource.js
Normal file
@ -0,0 +1,93 @@
|
||||
layui.config({
|
||||
base: "/js/"
|
||||
}).use(['form','vue', 'ztree', 'layer', 'jquery', 'table','utils'], function () {
|
||||
var form = layui.form,
|
||||
layer = layui.layer,
|
||||
$ = layui.jquery;
|
||||
var table = layui.table;
|
||||
var id = $.getUrlParam("id"); //待分配的id
|
||||
var type = $.getUrlParam("type"); //待分配的id
|
||||
|
||||
|
||||
//主列表加载,可反复调用进行刷新
|
||||
var config= {}; //table的参数,如搜索key,点击tree的id
|
||||
var mainList = function(options) {
|
||||
if (options != undefined) {
|
||||
$.extend(config, options);
|
||||
}
|
||||
table.reload('mainList',
|
||||
{
|
||||
url: '/Resources/Load',
|
||||
where: config,
|
||||
done: function(res, curr, count) {
|
||||
//如果是异步请求数据方式,res即为你接口返回的信息。
|
||||
//如果是直接赋值的方式,res即为:{data: [], count: 99} data为当前页数据、count为数据总长度
|
||||
var url = "/Resources/LoadForUser";
|
||||
if (type.indexOf("Role") != -1) {
|
||||
url = "/Resources/LoadForRole";
|
||||
}
|
||||
|
||||
$.ajax(url,
|
||||
{
|
||||
async: false
|
||||
, data: {
|
||||
firstId: id
|
||||
, appid: "" //暂时不做左边的应用列表树
|
||||
}
|
||||
, dataType: 'json'
|
||||
,success: function(json) {
|
||||
if (json.Code == 500) return;
|
||||
var roles = json.Result;
|
||||
//循环所有数据,找出对应关系,设置checkbox选中状态
|
||||
for (var i = 0; i < res.data.length; i++) {
|
||||
for (var j = 0; j < roles.length; j++) {
|
||||
if (res.data[i].Id != roles[j]) continue;
|
||||
|
||||
//这里才是真正的有效勾选
|
||||
res.data[i]["LAY_CHECKED"] = true;
|
||||
//找到对应数据改变勾选样式,呈现出选中效果
|
||||
var index = res.data[i]['LAY_TABLE_INDEX'];
|
||||
$('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
$('.layui-table-fixed-l tr[data-index=' + index + '] input[type="checkbox"]')
|
||||
.next().addClass('layui-form-checked');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//如果构成全选
|
||||
var checkStatus = table.checkStatus('mainList');
|
||||
if (checkStatus.isAll) {
|
||||
$('.layui-table-header th[data-field="0"] input[type="checkbox"]')
|
||||
.prop('checked', true);
|
||||
$('.layui-table-header th[data-field="0"] input[type="checkbox"]').next()
|
||||
.addClass('layui-form-checked');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
mainList();
|
||||
|
||||
//分配及取消分配
|
||||
table.on('checkbox(list)', function (obj) {
|
||||
console.log(obj.checked); //当前是否选中状态
|
||||
console.log(obj.data); //选中行的相关数据
|
||||
console.log(obj.type); //如果触发的是全选,则为:all,如果触发的是单选,则为:one
|
||||
|
||||
var url = "/RelevanceManager/Assign";
|
||||
if (!obj.checked) {
|
||||
url = "/RelevanceManager/UnAssign";
|
||||
}
|
||||
$.post(url, { type: type, firstId: id, secIds: [obj.data.Id] }
|
||||
, function (data) {
|
||||
layer.msg(data.Message);
|
||||
}
|
||||
, "json");
|
||||
});
|
||||
//监听页面主按钮操作 end
|
||||
})
|
@ -24,8 +24,8 @@ layui.config({
|
||||
|
||||
$.ajax("/RoleManager/LoadForUser?userId=" + id,{
|
||||
async: false
|
||||
, success: function (data) {
|
||||
var json = JSON.parse(data);
|
||||
, dataType: 'json'
|
||||
, success: function (json) {
|
||||
if (json.Code == 500) return;
|
||||
var roles = json.Result;
|
||||
//循环所有数据,找出对应关系,设置checkbox选中状态
|
||||
|
@ -166,6 +166,24 @@ layui.config({
|
||||
content: "/ModuleManager/Assign?type=RoleModule&menuType=RoleElement&id=" + data[0].Id,
|
||||
success: function (layero, index) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
, btnAssignReource: function () {
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
toplayer.msg("请选择要分配的角色");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = toplayer.open({
|
||||
title: "为角色【" + data[0].Name + "】分配资源",
|
||||
type: 2,
|
||||
area: ['750px', '600px'],
|
||||
content: "/Resources/Assign?type=RoleResource&id=" + data[0].Id,
|
||||
success: function (layero, index) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -188,6 +188,24 @@ layui.config({
|
||||
content: "/RoleManager/Assign?type=UserRole&id=" + data[0].Id,
|
||||
success: function (layero, index) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
, btnAssignReource: function () {
|
||||
var checkStatus = table.checkStatus('mainList')
|
||||
, data = checkStatus.data;
|
||||
if (data.length != 1) {
|
||||
toplayer.msg("请选择要分配的用户");
|
||||
return;
|
||||
}
|
||||
|
||||
var index = toplayer.open({
|
||||
title: "为用户【" + data[0].Name + "】分配资源",
|
||||
type: 2,
|
||||
area: ['750px', '600px'],
|
||||
content: "/Resources/Assign?type=UserResource&id=" + data[0].Id,
|
||||
success: function (layero, index) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -21,8 +21,7 @@ namespace OpenAuth.Repository.Domain
|
||||
public Application()
|
||||
{
|
||||
this.Name= string.Empty;
|
||||
this.AppId= string.Empty;
|
||||
this.AppKey= string.Empty;
|
||||
this.AppSecret= string.Empty;
|
||||
this.Description= string.Empty;
|
||||
this.Icon= string.Empty;
|
||||
this.CreateTime= DateTime.Now;
|
||||
@ -30,17 +29,13 @@ namespace OpenAuth.Repository.Domain
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// 应用名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 应用ID
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
/// <summary>
|
||||
/// 应用密钥
|
||||
/// </summary>
|
||||
public string AppKey { get; set; }
|
||||
public string AppSecret { get; set; }
|
||||
/// <summary>
|
||||
/// 应用描述
|
||||
/// </summary>
|
||||
@ -56,7 +51,7 @@ namespace OpenAuth.Repository.Domain
|
||||
/// <summary>
|
||||
/// 创建日期
|
||||
/// </summary>
|
||||
public System.DateTime? CreateTime { get; set; }
|
||||
public System.DateTime CreateTime { get; set; }
|
||||
/// <summary>
|
||||
/// 创建人
|
||||
/// </summary>
|
||||
|
@ -21,13 +21,13 @@ namespace OpenAuth.Repository.Domain
|
||||
public Resource()
|
||||
{
|
||||
this.CascadeId= string.Empty;
|
||||
this.Key= string.Empty;
|
||||
this.Name= string.Empty;
|
||||
this.Status= 0;
|
||||
this.SortNo= 0;
|
||||
this.Description= string.Empty;
|
||||
this.ParentName= string.Empty;
|
||||
this.ParentId= string.Empty;
|
||||
this.AppId= string.Empty;
|
||||
this.AppName= string.Empty;
|
||||
this.TypeName= string.Empty;
|
||||
this.TypeId= string.Empty;
|
||||
}
|
||||
@ -36,18 +36,10 @@ namespace OpenAuth.Repository.Domain
|
||||
/// 节点语义ID
|
||||
/// </summary>
|
||||
public string CascadeId { get; set; }
|
||||
/// <summary>
|
||||
/// 资源英文唯一标识
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
/// <summary>
|
||||
/// 名称
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
/// <summary>
|
||||
/// 当前状态
|
||||
/// </summary>
|
||||
public int Status { get; set; }
|
||||
/// <summary>
|
||||
/// 排序号
|
||||
/// </summary>
|
||||
@ -57,13 +49,21 @@ namespace OpenAuth.Repository.Domain
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
/// <summary>
|
||||
/// 父节点流水号
|
||||
/// 父节点名称
|
||||
/// </summary>
|
||||
public string ParentName { get; set; }
|
||||
/// <summary>
|
||||
/// 父节点流ID
|
||||
/// </summary>
|
||||
public string ParentId { get; set; }
|
||||
/// <summary>
|
||||
/// 资源所属应用
|
||||
/// 资源所属应用ID
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
/// <summary>
|
||||
/// 所属应用名称
|
||||
/// </summary>
|
||||
public string AppName { get; set; }
|
||||
/// <summary>
|
||||
/// 分类名称
|
||||
/// </summary>
|
||||
@ -72,6 +72,10 @@ namespace OpenAuth.Repository.Domain
|
||||
/// 分类ID
|
||||
/// </summary>
|
||||
public string TypeId { get; set; }
|
||||
/// <summary>
|
||||
/// 是否可用
|
||||
/// </summary>
|
||||
public bool Disable { get; set; }
|
||||
|
||||
}
|
||||
}
|
@ -32,12 +32,8 @@ namespace OpenAuth.Repository.Mapping
|
||||
.HasColumnName("Name")
|
||||
.HasMaxLength(255)
|
||||
.IsRequired();
|
||||
Property(t => t.AppId)
|
||||
.HasColumnName("AppId")
|
||||
.HasMaxLength(255)
|
||||
.IsOptional();
|
||||
Property(t => t.AppKey)
|
||||
.HasColumnName("AppKey")
|
||||
Property(t => t.AppSecret)
|
||||
.HasColumnName("AppSecret")
|
||||
.HasMaxLength(255)
|
||||
.IsOptional();
|
||||
Property(t => t.Description)
|
||||
@ -53,7 +49,7 @@ namespace OpenAuth.Repository.Mapping
|
||||
.IsRequired();
|
||||
Property(t => t.CreateTime)
|
||||
.HasColumnName("CreateTime")
|
||||
.IsOptional();
|
||||
.IsRequired();
|
||||
Property(t => t.CreateUser)
|
||||
.HasColumnName("CreateUser")
|
||||
.HasMaxLength(50)
|
||||
|
@ -32,17 +32,10 @@ namespace OpenAuth.Repository.Mapping
|
||||
.HasColumnName("CascadeId")
|
||||
.HasMaxLength(255)
|
||||
.IsRequired();
|
||||
Property(t => t.Key)
|
||||
.HasColumnName("Key")
|
||||
.HasMaxLength(200)
|
||||
.IsRequired();
|
||||
Property(t => t.Name)
|
||||
.HasColumnName("Name")
|
||||
.HasMaxLength(255)
|
||||
.IsRequired();
|
||||
Property(t => t.Status)
|
||||
.HasColumnName("Status")
|
||||
.IsRequired();
|
||||
Property(t => t.SortNo)
|
||||
.HasColumnName("SortNo")
|
||||
.IsRequired();
|
||||
@ -50,6 +43,10 @@ namespace OpenAuth.Repository.Mapping
|
||||
.HasColumnName("Description")
|
||||
.HasMaxLength(500)
|
||||
.IsRequired();
|
||||
Property(t => t.ParentName)
|
||||
.HasColumnName("ParentName")
|
||||
.HasMaxLength(50)
|
||||
.IsOptional();
|
||||
Property(t => t.ParentId)
|
||||
.HasColumnName("ParentId")
|
||||
.HasMaxLength(50)
|
||||
@ -58,6 +55,10 @@ namespace OpenAuth.Repository.Mapping
|
||||
.HasColumnName("AppId")
|
||||
.HasMaxLength(50)
|
||||
.IsOptional();
|
||||
Property(t => t.AppName)
|
||||
.HasColumnName("AppName")
|
||||
.HasMaxLength(50)
|
||||
.IsOptional();
|
||||
Property(t => t.TypeName)
|
||||
.HasColumnName("TypeName")
|
||||
.HasMaxLength(20)
|
||||
@ -66,6 +67,9 @@ namespace OpenAuth.Repository.Mapping
|
||||
.HasColumnName("TypeId")
|
||||
.HasMaxLength(50)
|
||||
.IsOptional();
|
||||
Property(t => t.Disable)
|
||||
.HasColumnName("Disable")
|
||||
.IsRequired();
|
||||
|
||||
// Relationships
|
||||
}
|
||||
|
BIN
建表&初始化数据.sql
BIN
建表&初始化数据.sql
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user