提交 20ab5a8d 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

api 增加 GET PUT DELETE POST 四种可选声明方式

上级 f7a1fdd0
......@@ -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.Paths)
err := new(sysModel.CasbinModel).CasbinPUpdata(cmr.AuthorityId, cmr.CasbinInfos)
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})
......
......@@ -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) {
......
......@@ -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 Paths {
for _, v := range casbinInfos {
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 {
......
<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>
......
......@@ -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.
先完成此消息的编辑!
想要评论请 注册