Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
guns-vip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjunxiong
guns-vip
Commits
2f5298bc
Commit
2f5298bc
authored
May 23, 2017
by
fsn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
菜单添加和修改更加人性化,不需手动输入父级编号和层级
parent
4eec946f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
111 additions
and
25 deletions
+111
-25
src/main/java/com/stylefeng/guns/common/constant/factory/ConstantFactory.java
+18
-0
src/main/java/com/stylefeng/guns/modular/system/controller/MenuController.java
+40
-4
src/main/webapp/WEB-INF/view/system/menu/menu_add.html
+6
-3
src/main/webapp/WEB-INF/view/system/menu/menu_edit.html
+6
-3
src/main/webapp/static/js/common/Feng.js
+8
-2
src/main/webapp/static/modular/system/menu/menu_info.js
+33
-13
No files found.
src/main/java/com/stylefeng/guns/common/constant/factory/ConstantFactory.java
View file @
2f5298bc
...
@@ -160,6 +160,24 @@ public class ConstantFactory {
...
@@ -160,6 +160,24 @@ public class ConstantFactory {
}
}
/**
/**
* 获取菜单名称通过编号
*/
public
String
getMenuNameByCode
(
String
code
)
{
if
(
ToolUtil
.
isEmpty
(
code
))
{
return
""
;
}
else
{
Menu
param
=
new
Menu
();
param
.
setCode
(
code
);
Menu
menu
=
menuMapper
.
selectOne
(
param
);
if
(
menu
==
null
)
{
return
""
;
}
else
{
return
menu
.
getName
();
}
}
}
/**
* 获取字典名称
* 获取字典名称
*/
*/
public
String
getDictName
(
Integer
dictId
){
public
String
getDictName
(
Integer
dictId
){
...
...
src/main/java/com/stylefeng/guns/modular/system/controller/MenuController.java
View file @
2f5298bc
...
@@ -11,13 +11,14 @@ import com.stylefeng.guns.common.controller.BaseController;
...
@@ -11,13 +11,14 @@ import com.stylefeng.guns.common.controller.BaseController;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BizExceptionEnum
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.common.exception.BussinessException
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.common.node.ZTreeNode
;
import
com.stylefeng.guns.common.persistence.dao.MenuMapper
;
import
com.stylefeng.guns.common.persistence.model.Menu
;
import
com.stylefeng.guns.core.log.LogObjectHolder
;
import
com.stylefeng.guns.core.log.LogObjectHolder
;
import
com.stylefeng.guns.core.support.BeanKit
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
com.stylefeng.guns.core.util.ToolUtil
;
import
com.stylefeng.guns.modular.system.dao.MenuDao
;
import
com.stylefeng.guns.modular.system.dao.MenuDao
;
import
com.stylefeng.guns.modular.system.service.IMenuService
;
import
com.stylefeng.guns.modular.system.service.IMenuService
;
import
com.stylefeng.guns.modular.system.warpper.MenuWarpper
;
import
com.stylefeng.guns.modular.system.warpper.MenuWarpper
;
import
com.stylefeng.guns.common.persistence.dao.MenuMapper
;
import
com.stylefeng.guns.common.persistence.model.Menu
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.BindingResult
;
...
@@ -77,7 +78,9 @@ public class MenuController extends BaseController {
...
@@ -77,7 +78,9 @@ public class MenuController extends BaseController {
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
}
Menu
menu
=
this
.
menuMapper
.
selectById
(
menuId
);
Menu
menu
=
this
.
menuMapper
.
selectById
(
menuId
);
model
.
addAttribute
(
menu
);
Map
<
String
,
Object
>
menuMap
=
BeanKit
.
beanToMap
(
menu
);
menuMap
.
put
(
"pcodeName"
,
ConstantFactory
.
me
().
getMenuNameByCode
(
menu
.
getPcode
()));
model
.
addAttribute
(
"menu"
,
menuMap
);
LogObjectHolder
.
me
().
set
(
menu
);
LogObjectHolder
.
me
().
set
(
menu
);
return
PREFIX
+
"menu_edit.html"
;
return
PREFIX
+
"menu_edit.html"
;
}
}
...
@@ -93,6 +96,9 @@ public class MenuController extends BaseController {
...
@@ -93,6 +96,9 @@ public class MenuController extends BaseController {
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
}
//设置父级菜单编号
menuSetPcode
(
menu
);
this
.
menuMapper
.
updateById
(
menu
);
this
.
menuMapper
.
updateById
(
menu
);
return
SUCCESS_TIP
;
return
SUCCESS_TIP
;
}
}
...
@@ -118,6 +124,9 @@ public class MenuController extends BaseController {
...
@@ -118,6 +124,9 @@ public class MenuController extends BaseController {
if
(
result
.
hasErrors
())
{
if
(
result
.
hasErrors
())
{
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
throw
new
BussinessException
(
BizExceptionEnum
.
REQUEST_NULL
);
}
}
//设置父级菜单编号
menuSetPcode
(
menu
);
menu
.
setStatus
(
MenuStatus
.
ENABLE
.
getCode
());
menu
.
setStatus
(
MenuStatus
.
ENABLE
.
getCode
());
this
.
menuMapper
.
insert
(
menu
);
this
.
menuMapper
.
insert
(
menu
);
return
SUCCESS_TIP
;
return
SUCCESS_TIP
;
...
@@ -156,7 +165,7 @@ public class MenuController extends BaseController {
...
@@ -156,7 +165,7 @@ public class MenuController extends BaseController {
}
}
/**
/**
* 获取菜单列表
* 获取菜单列表
(首页用)
*/
*/
@RequestMapping
(
value
=
"/menuTreeList"
)
@RequestMapping
(
value
=
"/menuTreeList"
)
@ResponseBody
@ResponseBody
...
@@ -166,6 +175,17 @@ public class MenuController extends BaseController {
...
@@ -166,6 +175,17 @@ public class MenuController extends BaseController {
}
}
/**
/**
* 获取菜单列表(选择父级菜单用)
*/
@RequestMapping
(
value
=
"/selectMenuTreeList"
)
@ResponseBody
public
List
<
ZTreeNode
>
selectMenuTreeList
()
{
List
<
ZTreeNode
>
roleTreeList
=
this
.
menuDao
.
menuTreeList
();
roleTreeList
.
add
(
ZTreeNode
.
createParent
());
return
roleTreeList
;
}
/**
* 获取角色列表
* 获取角色列表
*/
*/
@RequestMapping
(
value
=
"/menuTreeListByRoleId/{roleId}"
)
@RequestMapping
(
value
=
"/menuTreeListByRoleId/{roleId}"
)
...
@@ -181,4 +201,20 @@ public class MenuController extends BaseController {
...
@@ -181,4 +201,20 @@ public class MenuController extends BaseController {
}
}
}
}
/**
* 根据请求的父级菜单编号设置pcode和层级
*/
private
void
menuSetPcode
(
@Valid
Menu
menu
)
{
if
(
ToolUtil
.
isEmpty
(
menu
.
getPcode
())
||
menu
.
getPcode
().
equals
(
"0"
)){
menu
.
setPcode
(
"0"
);
menu
.
setLevels
(
1
);
}
else
{
int
code
=
Integer
.
parseInt
(
menu
.
getPcode
());
Menu
pMenu
=
menuMapper
.
selectById
(
code
);
Integer
pLevels
=
pMenu
.
getLevels
();
menu
.
setPcode
(
pMenu
.
getCode
());
menu
.
setLevels
(
pLevels
+
1
);
}
}
}
}
src/main/webapp/WEB-INF/view/system/menu/menu_add.html
View file @
2f5298bc
...
@@ -9,13 +9,16 @@
...
@@ -9,13 +9,16 @@
<div
class=
"col-sm-6 b-r"
>
<div
class=
"col-sm-6 b-r"
>
<
#
input
id=
"name"
name=
"名称"
underline=
"true"
/>
<
#
input
id=
"name"
name=
"名称"
underline=
"true"
/>
<
#
input
id=
"code"
name=
"菜单编号"
underline=
"true"
/>
<
#
input
id=
"code"
name=
"菜单编号"
underline=
"true"
/>
<
#
input
id=
"pcode"
name=
"父级编号"
underline=
"true"
/>
<
#
input
id=
"pcodeName"
name=
"父级编号"
underline=
"true"
<
#
input
id=
"icon"
name=
"图标"
underline=
"false"
/>
hidden=
"pcode"
readonly=
"readonly"
clickFun=
"MenuInfoDlg.showMenuSelectTree(); return false;"
style=
"background-color: #ffffff !important;"
selectFlag=
"true"
selectId=
"pcodeTreeDiv"
selectTreeId=
"pcodeTree"
selectStyle=
"width:244px !important;"
/>
</div>
</div>
<div
class=
"col-sm-6"
>
<div
class=
"col-sm-6"
>
<
#
input
id=
"url"
name=
"请求地址"
underline=
"true"
/>
<
#
input
id=
"url"
name=
"请求地址"
underline=
"true"
/>
<
#
input
id=
"num"
name=
"排序"
underline=
"true"
/>
<
#
input
id=
"num"
name=
"排序"
underline=
"true"
/>
<
#
input
id=
"
levels"
name=
"层级
"
underline=
"false"
/>
<
#
input
id=
"
icon"
name=
"图标
"
underline=
"false"
/>
</div>
</div>
</div>
</div>
...
...
src/main/webapp/WEB-INF/view/system/menu/menu_edit.html
View file @
2f5298bc
...
@@ -9,13 +9,16 @@
...
@@ -9,13 +9,16 @@
<div
class=
"col-sm-6 b-r"
>
<div
class=
"col-sm-6 b-r"
>
<
#
input
id=
"name"
name=
"名称"
value=
"${menu.name}"
underline=
"true"
/>
<
#
input
id=
"name"
name=
"名称"
value=
"${menu.name}"
underline=
"true"
/>
<
#
input
id=
"code"
name=
"菜单编号"
value=
"${menu.code}"
underline=
"true"
/>
<
#
input
id=
"code"
name=
"菜单编号"
value=
"${menu.code}"
underline=
"true"
/>
<
#
input
id=
"pcode"
name=
"父级编号"
value=
"${menu.pcode}"
underline=
"true"
/>
<
#
input
id=
"pcodeName"
name=
"父级编号"
value=
"${menu.pcodeName}"
underline=
"true"
<
#
input
id=
"icon"
name=
"图标"
underline=
"false"
value=
"${menu.icon}"
/>
hidden=
"pcode"
readonly=
"readonly"
hiddenValue=
"${menu.pcode}"
clickFun=
"MenuInfoDlg.showMenuSelectTree(); return false;"
style=
"background-color: #ffffff !important;"
selectFlag=
"true"
selectId=
"pcodeTreeDiv"
selectTreeId=
"pcodeTree"
selectStyle=
"width:244px !important;"
/>
</div>
</div>
<div
class=
"col-sm-6"
>
<div
class=
"col-sm-6"
>
<
#
input
id=
"url"
name=
"请求地址"
value=
"${menu.url}"
underline=
"true"
/>
<
#
input
id=
"url"
name=
"请求地址"
value=
"${menu.url}"
underline=
"true"
/>
<
#
input
id=
"num"
name=
"排序"
value=
"${menu.num}"
underline=
"true"
/>
<
#
input
id=
"num"
name=
"排序"
value=
"${menu.num}"
underline=
"true"
/>
<
#
input
id=
"levels"
name=
"层级"
value=
"${menu.levels}"
underline=
"false"
/>
<
#
input
id=
"icon"
name=
"图标"
underline=
"false"
value=
"${menu.icon}"
/>
</div>
</div>
</div>
</div>
...
...
src/main/webapp/static/js/common/Feng.js
View file @
2f5298bc
...
@@ -64,7 +64,7 @@ var Feng = {
...
@@ -64,7 +64,7 @@ var Feng = {
closeBtn
:
0
closeBtn
:
0
});
});
},
},
showInputTree
:
function
(
inputId
,
inputTreeContentId
)
{
showInputTree
:
function
(
inputId
,
inputTreeContentId
,
leftOffset
,
rightOffset
)
{
var
onBodyDown
=
function
(
event
)
{
var
onBodyDown
=
function
(
event
)
{
if
(
!
(
event
.
target
.
id
==
"menuBtn"
||
event
.
target
.
id
==
inputTreeContentId
||
$
(
event
.
target
).
parents
(
"#"
+
inputTreeContentId
).
length
>
0
))
{
if
(
!
(
event
.
target
.
id
==
"menuBtn"
||
event
.
target
.
id
==
inputTreeContentId
||
$
(
event
.
target
).
parents
(
"#"
+
inputTreeContentId
).
length
>
0
))
{
$
(
"#"
+
inputTreeContentId
).
fadeOut
(
"fast"
);
$
(
"#"
+
inputTreeContentId
).
fadeOut
(
"fast"
);
...
@@ -72,13 +72,19 @@ var Feng = {
...
@@ -72,13 +72,19 @@ var Feng = {
}
}
};
};
if
(
leftOffset
==
undefined
&&
rightOffset
==
undefined
){
var
inputDiv
=
$
(
"#"
+
inputId
);
var
inputDiv
=
$
(
"#"
+
inputId
);
var
inputDivOffset
=
$
(
"#"
+
inputId
).
offset
();
var
inputDivOffset
=
$
(
"#"
+
inputId
).
offset
();
$
(
"#"
+
inputTreeContentId
).
css
({
$
(
"#"
+
inputTreeContentId
).
css
({
left
:
inputDivOffset
.
left
+
"px"
,
left
:
inputDivOffset
.
left
+
"px"
,
top
:
inputDivOffset
.
top
+
inputDiv
.
outerHeight
()
+
"px"
top
:
inputDivOffset
.
top
+
inputDiv
.
outerHeight
()
+
"px"
}).
slideDown
(
"fast"
);
}).
slideDown
(
"fast"
);
}
else
{
$
(
"#"
+
inputTreeContentId
).
css
({
left
:
leftOffset
+
"px"
,
top
:
rightOffset
+
"px"
}).
slideDown
(
"fast"
);
}
$
(
"body"
).
bind
(
"mousedown"
,
onBodyDown
);
$
(
"body"
).
bind
(
"mousedown"
,
onBodyDown
);
},
},
...
...
src/main/webapp/static/modular/system/menu/menu_info.js
View file @
2f5298bc
...
@@ -2,13 +2,14 @@
...
@@ -2,13 +2,14 @@
* 菜单详情对话框
* 菜单详情对话框
*/
*/
var
MenuInfoDlg
=
{
var
MenuInfoDlg
=
{
menuInfoData
:
{}
menuInfoData
:
{},
ztreeInstance
:
null
};
};
/**
/**
* 清除数据
* 清除数据
*/
*/
MenuInfoDlg
.
clearData
=
function
()
{
MenuInfoDlg
.
clearData
=
function
()
{
this
.
roleInfoData
=
{};
this
.
roleInfoData
=
{};
}
}
...
@@ -18,7 +19,7 @@ MenuInfoDlg.clearData = function() {
...
@@ -18,7 +19,7 @@ MenuInfoDlg.clearData = function() {
* @param key 数据的名称
* @param key 数据的名称
* @param val 数据的具体值
* @param val 数据的具体值
*/
*/
MenuInfoDlg
.
set
=
function
(
key
,
val
)
{
MenuInfoDlg
.
set
=
function
(
key
,
val
)
{
this
.
roleInfoData
[
key
]
=
(
typeof
value
==
"undefined"
)
?
$
(
"#"
+
key
).
val
()
:
value
;
this
.
roleInfoData
[
key
]
=
(
typeof
value
==
"undefined"
)
?
$
(
"#"
+
key
).
val
()
:
value
;
return
this
;
return
this
;
}
}
...
@@ -29,38 +30,38 @@ MenuInfoDlg.set = function(key, val) {
...
@@ -29,38 +30,38 @@ MenuInfoDlg.set = function(key, val) {
* @param key 数据的名称
* @param key 数据的名称
* @param val 数据的具体值
* @param val 数据的具体值
*/
*/
MenuInfoDlg
.
get
=
function
(
key
)
{
MenuInfoDlg
.
get
=
function
(
key
)
{
return
$
(
"#"
+
key
).
val
();
return
$
(
"#"
+
key
).
val
();
}
}
/**
/**
* 关闭此对话框
* 关闭此对话框
*/
*/
MenuInfoDlg
.
close
=
function
()
{
MenuInfoDlg
.
close
=
function
()
{
parent
.
layer
.
close
(
window
.
parent
.
Menu
.
layerIndex
);
parent
.
layer
.
close
(
window
.
parent
.
Menu
.
layerIndex
);
}
}
/**
/**
* 收集数据
* 收集数据
*/
*/
MenuInfoDlg
.
collectData
=
function
()
{
MenuInfoDlg
.
collectData
=
function
()
{
this
.
set
(
'id'
).
set
(
'name'
).
set
(
'code'
).
set
(
'pcode'
).
set
(
'url'
).
set
(
'num'
).
set
(
'levels'
).
set
(
'icon'
);
this
.
set
(
'id'
).
set
(
'name'
).
set
(
'code'
).
set
(
'pcode'
).
set
(
'url'
).
set
(
'num'
).
set
(
'levels'
).
set
(
'icon'
);
}
}
/**
/**
* 提交添加用户
* 提交添加用户
*/
*/
MenuInfoDlg
.
addSubmit
=
function
()
{
MenuInfoDlg
.
addSubmit
=
function
()
{
this
.
clearData
();
this
.
clearData
();
this
.
collectData
();
this
.
collectData
();
//提交信息
//提交信息
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/menu/add"
,
function
(
data
)
{
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/menu/add"
,
function
(
data
)
{
Feng
.
success
(
"添加成功!"
);
Feng
.
success
(
"添加成功!"
);
window
.
parent
.
Menu
.
table
.
refresh
();
window
.
parent
.
Menu
.
table
.
refresh
();
MenuInfoDlg
.
close
();
MenuInfoDlg
.
close
();
},
function
(
data
)
{
},
function
(
data
)
{
Feng
.
error
(
"添加失败!"
+
data
.
responseJSON
.
message
+
"!"
);
Feng
.
error
(
"添加失败!"
+
data
.
responseJSON
.
message
+
"!"
);
});
});
ajax
.
set
(
this
.
roleInfoData
);
ajax
.
set
(
this
.
roleInfoData
);
...
@@ -70,23 +71,42 @@ MenuInfoDlg.addSubmit = function() {
...
@@ -70,23 +71,42 @@ MenuInfoDlg.addSubmit = function() {
/**
/**
* 提交修改
* 提交修改
*/
*/
MenuInfoDlg
.
editSubmit
=
function
()
{
MenuInfoDlg
.
editSubmit
=
function
()
{
this
.
clearData
();
this
.
clearData
();
this
.
collectData
();
this
.
collectData
();
//提交信息
//提交信息
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/menu/edit"
,
function
(
data
)
{
var
ajax
=
new
$ax
(
Feng
.
ctxPath
+
"/menu/edit"
,
function
(
data
)
{
Feng
.
success
(
"修改成功!"
);
Feng
.
success
(
"修改成功!"
);
window
.
parent
.
Menu
.
table
.
refresh
();
window
.
parent
.
Menu
.
table
.
refresh
();
MenuInfoDlg
.
close
();
MenuInfoDlg
.
close
();
},
function
(
data
)
{
},
function
(
data
)
{
Feng
.
error
(
"修改失败!"
+
data
.
responseJSON
.
message
+
"!"
);
Feng
.
error
(
"修改失败!"
+
data
.
responseJSON
.
message
+
"!"
);
});
});
ajax
.
set
(
this
.
roleInfoData
);
ajax
.
set
(
this
.
roleInfoData
);
ajax
.
start
();
ajax
.
start
();
}
}
$
(
function
()
{
/**
* 点击父级编号input框时
*/
MenuInfoDlg
.
onClickDept
=
function
(
e
,
treeId
,
treeNode
)
{
$
(
"#pcodeName"
).
attr
(
"value"
,
MenuInfoDlg
.
ztreeInstance
.
getSelectedVal
());
$
(
"#pcode"
).
attr
(
"value"
,
treeNode
.
id
);
};
/**
* 显示父级菜单选择的树
*/
MenuInfoDlg
.
showMenuSelectTree
=
function
()
{
Feng
.
showInputTree
(
"pcodeName"
,
"pcodeTreeDiv"
,
15
,
34
);
};
$
(
function
()
{
var
ztree
=
new
$ZTree
(
"pcodeTree"
,
"/menu/selectMenuTreeList"
);
ztree
.
bindOnClick
(
MenuInfoDlg
.
onClickDept
);
ztree
.
init
();
MenuInfoDlg
.
ztreeInstance
=
ztree
;
});
});
Write
Preview
Markdown
is supported
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