Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
nizhengjia888
gin-vue-admin
提交
20ab5a8d
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,发现更多精彩内容 >>
提交
20ab5a8d
编写于
1月 18, 2020
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
api 增加 GET PUT DELETE POST 四种可选声明方式
上级
f7a1fdd0
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
93 addition
and
33 deletion
+93
-33
QMPlusServer/controller/api/sys_casbin.go
QMPlusServer/controller/api/sys_casbin.go
+4
-9
QMPlusServer/model/sysModel/sys_api.go
QMPlusServer/model/sysModel/sys_api.go
+1
-0
QMPlusServer/model/sysModel/sys_casbin.go
QMPlusServer/model/sysModel/sys_casbin.go
+16
-4
QMPlusVuePage/src/view/superAdmin/api/api.vue
QMPlusVuePage/src/view/superAdmin/api/api.vue
+62
-18
QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue
...VuePage/src/view/superAdmin/authority/components/apis.vue
+10
-2
未找到文件。
QMPlusServer/controller/api/sys_casbin.go
浏览文件 @
20ab5a8d
...
...
@@ -7,23 +7,18 @@ import (
"github.com/gin-gonic/gin"
)
type
CasbinInReceive
struct
{
AuthorityId
string
`json:"authorityId"`
Paths
[]
string
`json:paths`
}
// @Tags casbin
// @Summary 更改角色api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body
api.CreateAuthorityParams
true "更改角色api权限"
// @Param data body
sysModel.CasbinInReceive
true "更改角色api权限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/casbinPUpdata [post]
func
CasbinPUpdata
(
c
*
gin
.
Context
)
{
var
cmr
CasbinInReceive
var
cmr
sysModel
.
CasbinInReceive
_
=
c
.
ShouldBind
(
&
cmr
)
err
:=
new
(
sysModel
.
CasbinModel
)
.
CasbinPUpdata
(
cmr
.
AuthorityId
,
cmr
.
Path
s
)
err
:=
new
(
sysModel
.
CasbinModel
)
.
CasbinPUpdata
(
cmr
.
AuthorityId
,
cmr
.
CasbinInfo
s
)
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"添加规则失败,%v"
,
err
),
gin
.
H
{})
}
else
{
...
...
@@ -40,7 +35,7 @@ func CasbinPUpdata(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /casbin/getPolicyPathByAuthorityId [post]
func
GetPolicyPathByAuthorityId
(
c
*
gin
.
Context
)
{
var
cmr
CasbinInReceive
var
cmr
sysModel
.
CasbinInReceive
_
=
c
.
ShouldBind
(
&
cmr
)
paths
:=
new
(
sysModel
.
CasbinModel
)
.
GetPolicyPathByAuthorityId
(
cmr
.
AuthorityId
)
servers
.
ReportFormat
(
c
,
true
,
"获取规则成功"
,
gin
.
H
{
"paths"
:
paths
})
...
...
QMPlusServer/model/sysModel/sys_api.go
浏览文件 @
20ab5a8d
...
...
@@ -13,6 +13,7 @@ type SysApi struct {
Path
string
`json:"path"`
Description
string
`json:"description"`
Group
string
`json:"group"`
Method
string
`json:"method" gorm:"default:'POST'"`
}
func
(
a
*
SysApi
)
CreateApi
()
(
err
error
)
{
...
...
QMPlusServer/model/sysModel/sys_casbin.go
浏览文件 @
20ab5a8d
...
...
@@ -17,16 +17,28 @@ type CasbinModel struct {
Method
string
`json:"method" gorm:"column:v2"`
}
// 供入参使用
type
CasbinInfo
struct
{
Path
string
`json:"path"`
Method
string
`json:"method"`
}
// 供入参使用
type
CasbinInReceive
struct
{
AuthorityId
string
`json:"authorityId"`
CasbinInfos
[]
CasbinInfo
`json:"casbinInfos"`
}
// 更新权限
func
(
c
*
CasbinModel
)
CasbinPUpdata
(
AuthorityId
string
,
Paths
[]
string
)
error
{
func
(
c
*
CasbinModel
)
CasbinPUpdata
(
AuthorityId
string
,
casbinInfos
[]
CasbinInfo
)
error
{
c
.
clearCasbin
(
0
,
AuthorityId
)
for
_
,
v
:=
range
Path
s
{
for
_
,
v
:=
range
casbinInfo
s
{
cm
:=
CasbinModel
{
ID
:
0
,
Ptype
:
"p"
,
AuthorityId
:
AuthorityId
,
Path
:
v
,
Method
:
"POST"
,
Path
:
v
.
Path
,
Method
:
v
.
Method
,
}
addflag
:=
c
.
AddCasbin
(
cm
)
if
addflag
==
false
{
...
...
QMPlusVuePage/src/view/superAdmin/api/api.vue
浏览文件 @
20ab5a8d
<
template
>
<div>
<div
class=
"button-box clearflex"
>
</div>
<div
class=
"search-term"
>
<div
class=
"button-box clearflex"
></div>
<div
class=
"search-term"
>
<el-form
:inline=
"true"
:model=
"searchInfo"
class=
"demo-form-inline"
>
<el-form-item
label=
"路径"
>
<el-input
v-model=
"searchInfo.path"
placeholder=
"路径
"
></el-input>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
@
click=
"onSubmit
"
>
查询
</el-button>
</el-form-item>
<el-form-item
>
<el-button
@
click=
"openDialog('addApi')"
type=
"primary"
>
新增api
</el-button>
</el-form-item>
</el-form>
</div>
<el-form-item
label=
"路径"
>
<el-input
placeholder=
"路径"
v-model=
"searchInfo.path
"
></el-input>
</el-form-item>
<el-form-item>
<el-button
@
click=
"onSubmit"
type=
"primary
"
>
查询
</el-button>
</el-form-item>
<el-form-item
>
<el-button
@
click=
"openDialog('addApi')"
type=
"primary"
>
新增api
</el-button>
</el-form-item>
</el-form>
</div>
<el-table
:data=
"tableData"
border
stripe
>
<el-table-column
label=
"id"
min-width=
"60"
prop=
"ID"
></el-table-column>
<el-table-column
label=
"api路径"
min-width=
"150"
prop=
"path"
></el-table-column>
<el-table-column
label=
"api分组"
min-width=
"150"
prop=
"group"
></el-table-column>
<el-table-column
label=
"api简介"
min-width=
"150"
prop=
"description"
></el-table-column>
<el-table-column
label=
"请求"
min-width=
"150"
prop=
"method"
>
<template
slot-scope=
"scope"
>
<div>
{{
scope
.
row
.
method
|
methodFiletr
}}
</div>
</
template
>
</el-table-column>
<el-table-column
fixed=
"right"
label=
"操作"
width=
"200"
>
<
template
slot-scope=
"scope"
>
<el-button
@
click=
"editApi(scope.row)"
size=
"small"
type=
"text"
>
编辑
</el-button>
...
...
@@ -38,11 +45,21 @@
layout=
"total, sizes, prev, pager, next, jumper"
></el-pagination>
<el-dialog
:visible.sync=
"dialogFormVisible"
title=
"新增Api"
>
<el-dialog
:
before-close=
"closeDialog"
:
visible.sync=
"dialogFormVisible"
title=
"新增Api"
>
<el-form
:inline=
"true"
:model=
"form"
label-width=
"80px"
>
<el-form-item
label=
"路径"
>
<el-input
autocomplete=
"off"
v-model=
"form.path"
></el-input>
</el-form-item>
<el-form-item
label=
"请求"
>
<el-select
placeholder=
"请选择"
v-model=
"form.method"
>
<el-option
:key=
"item.value"
:label=
"`${item.label}(${item.value})`"
:value=
"item.value"
v-for=
"item in methodOptions"
></el-option>
</el-select>
</el-form-item>
<el-form-item
label=
"api分组"
>
<el-input
autocomplete=
"off"
v-model=
"form.group"
></el-input>
</el-form-item>
...
...
@@ -71,6 +88,25 @@ import {
}
from
'
@/api/api
'
import
infoList
from
'
@/components/mixins/infoList
'
const
methodOptions
=
[
{
value
:
'
POST
'
,
label
:
'
创建
'
},
{
value
:
'
GET
'
,
label
:
'
查看
'
},
{
value
:
'
PUT
'
,
label
:
'
更新
'
},
{
value
:
'
DELETE
'
,
label
:
'
删除
'
}
]
export
default
{
name
:
'
Api
'
,
mixins
:
[
infoList
],
...
...
@@ -84,13 +120,14 @@ export default {
group
:
''
,
description
:
''
},
methodOptions
:
methodOptions
,
type
:
''
}
},
methods
:
{
//条件搜索前端看此方法
onSubmit
(){
this
.
page
=
1
onSubmit
()
{
this
.
page
=
1
this
.
pageSize
=
10
this
.
getTableData
()
},
...
...
@@ -98,7 +135,8 @@ export default {
this
.
form
=
{
path
:
''
,
group
:
''
,
description
:
''
description
:
''
,
method
:
''
}
},
closeDialog
()
{
...
...
@@ -179,6 +217,12 @@ export default {
break
}
}
},
filters
:{
methodFiletr
(
value
){
const
target
=
methodOptions
.
filter
(
item
=>
item
.
value
===
value
)[
0
]
return
`
${
target
.
label
}
(
${
target
.
value
}
)`
}
}
}
</
script
>
...
...
QMPlusVuePage/src/view/superAdmin/authority/components/apis.vue
浏览文件 @
20ab5a8d
...
...
@@ -63,10 +63,18 @@ export default {
},
// 关联关系确定
async
authApiEnter
()
{
const
checkArr
=
this
.
$refs
.
apiTree
.
getCheckedKeys
(
true
)
const
checkArr
=
this
.
$refs
.
apiTree
.
getCheckedNodes
(
true
)
var
casbinInfos
=
[]
checkArr
&&
checkArr
.
map
(
item
=>
{
var
casbinInfo
=
{
path
:
item
.
path
,
method
:
item
.
method
}
casbinInfos
.
push
(
casbinInfo
)
})
const
res
=
await
casbinPUpdata
({
authorityId
:
this
.
activeUserId
,
paths
:
checkArr
casbinInfos
})
if
(
res
.
success
)
{
this
.
$message
({
type
:
'
success
'
,
message
:
res
.
msg
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录