diff --git a/common/src/main/java/ink/wgink/common/startup/CommonStartup.java b/common/src/main/java/ink/wgink/common/startup/CommonStartup.java index b2652ba7..417e1f25 100644 --- a/common/src/main/java/ink/wgink/common/startup/CommonStartup.java +++ b/common/src/main/java/ink/wgink/common/startup/CommonStartup.java @@ -25,13 +25,13 @@ import java.util.Map; public class CommonStartup implements ApplicationRunner { private ApplicationContext applicationContext; + @Autowired(required = false) private IInitBaseMenu initBaseMenu; + @Autowired(required = false) private IInitBaseUser initBaseUser; - public CommonStartup(ApplicationContext applicationContext, IInitBaseMenu initBaseMenu, IInitBaseUser initBaseUser) { + public CommonStartup(ApplicationContext applicationContext) { this.applicationContext = applicationContext; - this.initBaseMenu = initBaseMenu; - this.initBaseUser = initBaseUser; } @Override diff --git a/login-oauth2-server/src/main/java/ink/wgink/login/oauth2/server/service/impl/OAuth2ClientMenuServiceImpl.java b/login-oauth2-server/src/main/java/ink/wgink/login/oauth2/server/service/impl/OAuth2ClientMenuServiceImpl.java index 0c9a1a01..be473e6a 100644 --- a/login-oauth2-server/src/main/java/ink/wgink/login/oauth2/server/service/impl/OAuth2ClientMenuServiceImpl.java +++ b/login-oauth2-server/src/main/java/ink/wgink/login/oauth2/server/service/impl/OAuth2ClientMenuServiceImpl.java @@ -2,10 +2,13 @@ package ink.wgink.login.oauth2.server.service.impl; import ink.wgink.common.base.DefaultBaseService; import ink.wgink.exceptions.DependencyException; +import ink.wgink.exceptions.ParamsException; import ink.wgink.interfaces.consts.ISystemConstant; import ink.wgink.interfaces.menu.IMenuBaseService; import ink.wgink.interfaces.role.IRoleMenuBaseService; +import ink.wgink.login.oauth2.server.pojo.pos.OAuth2ClientPO; import ink.wgink.login.oauth2.server.service.IOAuth2ClientMenuService; +import ink.wgink.login.oauth2.server.service.IOAuth2ClientService; import ink.wgink.pojo.dtos.menu.MenuDTO; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -27,6 +30,8 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I private IRoleMenuBaseService roleMenuBaseService; @Autowired(required = false) private IMenuBaseService menuBaseService; + @Autowired + private IOAuth2ClientService oAuth2ClientService; @Override public List list(String clientId, List roleIds) { @@ -36,15 +41,23 @@ public class OAuth2ClientMenuServiceImpl extends DefaultBaseService implements I if (menuBaseService == null) { throw new DependencyException("菜单依赖为引入"); } + OAuth2ClientPO oAuth2ClientPO = oAuth2ClientService.getPO(clientId); + if (StringUtils.isBlank(oAuth2ClientPO.getMenuId())) { + throw new ParamsException("客户端未绑定菜单"); + } List menuIds; if (StringUtils.equals(roleIds.get(0), ISystemConstant.ADMIN)) { // 管理员菜单 menuIds = roleMenuBaseService.listMenuId(ISystemConstant.ADMIN); + // 管理员菜单为空,加载全部 + if (menuIds.isEmpty()) { + return menuBaseService.listAllByParentId(oAuth2ClientPO.getMenuId()); + } } else { // 其他角色菜单 menuIds = roleMenuBaseService.listMenuId(roleIds); } - return menuBaseService.listByIds(menuIds); + return menuBaseService.listAllByParentIdAndIds(oAuth2ClientPO.getMenuId(), menuIds); } } diff --git a/login-oauth2-server/src/main/resources/mybatis/mapper/oauth2-client-mapper.xml b/login-oauth2-server/src/main/resources/mybatis/mapper/oauth2-client-mapper.xml index 04281dd3..fb1e7d02 100644 --- a/login-oauth2-server/src/main/resources/mybatis/mapper/oauth2-client-mapper.xml +++ b/login-oauth2-server/src/main/resources/mybatis/mapper/oauth2-client-mapper.xml @@ -29,6 +29,7 @@ + @@ -229,7 +230,6 @@ t1.client_id, t1.client_name, t1.resource_ids, - t1.client_secret, t1.scope, t1.authorized_grant_types, t1.web_server_redirect_uri, @@ -244,6 +244,7 @@ t1.expire_time, t1.system_summary, t1.system_icon, + t1.menu_id, LEFT(t1.gmt_create, 10) gmt_create FROM oauth_client_details t1 @@ -305,7 +306,6 @@ t1.client_id, t1.client_name, t1.resource_ids, - t1.client_secret, t1.scope, t1.authorized_grant_types, t1.web_server_redirect_uri, @@ -369,6 +369,7 @@ t1.expire_time, t1.system_summary, t1.system_icon, + t1.menu_id, t1.gmt_create, t1.creator, t1.gmt_modified, diff --git a/login-oauth2-server/src/main/resources/templates/oauth2client/list.html b/login-oauth2-server/src/main/resources/templates/oauth2client/list.html index 31ee1b73..329b8606 100644 --- a/login-oauth2-server/src/main/resources/templates/oauth2client/list.html +++ b/login-oauth2-server/src/main/resources/templates/oauth2client/list.html @@ -240,17 +240,16 @@ } // 绑定菜单 function bindMenu(clientId, menuId) { - var params = {}; var message = null; var successMessage = null; - if(typeof(menuId) != 'undefined' && menuId != null && menuId != '') { - params.menuId = menuId; + if(menuId) { message = '确定关联?'; successMessage = '关联成功'; } else { message = top.dataMessage.bind + '绑定后,根节点菜单将自动生成'; successMessage = top.dataMessage.bindSuccess; } + top.dialog.msg(message, { time: 0, btn: [top.dataMessage.button.yes, top.dataMessage.button.no], @@ -258,7 +257,7 @@ yes: function (index) { top.dialog.close(index); var layIndex; - top.restAjax.put(top.restAjax.path('api/oauth2client/update-menu-init/{clientId}', [clientId]), params, null, function (code, data) { + top.restAjax.put(top.restAjax.path('api/oauth2client/update-menu-init/{clientId}?menuId={menuId}', [clientId, menuId]), {}, null, function (code, data) { top.dialog.msg(successMessage, {time: 1000}); reloadTable(); }, function (code, data) { @@ -272,27 +271,20 @@ }); } // 关联菜单 - function contactMenu(clientId) { - var self = this; - top.dialog.tree({ - title: '绑定菜单', - apiUri: top.restAjax.path('api/menu/listztreemenus', []), - width: '250px', + function contactMenu(clientId, menuId) { + top.dialog.open({ + title: '选择菜单', + width: '300px', height: '400px', - dataFilter: function(treeId, parentNode, childNodes) { - return childNodes; - }, + url: top.restAjax.path('route/menu/list-tree-root?menuId={menuId}', [menuId]), onClose: function() { - var selectNodes = top.dialog.dialogTreeData.selectedNodes; - if(typeof(selectNodes) != 'undefined' && selectNodes != null) { - if(selectNodes.length > 0) { - var selectedNode = selectNodes[0]; - var menuId = selectedNode.id; - bindMenu(clientId, menuId); - } + var menuId = top.dialog.dialogData.menuId; + if(!menuId) { + return; } + bindMenu(clientId, menuId); } - }); + }) } // 解绑菜单 function unBindMenu(clientId) { @@ -389,7 +381,7 @@ if(layEvent === 'bindMenu') { bindMenu(data.clientId); } else if(layEvent === 'contactMenu') { - contactMenu(data.clientId); + contactMenu(data.clientId, data.menuId); } else if(layEvent === 'unBindMenu') { unBindMenu(data.clientId); }