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
RuoYi Vue
Commits
5879c248
"vscode:/vscode.git/clone" did not exist on "5295f90990a57b43bd5f9b08a99345acc474345b"
Commit
5879c248
authored
Jul 11, 2021
by
RuoYi
Browse files
菜单路由配置支持内链访问
parent
c02dad2c
Changes
11
Show whitespace changes
Inline
Side-by-side
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysIndexController.java
View file @
5879c248
...
@@ -24,6 +24,6 @@ public class SysIndexController
...
@@ -24,6 +24,6 @@ public class SysIndexController
@RequestMapping
(
"/"
)
@RequestMapping
(
"/"
)
public
String
index
()
public
String
index
()
{
{
return
StringUtils
.
format
(
"欢迎使用
RuoYi
后台管理框架,当前版本:v{}
"
,
ruoyiConfig
.
getVersion
());
return
StringUtils
.
format
(
"欢迎使用
{}
后台管理框架,当前版本:v{}
,请通过前端地址访问。"
,
ruoyiConfig
.
getName
()
,
ruoyiConfig
.
getVersion
());
}
}
}
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysMenuController.java
View file @
5879c248
...
@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody;
...
@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestBody;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ruoyi.common.annotation.Log
;
import
com.ruoyi.common.annotation.Log
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.core.controller.BaseController
;
import
com.ruoyi.common.core.controller.BaseController
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.core.domain.AjaxResult
;
...
@@ -102,8 +101,7 @@ public class SysMenuController extends BaseController
...
@@ -102,8 +101,7 @@ public class SysMenuController extends BaseController
{
{
return
AjaxResult
.
error
(
"新增菜单'"
+
menu
.
getMenuName
()
+
"'失败,菜单名称已存在"
);
return
AjaxResult
.
error
(
"新增菜单'"
+
menu
.
getMenuName
()
+
"'失败,菜单名称已存在"
);
}
}
else
if
(
UserConstants
.
YES_FRAME
.
equals
(
menu
.
getIsFrame
())
else
if
(
UserConstants
.
YES_FRAME
.
equals
(
menu
.
getIsFrame
())
&&
!
StringUtils
.
ishttp
(
menu
.
getPath
()))
&&
!
StringUtils
.
startsWithAny
(
menu
.
getPath
(),
Constants
.
HTTP
,
Constants
.
HTTPS
))
{
{
return
AjaxResult
.
error
(
"新增菜单'"
+
menu
.
getMenuName
()
+
"'失败,地址必须以http(s)://开头"
);
return
AjaxResult
.
error
(
"新增菜单'"
+
menu
.
getMenuName
()
+
"'失败,地址必须以http(s)://开头"
);
}
}
...
@@ -123,8 +121,7 @@ public class SysMenuController extends BaseController
...
@@ -123,8 +121,7 @@ public class SysMenuController extends BaseController
{
{
return
AjaxResult
.
error
(
"修改菜单'"
+
menu
.
getMenuName
()
+
"'失败,菜单名称已存在"
);
return
AjaxResult
.
error
(
"修改菜单'"
+
menu
.
getMenuName
()
+
"'失败,菜单名称已存在"
);
}
}
else
if
(
UserConstants
.
YES_FRAME
.
equals
(
menu
.
getIsFrame
())
else
if
(
UserConstants
.
YES_FRAME
.
equals
(
menu
.
getIsFrame
())
&&
!
StringUtils
.
ishttp
(
menu
.
getPath
()))
&&
!
StringUtils
.
startsWithAny
(
menu
.
getPath
(),
Constants
.
HTTP
,
Constants
.
HTTPS
))
{
{
return
AjaxResult
.
error
(
"修改菜单'"
+
menu
.
getMenuName
()
+
"'失败,地址必须以http(s)://开头"
);
return
AjaxResult
.
error
(
"修改菜单'"
+
menu
.
getMenuName
()
+
"'失败,地址必须以http(s)://开头"
);
}
}
...
...
ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java
View file @
5879c248
...
@@ -57,6 +57,9 @@ public class UserConstants
...
@@ -57,6 +57,9 @@ public class UserConstants
/** ParentView组件标识 */
/** ParentView组件标识 */
public
final
static
String
PARENT_VIEW
=
"ParentView"
;
public
final
static
String
PARENT_VIEW
=
"ParentView"
;
/** InnerLink组件标识 */
public
final
static
String
INNER_LINK
=
"InnerLink"
;
/** 校验返回结果码 */
/** 校验返回结果码 */
public
final
static
String
UNIQUE
=
"0"
;
public
final
static
String
UNIQUE
=
"0"
;
public
final
static
String
NOT_UNIQUE
=
"1"
;
public
final
static
String
NOT_UNIQUE
=
"1"
;
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java
View file @
5879c248
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.core.text.StrFormatter
;
import
com.ruoyi.common.core.text.StrFormatter
;
/**
/**
...
@@ -260,6 +261,17 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
...
@@ -260,6 +261,17 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
return
StrFormatter
.
format
(
template
,
params
);
return
StrFormatter
.
format
(
template
,
params
);
}
}
/**
* 是否为http(s)://开头
*
* @param link 链接
* @return 结果
*/
public
static
boolean
ishttp
(
String
link
)
{
return
StringUtils
.
startsWithAny
(
link
,
Constants
.
HTTP
,
Constants
.
HTTPS
);
}
/**
/**
* 字符串转set
* 字符串转set
*
*
...
...
ruoyi-system/src/main/java/com/ruoyi/system/domain/vo/MetaVo.java
View file @
5879c248
package
com.ruoyi.system.domain.vo
;
package
com.ruoyi.system.domain.vo
;
import
com.ruoyi.common.utils.StringUtils
;
/**
/**
* 路由显示信息
* 路由显示信息
*
*
...
@@ -22,6 +24,11 @@ public class MetaVo
...
@@ -22,6 +24,11 @@ public class MetaVo
*/
*/
private
boolean
noCache
;
private
boolean
noCache
;
/**
* 内链地址(http(s)://开头)
*/
private
String
link
;
public
MetaVo
()
public
MetaVo
()
{
{
}
}
...
@@ -39,6 +46,24 @@ public class MetaVo
...
@@ -39,6 +46,24 @@ public class MetaVo
this
.
noCache
=
noCache
;
this
.
noCache
=
noCache
;
}
}
public
MetaVo
(
String
title
,
String
icon
,
String
link
)
{
this
.
title
=
title
;
this
.
icon
=
icon
;
this
.
link
=
link
;
}
public
MetaVo
(
String
title
,
String
icon
,
boolean
noCache
,
String
link
)
{
this
.
title
=
title
;
this
.
icon
=
icon
;
this
.
noCache
=
noCache
;
if
(
StringUtils
.
ishttp
(
link
))
{
this
.
link
=
link
;
}
}
public
boolean
isNoCache
()
public
boolean
isNoCache
()
{
{
return
noCache
;
return
noCache
;
...
@@ -68,4 +93,14 @@ public class MetaVo
...
@@ -68,4 +93,14 @@ public class MetaVo
{
{
this
.
icon
=
icon
;
this
.
icon
=
icon
;
}
}
public
String
getLink
()
{
return
link
;
}
public
void
setLink
(
String
link
)
{
this
.
link
=
link
;
}
}
}
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
View file @
5879c248
...
@@ -10,6 +10,7 @@ import java.util.Set;
...
@@ -10,6 +10,7 @@ import java.util.Set;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.constant.UserConstants
;
import
com.ruoyi.common.core.domain.TreeSelect
;
import
com.ruoyi.common.core.domain.TreeSelect
;
import
com.ruoyi.common.core.domain.entity.SysMenu
;
import
com.ruoyi.common.core.domain.entity.SysMenu
;
...
@@ -150,7 +151,7 @@ public class SysMenuServiceImpl implements ISysMenuService
...
@@ -150,7 +151,7 @@ public class SysMenuServiceImpl implements ISysMenuService
router
.
setName
(
getRouteName
(
menu
));
router
.
setName
(
getRouteName
(
menu
));
router
.
setPath
(
getRouterPath
(
menu
));
router
.
setPath
(
getRouterPath
(
menu
));
router
.
setComponent
(
getComponent
(
menu
));
router
.
setComponent
(
getComponent
(
menu
));
router
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
(),
StringUtils
.
equals
(
"1"
,
menu
.
getIsCache
())));
router
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
(),
StringUtils
.
equals
(
"1"
,
menu
.
getIsCache
())
,
menu
.
getPath
()
));
List
<
SysMenu
>
cMenus
=
menu
.
getChildren
();
List
<
SysMenu
>
cMenus
=
menu
.
getChildren
();
if
(!
cMenus
.
isEmpty
()
&&
cMenus
.
size
()
>
0
&&
UserConstants
.
TYPE_DIR
.
equals
(
menu
.
getMenuType
()))
if
(!
cMenus
.
isEmpty
()
&&
cMenus
.
size
()
>
0
&&
UserConstants
.
TYPE_DIR
.
equals
(
menu
.
getMenuType
()))
{
{
...
@@ -166,7 +167,21 @@ public class SysMenuServiceImpl implements ISysMenuService
...
@@ -166,7 +167,21 @@ public class SysMenuServiceImpl implements ISysMenuService
children
.
setPath
(
menu
.
getPath
());
children
.
setPath
(
menu
.
getPath
());
children
.
setComponent
(
menu
.
getComponent
());
children
.
setComponent
(
menu
.
getComponent
());
children
.
setName
(
StringUtils
.
capitalize
(
menu
.
getPath
()));
children
.
setName
(
StringUtils
.
capitalize
(
menu
.
getPath
()));
children
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
(),
StringUtils
.
equals
(
"1"
,
menu
.
getIsCache
())));
children
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
(),
StringUtils
.
equals
(
"1"
,
menu
.
getIsCache
()),
menu
.
getPath
()));
childrenList
.
add
(
children
);
router
.
setChildren
(
childrenList
);
}
else
if
(
menu
.
getParentId
().
intValue
()
==
0
&&
isInnerLink
(
menu
))
{
router
.
setMeta
(
null
);
router
.
setPath
(
"/inner"
);
List
<
RouterVo
>
childrenList
=
new
ArrayList
<
RouterVo
>();
RouterVo
children
=
new
RouterVo
();
String
routerPath
=
StringUtils
.
replaceEach
(
menu
.
getPath
(),
new
String
[]
{
Constants
.
HTTP
,
Constants
.
HTTPS
},
new
String
[]
{
""
,
""
});
children
.
setPath
(
routerPath
);
children
.
setComponent
(
UserConstants
.
INNER_LINK
);
children
.
setName
(
StringUtils
.
capitalize
(
routerPath
));
children
.
setMeta
(
new
MetaVo
(
menu
.
getMenuName
(),
menu
.
getIcon
(),
menu
.
getPath
()));
childrenList
.
add
(
children
);
childrenList
.
add
(
children
);
router
.
setChildren
(
childrenList
);
router
.
setChildren
(
childrenList
);
}
}
...
@@ -338,6 +353,11 @@ public class SysMenuServiceImpl implements ISysMenuService
...
@@ -338,6 +353,11 @@ public class SysMenuServiceImpl implements ISysMenuService
public
String
getRouterPath
(
SysMenu
menu
)
public
String
getRouterPath
(
SysMenu
menu
)
{
{
String
routerPath
=
menu
.
getPath
();
String
routerPath
=
menu
.
getPath
();
// 内链打开外网方式
if
(
menu
.
getParentId
().
intValue
()
!=
0
&&
isInnerLink
(
menu
))
{
routerPath
=
StringUtils
.
replaceEach
(
routerPath
,
new
String
[]
{
Constants
.
HTTP
,
Constants
.
HTTPS
},
new
String
[]
{
""
,
""
});
}
// 非外链并且是一级目录(类型为目录)
// 非外链并且是一级目录(类型为目录)
if
(
0
==
menu
.
getParentId
().
intValue
()
&&
UserConstants
.
TYPE_DIR
.
equals
(
menu
.
getMenuType
())
if
(
0
==
menu
.
getParentId
().
intValue
()
&&
UserConstants
.
TYPE_DIR
.
equals
(
menu
.
getMenuType
())
&&
UserConstants
.
NO_FRAME
.
equals
(
menu
.
getIsFrame
()))
&&
UserConstants
.
NO_FRAME
.
equals
(
menu
.
getIsFrame
()))
...
@@ -365,6 +385,10 @@ public class SysMenuServiceImpl implements ISysMenuService
...
@@ -365,6 +385,10 @@ public class SysMenuServiceImpl implements ISysMenuService
{
{
component
=
menu
.
getComponent
();
component
=
menu
.
getComponent
();
}
}
else
if
(
StringUtils
.
isEmpty
(
menu
.
getComponent
())
&&
menu
.
getParentId
().
intValue
()
!=
0
&&
isInnerLink
(
menu
))
{
component
=
UserConstants
.
INNER_LINK
;
}
else
if
(
StringUtils
.
isEmpty
(
menu
.
getComponent
())
&&
isParentView
(
menu
))
else
if
(
StringUtils
.
isEmpty
(
menu
.
getComponent
())
&&
isParentView
(
menu
))
{
{
component
=
UserConstants
.
PARENT_VIEW
;
component
=
UserConstants
.
PARENT_VIEW
;
...
@@ -384,6 +408,17 @@ public class SysMenuServiceImpl implements ISysMenuService
...
@@ -384,6 +408,17 @@ public class SysMenuServiceImpl implements ISysMenuService
&&
menu
.
getIsFrame
().
equals
(
UserConstants
.
NO_FRAME
);
&&
menu
.
getIsFrame
().
equals
(
UserConstants
.
NO_FRAME
);
}
}
/**
* 是否为内链组件
*
* @param menu 菜单信息
* @return 结果
*/
public
boolean
isInnerLink
(
SysMenu
menu
)
{
return
menu
.
getIsFrame
().
equals
(
UserConstants
.
NO_FRAME
)
&&
StringUtils
.
ishttp
(
menu
.
getPath
());
}
/**
/**
* 是否为parent_view组件
* 是否为parent_view组件
*
*
...
...
ruoyi-ui/src/components/HeaderSearch/index.vue
View file @
5879c248
...
@@ -70,9 +70,11 @@ export default {
...
@@ -70,9 +70,11 @@ export default {
this
.
show
=
false
this
.
show
=
false
},
},
change
(
val
)
{
change
(
val
)
{
const
path
=
val
.
path
;
if
(
this
.
ishttp
(
val
.
path
))
{
if
(
this
.
ishttp
(
val
.
path
))
{
// http(s):// 路径新窗口打开
// http(s):// 路径新窗口打开
window
.
open
(
val
.
path
,
"
_blank
"
);
const
pindex
=
path
.
indexOf
(
"
http
"
);
window
.
open
(
path
.
substr
(
pindex
,
path
.
length
),
"
_blank
"
);
}
else
{
}
else
{
this
.
$router
.
push
(
val
.
path
)
this
.
$router
.
push
(
val
.
path
)
}
}
...
...
ruoyi-ui/src/layout/components/AppMain.vue
View file @
5879c248
...
@@ -51,7 +51,7 @@ export default {
...
@@ -51,7 +51,7 @@ export default {
// fix css style bug in open el-dialog
// fix css style bug in open el-dialog
.el-popup-parent--hidden
{
.el-popup-parent--hidden
{
.fixed-header
{
.fixed-header
{
padding-right
:
1
5
px
;
padding-right
:
1
7
px
;
}
}
}
}
</
style
>
</
style
>
ruoyi-ui/src/layout/components/InnerLink/index.vue
0 → 100644
View file @
5879c248
<
script
>
export
default
{
data
()
{
return
{};
},
render
()
{
const
{
$route
:
{
meta
:
{
link
}
},
}
=
this
;
if
({
link
}.
link
===
""
)
{
return
"
404
"
;
}
let
url
=
{
link
}.
link
;
const
height
=
document
.
documentElement
.
clientHeight
-
94.5
+
"
px
"
;
const
style
=
{
height
:
height
};
return
(
<
div
style
=
{
style
}
>
<
iframe
src
=
{
url
}
frameborder
=
"
no
"
style
=
"
width: 100%; height: 100%
"
scrolling
=
"
auto
"
><
/iframe>
<
/div>
);
},
};
</
script
>
ruoyi-ui/src/router/index.js
View file @
5879c248
...
@@ -6,6 +6,7 @@ Vue.use(Router)
...
@@ -6,6 +6,7 @@ Vue.use(Router)
/* Layout */
/* Layout */
import
Layout
from
'
@/layout
'
import
Layout
from
'
@/layout
'
import
ParentView
from
'
@/components/ParentView
'
;
import
ParentView
from
'
@/components/ParentView
'
;
import
InnerLink
from
'
@/layout/components/InnerLink
'
/**
/**
* Note: 路由配置项
* Note: 路由配置项
...
...
ruoyi-ui/src/store/modules/permission.js
View file @
5879c248
...
@@ -2,6 +2,7 @@ import { constantRoutes } from '@/router'
...
@@ -2,6 +2,7 @@ import { constantRoutes } from '@/router'
import
{
getRouters
}
from
'
@/api/menu
'
import
{
getRouters
}
from
'
@/api/menu
'
import
Layout
from
'
@/layout/index
'
import
Layout
from
'
@/layout/index
'
import
ParentView
from
'
@/components/ParentView
'
;
import
ParentView
from
'
@/components/ParentView
'
;
import
InnerLink
from
'
@/layout/components/InnerLink
'
const
permission
=
{
const
permission
=
{
state
:
{
state
:
{
...
@@ -65,6 +66,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
...
@@ -65,6 +66,8 @@ function filterAsyncRouter(asyncRouterMap, lastRouter = false, type = false) {
route
.
component
=
Layout
route
.
component
=
Layout
}
else
if
(
route
.
component
===
'
ParentView
'
)
{
}
else
if
(
route
.
component
===
'
ParentView
'
)
{
route
.
component
=
ParentView
route
.
component
=
ParentView
}
else
if
(
route
.
component
===
'
InnerLink
'
)
{
route
.
component
=
InnerLink
}
else
{
}
else
{
route
.
component
=
loadView
(
route
.
component
)
route
.
component
=
loadView
(
route
.
component
)
}
}
...
...
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