diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
index df8eab43..030ce0cd 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
@@ -91,6 +91,12 @@
+
+
+ 通过角色id来获取菜单列表
+
+
+
测试控制器
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
index 5159bca4..b2c3a03c 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/MenuController.cs
@@ -28,6 +28,8 @@ namespace Yi.Framework.ApiMicroservice.Controllers
_iMenuService = iMenuService;
}
+
+
///
/// 得到树形菜单
///
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
index a6c57344..4ce473d8 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/RoleController.cs
@@ -40,6 +40,14 @@ namespace Yi.Framework.ApiMicroservice.Controllers
return Result.Success().SetStatus(await _iRoleService.GiveRoleSetMenu(giveRoleSetMenuDto.RoleIds, giveRoleSetMenuDto.MenuIds));
}
-
+ ///
+ /// 通过角色id来获取菜单列表
+ ///
+ ///
+ [HttpGet]
+ public async Task GetInMenuByRoleId(long RoleId)
+ {
+ return Result.Success().SetData(await _iRoleService.GetInMenuByRoleId(RoleId));
+ }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
index f8ecd6b6..a7251a4c 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
@@ -63,7 +63,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
//不建议操作,直接切换其他仓储
await _iUserService._repository.ChangeRepository>().GetListAsync();
- //直接操作Db对象???恭喜你已经毕业了!此后将有一天,接手到这个的软件的程序员将破口大骂。
+ //最好不要直接操作Db对象
await _iUserService._repository._Db.Queryable().ToListAsync();
return Result.Success().SetData(await _iUserService.DbTest());
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db
index 9c6a6b2d..d7568068 100644
Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
index 88f2aec3..58895248 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/IRoleService.cs
@@ -13,6 +13,13 @@ namespace Yi.Framework.Interface
///
Task> DbTest();
+ ///
+ /// 通过角色id获取角色实体包含菜单
+ ///
+ ///
+ ///
+ Task GetInMenuByRoleId(long roleId);
+
///
/// 给角色设置菜单,多角色,多菜单
///
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
index 16340453..37fe431d 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Model/RoleEntity.cs
@@ -10,5 +10,7 @@ namespace Yi.Framework.Model.Models
{
//[Navigate(typeof(UserRoleEntity), nameof(UserRoleEntity.RoleId), nameof(UserRoleEntity.UserId))]
//public List Users { get; set; }
+ [Navigate(typeof(RoleMenuEntity),nameof(RoleMenuEntity.RoleId),nameof(RoleMenuEntity.MenuId))]
+ public List Menus { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs b/Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs
index d738ad77..9caae018 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/DataContext.cs
@@ -1,16 +1,15 @@
-using SqlSugar;
-using Yi.Framework.Common.Models;
-using Yi.Framework.Model.Models;
+//using SqlSugar;
+//using Yi.Framework.Common.Models;
+//using Yi.Framework.Model.Models;
-namespace Yi.Framework.Repository
-{
- public class DataContext : SimpleClient where T : class, IBaseModelEntity, new()
- {
- public DataContext(ISqlSugarClient context) : base(context)
- {
- Db =base.Context;
- }
+//namespace Yi.Framework.Repository
+//{
+// public class DataContext : SimpleClient where T : class, IBaseModelEntity, new()
+// {
+// public DataContext(ISqlSugarClient context) : base(context)
+// {
+// }
- public ISqlSugarClient Db;
- }
-}
+// }
+//}
+//简化已被弃用
diff --git a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
index a78f4704..cfa20c1f 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
@@ -12,16 +12,15 @@ namespace Yi.Framework.Repository
/// 仓储模式
///
///
- public class Repository : DataContext, IRepository where T : class, IBaseModelEntity, new()
+ public class Repository : SimpleClient, IRepository where T : class, IBaseModelEntity, new()
{
- public ISqlSugarClient _Db { get; set; }
+ public ISqlSugarClient _Db { get { return base.Context; } set { } }
///
/// 构造函数
///
///
public Repository(ISqlSugarClient context) : base(context)//注意这里要有默认值等于null
{
- _Db = context;
}
///
@@ -31,7 +30,8 @@ namespace Yi.Framework.Repository
///
public async Task UseTranAsync(Func func)
{
- var res = await Db.AsTenant().UseTranAsync(func);
+ var con = Context;
+ var res = await _Db.AsTenant().UseTranAsync(func);
return res.IsSuccess;
}
@@ -44,7 +44,7 @@ namespace Yi.Framework.Repository
///
public async Task> UseSqlAsync(string sql)
{
- return await Db.Ado.SqlQueryAsync(sql);
+ return await _Db.Ado.SqlQueryAsync(sql);
}
@@ -55,7 +55,7 @@ namespace Yi.Framework.Repository
///
public async Task UseSqlAsync(string sql)
{
- return await Db.Ado.ExecuteCommandAsync(sql)>0;
+ return await _Db.Ado.ExecuteCommandAsync(sql)>0;
}
@@ -68,7 +68,7 @@ namespace Yi.Framework.Repository
public async Task InsertReturnEntityAsync(T entity)
{
entity.Id =SnowFlakeSingle.instance.getID();
- return await Db.Insertable(entity).ExecuteReturnEntityAsync();
+ return await _Db.Insertable(entity).ExecuteReturnEntityAsync();
}
///
@@ -78,7 +78,7 @@ namespace Yi.Framework.Repository
///
public async Task UpdateIgnoreNullAsync(T entity)
{
- return await Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
+ return await _Db.Updateable(entity).IgnoreColumns(true).ExecuteCommandAsync()>0;
}
@@ -88,9 +88,9 @@ namespace Yi.Framework.Repository
///
public async Task DeleteByLogicAsync(List ids)
{
- var entitys = await Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync();
+ var entitys = await _Db.Queryable().Where(u => ids.Contains(u.Id)).ToListAsync();
entitys.ForEach(u=>u.IsDeleted=true);
- return await Db.Updateable(entitys).ExecuteCommandAsync()>0;
+ return await _Db.Updateable(entitys).ExecuteCommandAsync()>0;
}
@@ -103,7 +103,7 @@ namespace Yi.Framework.Repository
///
public async Task> StoreAsync(string storeName, object para)
{
- return await Db.Ado.UseStoredProcedure().SqlQueryAsync(storeName, para);
+ return await _Db.Ado.UseStoredProcedure().SqlQueryAsync(storeName, para);
}
@@ -142,7 +142,7 @@ namespace Yi.Framework.Repository
FieldName = it.Key,
FieldValue = it.Value
}).ToList();
- var query = Db.Queryable();
+ var query = _Db.Queryable();
if (pars.OrderBys != null)
{
foreach (var item in pars.OrderBys)
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
index fd1f93d7..52546893 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
@@ -15,8 +15,7 @@ namespace Yi.Framework.Service
}
public async Task GiveRoleSetMenu(List roleIds, List menuIds)
{
- var _repositoryRoleMenu = _repository.ChangeRepository>();
-
+ var _repositoryRoleMenu= _repository.ChangeRepository>();
//多次操作,需要事务确保原子性
return await _repositoryRoleMenu.UseTranAsync(async () =>
{
@@ -35,12 +34,17 @@ namespace Yi.Framework.Service
}
//一次性批量添加
- await _repositoryRoleMenu.InsertRangeAsync(roleMenuEntity);
+ await _repositoryRoleMenu.InsertReturnSnowflakeIdAsync(roleMenuEntity);
}
});
}
+ public async Task GetInMenuByRoleId(long roleId)
+ {
+ return await _repository._Db.Queryable().Includes(u => u.Menus).InSingleAsync(roleId);
+
+ }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
index c213ff87..886dcf38 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/UserService.cs
@@ -92,7 +92,7 @@ namespace Yi.Framework.Service
}
//一次性批量添加
- await _repositoryUserRole.InsertRangeAsync(userRoleEntities);
+ await _repositoryUserRole.InsertReturnSnowflakeIdAsync(userRoleEntities);
}
});
}
diff --git a/Yi.Vue2.x/src/api/menuApi.js b/Yi.Vue2.x/src/api/menuApi.js
index 3a770bf8..e2235761 100644
--- a/Yi.Vue2.x/src/api/menuApi.js
+++ b/Yi.Vue2.x/src/api/menuApi.js
@@ -26,12 +26,5 @@ export default {
method: 'post',
data: data
})
- },
-
- GetTopMenusByHttpUser() {
- return myaxios({
- url: '/Menu/GetTopMenusByHttpUser',
- method: 'get'
- })
}
}
\ No newline at end of file
diff --git a/Yi.Vue2.x/src/api/roleApi.js b/Yi.Vue2.x/src/api/roleApi.js
index a5af6224..5252affb 100644
--- a/Yi.Vue2.x/src/api/roleApi.js
+++ b/Yi.Vue2.x/src/api/roleApi.js
@@ -1,23 +1,36 @@
import myaxios from '@/util/myaxios'
export default {
- getRole() {
+ getList() {
return myaxios({
- url: '/Role/getRole',
- method: 'get'
- })
- },
- setMenuByRole(roleList, menuList) {
- return myaxios({
- url: '/Role/setMenuByRole',
+ url: '/Role/GetList',
method: 'post',
- data: { ids1: roleList, ids2: menuList }
+ data: {
+ parameters: [
+ {
+ key: "isDeleted",
+ value: "0",
+ type: 0
+
+ }
+ ],
+ orderBys: [
+ "id"
+ ]
+ }
})
},
- GetTopMenusByRoleId(roleId) {
+ giveRoleSetMenu(roleList, menuList) {
return myaxios({
- url: `/Role/GetTopMenusByRoleId?roleId=${roleId}`,
- method: 'get'
+ url: '/Role/GiveRoleSetMenu',
+ method: 'put',
+ data: { RoleIds: roleList, menuIds: menuList }
+ })
+ },
+ getInMenuByRoleId(roleId) {
+ return myaxios({
+ url: `/Role/GetInMenuByRoleId?roleId=${roleId}`,
+ method: 'get'
})
}
diff --git a/Yi.Vue2.x/src/views/AdmRoleMenu.vue b/Yi.Vue2.x/src/views/AdmRoleMenu.vue
index abbfed26..f83cfb3c 100644
--- a/Yi.Vue2.x/src/views/AdmRoleMenu.vue
+++ b/Yi.Vue2.x/src/views/AdmRoleMenu.vue
@@ -6,30 +6,28 @@
角色菜单分配管理 —
你可以在这里多角色分配多菜单/选中一个可查看
-
- 展开全部
- 确定分配
-
- 清空选择
+
+
+ 展开全部
+ 确定分配
+
+ 清空选择
-
-
+
@@ -38,7 +36,7 @@
id:{{ item.id }}
@@ -68,8 +66,12 @@ export default {
selectionRole: {
handler(val, oldVal) {
if (val.length == 1) {
- roleApi.GetTopMenusByRoleId(val[0].id).then((resp) => {
- this.selectionMenu = resp.data;
+ roleApi.getInMenuByRoleId(val[0].id).then((resp) => {
+ if (resp.data.menus == null) {
+ this.selectionMenu = [];
+ } else {
+ this.selectionMenu = resp.data.menus;
+ }
});
}
},
@@ -77,9 +79,9 @@ export default {
},
},
methods: {
- showAll(){
- this.$refs.tree.updateAll(true);
-},
+ showAll() {
+ this.$refs.tree.updateAll(true);
+ },
clear() {
this.selectionMenu = [];
this.selectionRole = [];
@@ -93,20 +95,20 @@ export default {
this.selectionMenu.forEach((ele) => {
menuIds.push(ele.id);
});
- roleApi.setMenuByRole(roleIds, menuIds).then((resp) => {
- this.$dialog.notify.info(resp.msg, {
+ roleApi.giveRoleSetMenu(roleIds, menuIds).then((resp) => {
+ this.$dialog.notify.info(resp.message, {
position: "top-right",
timeout: 5000,
});
});
},
init() {
- roleApi.getRole().then((resp) => {
+ roleApi.getList().then((resp) => {
this.RoleItems = resp.data;
});
- menuApi.GetMenuInMould().then((resp) => {
- this.Menuitems = [resp.data];
+ menuApi.getMenuTree().then((resp) => {
+ this.Menuitems = resp.data;
});
},
},