From 6c7b2224b144dccdde02348f0995a24f0b423d53 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Fri, 29 Apr 2022 12:38:19 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E8=A7=92=E8=89=B2=E8=8F=9C?=
=?UTF-8?q?=E5=8D=95=E5=88=86=E9=85=8D=E7=AE=A1=E7=90=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Config/SwaggerDoc.xml | 6 ++
.../Controllers/MenuController.cs | 2 +
.../Controllers/RoleController.cs | 10 +++-
.../Controllers/TestController.cs | 2 +-
.../yi-sqlsugar-dev.db | Bin 102400 -> 102400 bytes
.../Yi.Framework.Interface/IRoleService.cs | 7 +++
.../Yi.Framework.Model/RoleEntity.cs | 2 +
.../Yi.Framework.Repository/DataContext.cs | 27 +++++----
.../Yi.Framework.Repository/Repository.cs | 21 +++----
.../Yi.Framework.Service/RoleService.cs | 15 ++++-
.../Yi.Framework.Service/UserService.cs | 2 +-
Yi.Vue2.x/src/api/menuApi.js | 7 ---
Yi.Vue2.x/src/api/roleApi.js | 37 +++++++++----
Yi.Vue2.x/src/views/AdmRoleMenu.vue | 52 +++++++++---------
14 files changed, 116 insertions(+), 74 deletions(-)
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 9c6a6b2d5e6236c04938bc5245c68645191390c7..bd53f8e88b323293123defaa0e95b3e362f6e82c 100644
GIT binary patch
delta 296
zcmZozz}B#UZGtpo=tLQ3#?Xxki~M<-7?}CKFz{RRZ{Yi~SyAB`pSvqFCz~XLu`>q)
zgQ)PsyN*l(49}PBdp>oJk%5tsu7QcJk(q*_k(HsTm4N|V$Wp=3z{<$n%Fsa1!pzdp
z%)oTAb-X(Z|8oYt&28~@7dV*syBPS7@^@_(G^pdRw`AgCV`F2mW?#TnT-?bi0%LV85tb_-_J)x
delta 63
zcmV-F0Kor%pay`T29O&8Q;{4)0aLMHqE8Ix00R#@01rD4un&T>As{UelRIBW1S|sy
V2D64=e$clB5CQ!kw*gQA|36>Y6K4Pb
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..ddf1d1cf 100644
--- a/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Repository/Repository.cs
@@ -12,7 +12,7 @@ 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; }
///
@@ -31,7 +31,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 +45,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 +56,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 +69,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 +79,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 +89,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 +104,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 +143,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..3def6588 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/RoleService.cs
@@ -9,14 +9,18 @@ namespace Yi.Framework.Service
{
public partial class RoleService
{
+ private IRepository _repositoryRoleMenu;
+ public RoleService(IRepository repository, IRepository repositoryRoleMenu) : base(repository)
+ {
+ _repository = repository;
+ _repositoryRoleMenu = repositoryRoleMenu;
+ }
public async Task> DbTest()
{
return await _repository._Db.Queryable().ToListAsync();
}
public async Task GiveRoleSetMenu(List roleIds, List menuIds)
{
- var _repositoryRoleMenu = _repository.ChangeRepository>();
-
//多次操作,需要事务确保原子性
return await _repositoryRoleMenu.UseTranAsync(async () =>
{
@@ -35,12 +39,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;
});
},
},