Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
2ef5dc69
G
gin-vue-admin
项目概览
nizhengjia888
/
gin-vue-admin
与 Fork 源项目一致
Fork自
FLIPPED-AURORA / gin-vue-admin
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ef5dc69
编写于
9月 26, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
菜单编辑功能 api关联模式变更后台相关
上级
8f558cbb
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
87 addition
and
24 deletion
+87
-24
QMPlusServer/controller/api/menu.go
QMPlusServer/controller/api/menu.go
+21
-2
QMPlusServer/model/dbModel/api.go
QMPlusServer/model/dbModel/api.go
+0
-1
QMPlusServer/model/dbModel/api_authority.go
QMPlusServer/model/dbModel/api_authority.go
+16
-10
QMPlusServer/model/dbModel/baseMenu.go
QMPlusServer/model/dbModel/baseMenu.go
+17
-6
QMPlusServer/model/dbModel/menu_authority.go
QMPlusServer/model/dbModel/menu_authority.go
+1
-0
QMPlusServer/router/menu.go
QMPlusServer/router/menu.go
+2
-1
QMPlusVuePage/src/api/menu.js
QMPlusVuePage/src/api/menu.js
+15
-2
QMPlusVuePage/src/view/superAdmin/menu/menu.vue
QMPlusVuePage/src/view/superAdmin/menu/menu.vue
+15
-2
未找到文件。
QMPlusServer/controller/api/menu.go
浏览文件 @
2ef5dc69
...
...
@@ -52,11 +52,11 @@ func GetMenuList(c *gin.Context) {
}
// @Tags menu
// @Summary
分页获取基础menu列表
// @Summary
新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body
modelInterface.PageInfo true "分页获取基础menu列表
"
// @Param data body
dbModel.BaseMenu true "新增菜单
"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/addBaseMenu [post]
func
AddBaseMenu
(
c
*
gin
.
Context
)
{
...
...
@@ -155,3 +155,22 @@ func DeleteBaseMenu(c *gin.Context) {
servers
.
ReportFormat
(
c
,
true
,
"删除成功"
,
gin
.
H
{})
}
}
// @Tags menu
// @Summary 新增菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body dbModel.BaseMenu true "新增菜单"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/updataBaseMen [post]
func
UpdataBaseMenu
(
c
*
gin
.
Context
)
{
var
menu
dbModel
.
BaseMenu
_
=
c
.
BindJSON
(
&
menu
)
err
:=
menu
.
UpdataBaseMenu
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"修改失败:%v"
,
err
),
gin
.
H
{})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
"修改成功"
,
gin
.
H
{})
}
}
QMPlusServer/model/dbModel/api.go
浏览文件 @
2ef5dc69
...
...
@@ -31,7 +31,6 @@ func (a *Api) DeleteApi() (err error) {
func
(
a
*
Api
)
EditApi
()
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Update
(
a
)
.
Error
err
=
qmsql
.
DEFAULTDB
.
Where
(
"path = ?"
,
a
.
Path
)
.
Update
(
"path"
,
a
.
Path
)
.
Error
return
err
}
...
...
QMPlusServer/model/dbModel/api_authority.go
浏览文件 @
2ef5dc69
package
dbModel
import
"main/init/qmsql"
import
(
"fmt"
"github.com/jinzhu/gorm"
"main/init/qmsql"
)
type
ApiAuthority
struct
{
AuthorityId
string
`json:"-"`
Path
string
`json:"_"`
gorm
.
Model
AuthorityId
string
Authority
Authority
`gorm:"ForeignKey:AuthorityId;AssociationForeignKey:AuthorityId"`
//其实没有关联的必要
ApiId
string
Api
Api
}
//创建角色api关联关系
func
(
a
*
ApiAuthority
)
SetAuthAndPath
(
authId
string
,
apis
[]
Api
)(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"authority_id = ?"
,
authId
)
.
Delete
(
&
ApiAuthority
{})
.
Error
for
_
,
v
:=
range
apis
{
err
=
qmsql
.
DEFAULTDB
.
Create
(
&
ApiAuthority
{
AuthorityId
:
authId
,
Path
:
v
.
Path
})
.
Error
if
(
err
!=
nil
)
{
func
(
a
*
ApiAuthority
)
SetAuthAndPath
(
authId
string
,
apis
[]
Api
)
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"authority_id = ?"
,
authId
)
.
Delete
(
&
ApiAuthority
{})
.
Error
for
_
,
v
:=
range
apis
{
err
=
qmsql
.
DEFAULTDB
.
Create
(
&
ApiAuthority
{
AuthorityId
:
authId
,
ApiId
:
fmt
.
Sprintf
(
"%v"
,
v
.
ID
)
})
.
Error
if
err
!=
nil
{
return
err
}
}
return
nil
}
\ No newline at end of file
}
QMPlusServer/model/dbModel/baseMenu.go
浏览文件 @
2ef5dc69
package
dbModel
import
(
"fmt"
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
"main/controller/servers"
...
...
@@ -33,18 +34,28 @@ func (b *BaseMenu) AddBaseMenu() (err error) {
}
func
(
b
*
BaseMenu
)
DeleteBaseMenu
(
id
float64
)
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"parent_id = ?"
,
id
)
.
First
(
&
BaseMenu
{})
.
Error
if
(
err
!=
nil
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"parent_id = ?"
,
id
)
.
First
(
&
BaseMenu
{})
.
Error
if
err
!=
nil
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"id = ?"
,
id
)
.
Delete
(
&
b
)
.
Error
err
=
qmsql
.
DEFAULTDB
.
Where
(
"menu_id = ?"
,
id
)
.
Delete
(
&
Menu
{})
.
Error
}
else
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"menu_id = ?"
,
id
)
.
Unscoped
()
.
Delete
(
&
Menu
{})
.
Error
}
else
{
return
errors
.
New
(
"此菜单存在子菜单不可删除"
)
}
return
err
}
func
(
b
*
BaseMenu
)
UpdataBaseMenu
(
name
string
)
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"name = ?"
,
name
)
.
Update
(
&
b
)
.
Update
(
&
Menu
{})
.
Error
func
(
b
*
BaseMenu
)
UpdataBaseMenu
()
(
err
error
)
{
upDataMap
:=
make
(
map
[
string
]
interface
{})
upDataMap
[
"parentId"
]
=
b
.
ParentId
upDataMap
[
"path"
]
=
b
.
Path
upDataMap
[
"name"
]
=
b
.
Name
upDataMap
[
"hidden"
]
=
b
.
Hidden
upDataMap
[
"component"
]
=
b
.
Component
upDataMap
[
"title"
]
=
b
.
Title
upDataMap
[
"icon"
]
=
b
.
Icon
err
=
qmsql
.
DEFAULTDB
.
Where
(
"id = ?"
,
b
.
ID
)
.
Find
(
&
BaseMenu
{})
.
Updates
(
upDataMap
)
.
Error
err1
:=
qmsql
.
DEFAULTDB
.
Where
(
"menu_id = ?"
,
b
.
ID
)
.
Find
(
&
Menu
{})
.
Updates
(
upDataMap
)
.
Error
fmt
.
Printf
(
"菜单修改时候,关联菜单err:%v"
,
err1
)
return
err
}
...
...
QMPlusServer/model/dbModel/menu_authority.go
浏览文件 @
2ef5dc69
...
...
@@ -5,6 +5,7 @@ import (
"main/init/qmsql"
)
// menu需要构建的点有点多 这里关联关系表直接把所有数据拿过来 用代码实现关联 后期实现主外键模式
type
Menu
struct
{
BaseMenu
MenuId
string
`json:"menuId"`
...
...
QMPlusServer/router/menu.go
浏览文件 @
2ef5dc69
...
...
@@ -15,6 +15,7 @@ func InitMenuRouter(Router *gin.Engine) {
MenuRouter
.
POST
(
"getBaseMenuTree"
,
api
.
GetBaseMenuTree
)
MenuRouter
.
POST
(
"addMenuAuthority"
,
api
.
AddMenuAuthority
)
MenuRouter
.
POST
(
"getMenuAuthority"
,
api
.
GetMenuAuthority
)
MenuRouter
.
POST
(
"deleteBaseMenu"
,
api
.
DeleteBaseMenu
)
MenuRouter
.
POST
(
"deleteBaseMenu"
,
api
.
DeleteBaseMenu
)
MenuRouter
.
POST
(
"updataBaseMenu"
,
api
.
UpdataBaseMenu
)
}
}
QMPlusVuePage/src/api/menu.js
浏览文件 @
2ef5dc69
import
service
from
'
@/utils/request
'
// @Summary 用户登录
// @Summary 用户登录
获取动态路由
// @Produce application/json
// @Param 可以什么都不填 调一下即可
// @Router /menu/getMenu [post]
...
...
@@ -27,7 +27,7 @@ export const getMenuList = (data) => {
}
// @Summary
获取menu列表
// @Summary
新增基础menu
// @Produce application/json
// @Param menu Object
// @Router /menu/getMenuList [post]
...
...
@@ -84,4 +84,17 @@ export const deleteBaseMenu = (data) => {
method
:
'
post
'
,
data
})
}
// @Summary 修改menu列表
// @Produce application/json
// @Param menu Object
// @Router /menu/updataBaseMenu [post]
export
const
updataBaseMenu
=
(
data
)
=>
{
return
service
({
url
:
"
/menu/updataBaseMenu
"
,
method
:
'
post
'
,
data
})
}
\ No newline at end of file
QMPlusVuePage/src/view/superAdmin/menu/menu.vue
浏览文件 @
2ef5dc69
...
...
@@ -27,6 +27,7 @@
<el-table-column
fixed=
"right"
label=
"操作"
width=
"300"
>
<
template
slot-scope=
"scope"
>
<el-button
@
click=
"deleteMenu(scope.row.ID)"
size=
"small"
type=
"text"
>
删除菜单
</el-button>
<el-button
@
click=
"editMenu(scope.row)"
size=
"small"
type=
"text"
>
编辑菜单
</el-button>
<el-button
@
click=
"addMenu(scope.row.ID)"
size=
"small"
type=
"text"
>
添加子菜单
</el-button>
</
template
>
</el-table-column>
...
...
@@ -81,7 +82,7 @@
<
script
>
// 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
import
{
getMenuList
,
addBaseMenu
,
deleteBaseMenu
}
from
'
@/api/menu
'
import
{
updataBaseMenu
,
getMenuList
,
addBaseMenu
,
deleteBaseMenu
}
from
'
@/api/menu
'
import
infoList
from
'
@/view/superAdmin/mixins/infoList
'
export
default
{
name
:
'
Menus
'
,
...
...
@@ -105,6 +106,7 @@ export default {
}
},
methods
:
{
// 删除菜单
deleteMenu
(
ID
)
{
this
.
$confirm
(
'
此操作将永久删除所有角色下该菜单, 是否继续?
'
,
'
提示
'
,
{
confirmButtonText
:
'
确定
'
,
...
...
@@ -128,6 +130,7 @@ export default {
})
})
},
// 初始化弹窗内表格方法
initForm
()
{
this
.
form
=
{
path
:
''
,
...
...
@@ -141,10 +144,12 @@ export default {
}
}
},
// 关闭弹窗
closeDialog
()
{
this
.
initForm
()
this
.
dialogFormVisible
=
false
},
// 添加menu
async
enterDialog
()
{
const
res
=
await
addBaseMenu
(
this
.
form
)
if
(
res
.
success
)
{
...
...
@@ -164,11 +169,19 @@ export default {
this
.
initForm
()
this
.
dialogFormVisible
=
false
},
// 添加菜单方法,id为 0则为添加根菜单
addMenu
(
id
)
{
this
.
form
.
parentId
=
String
(
id
)
this
.
dialogFormVisible
=
true
},
// 修改菜单方法
async
editMenu
(
row
){
row
.
name
=
"
修改测试
"
row
.
meta
.
title
=
"
修改测试
"
row
.
meta
.
icon
=
"
share
"
const
res
=
await
updataBaseMenu
(
row
)
console
.
log
(
res
)
}
}
}
</
script
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录