Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Eladmin
Commits
d6888471
Commit
d6888471
authored
Aug 27, 2019
by
dqjdda
Browse files
菜单管理功能加强,新增功能项:是否隐藏菜单(某些页面不需要显示在左侧菜单栏中),是否缓存菜单(可解决切换Tab重新渲染的问题,使用该功能必须填写组件名称,且必须与组件中的name一致)
parent
8fc04d4a
Changes
4
Hide whitespace changes
Inline
Side-by-side
eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Menu.java
View file @
d6888471
...
...
@@ -40,6 +40,9 @@ public class Menu implements Serializable {
private
String
component
;
@Column
(
unique
=
true
)
private
String
componentName
;
private
String
icon
;
@Column
(
columnDefinition
=
"bit(1) default 0"
)
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/repository/MenuRepository.java
View file @
d6888471
...
...
@@ -23,6 +23,13 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
*/
Menu
findByName
(
String
name
);
/**
* findByName
* @param name
* @return
*/
Menu
findByComponentName
(
String
name
);
/**
* findByPid
* @param pid
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/MenuDTO.java
View file @
d6888471
...
...
@@ -31,6 +31,8 @@ public class MenuDTO {
private
Boolean
hidden
;
private
String
componentName
;
private
String
icon
;
private
List
<
MenuDTO
>
children
;
...
...
eladmin-system/src/main/java/me/zhengjie/modules/system/service/impl/MenuServiceImpl.java
View file @
d6888471
package
me.zhengjie.modules.system.service.impl
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.StrUtil
;
import
me.zhengjie.modules.system.domain.Menu
;
import
me.zhengjie.modules.system.domain.vo.MenuMetaVo
;
...
...
@@ -13,6 +15,7 @@ import me.zhengjie.modules.system.service.dto.MenuQueryCriteria;
import
me.zhengjie.modules.system.service.dto.RoleSmallDTO
;
import
me.zhengjie.modules.system.service.mapper.MenuMapper
;
import
me.zhengjie.utils.QueryHelp
;
import
me.zhengjie.utils.StringUtils
;
import
me.zhengjie.utils.ValidationUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
...
...
@@ -58,6 +61,11 @@ public class MenuServiceImpl implements MenuService {
if
(
menuRepository
.
findByName
(
resources
.
getName
())
!=
null
){
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
}
if
(
StringUtils
.
isNotBlank
(
resources
.
getComponentName
())){
if
(
menuRepository
.
findByComponentName
(
resources
.
getComponentName
())
!=
null
){
throw
new
EntityExistException
(
Menu
.
class
,
"componentName"
,
resources
.
getComponentName
());
}
}
if
(
resources
.
getIFrame
()){
if
(!(
resources
.
getPath
().
toLowerCase
().
startsWith
(
"http://"
)||
resources
.
getPath
().
toLowerCase
().
startsWith
(
"https://"
)))
{
throw
new
BadRequestException
(
"外链必须以http://或者https://开头"
);
...
...
@@ -85,6 +93,13 @@ public class MenuServiceImpl implements MenuService {
if
(
menu1
!=
null
&&
!
menu1
.
getId
().
equals
(
menu
.
getId
())){
throw
new
EntityExistException
(
Menu
.
class
,
"name"
,
resources
.
getName
());
}
if
(
StringUtils
.
isNotBlank
(
resources
.
getComponentName
())){
menu1
=
menuRepository
.
findByComponentName
(
resources
.
getComponentName
());
if
(
menu1
!=
null
&&
!
menu1
.
getId
().
equals
(
menu
.
getId
())){
throw
new
EntityExistException
(
Menu
.
class
,
"componentName"
,
resources
.
getComponentName
());
}
}
menu
.
setName
(
resources
.
getName
());
menu
.
setComponent
(
resources
.
getComponent
());
menu
.
setPath
(
resources
.
getPath
());
...
...
@@ -94,6 +109,7 @@ public class MenuServiceImpl implements MenuService {
menu
.
setSort
(
resources
.
getSort
());
menu
.
setCache
(
resources
.
getCache
());
menu
.
setHidden
(
resources
.
getHidden
());
menu
.
setComponentName
(
resources
.
getComponentName
());
menuRepository
.
save
(
menu
);
}
...
...
@@ -158,7 +174,7 @@ public class MenuServiceImpl implements MenuService {
if
(
menuDTO
!=
null
){
List
<
MenuDTO
>
menuDTOList
=
menuDTO
.
getChildren
();
MenuVo
menuVo
=
new
MenuVo
();
menuVo
.
setName
(
menuDTO
.
getName
(
));
menuVo
.
setName
(
ObjectUtil
.
isNotEmpty
(
menuDTO
.
getComponentName
())
?
menuDTO
.
getComponentName
()
:
RandomUtil
.
randomString
(
5
));
menuVo
.
setPath
(
menuDTO
.
getPath
());
menuVo
.
setHidden
(
menuDTO
.
getHidden
());
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment