mirror of
https://github.com/flipped-aurora/gin-vue-admin.git
synced 2026-09-21 20:35:16 +00:00
前端ui调整
This commit is contained in:
@@ -60,25 +60,6 @@ type AuthAndPathIn struct {
|
||||
ApiIds []uint `json:"apiIds"`
|
||||
}
|
||||
|
||||
// @Tags SysApi
|
||||
// @Summary 创建api和角色关系
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body api.AuthAndPathIn true "创建api和角色关系"
|
||||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /api/setAuthAndApi [post]
|
||||
func SetAuthAndApi(c *gin.Context) {
|
||||
var authAndPathIn AuthAndPathIn
|
||||
_ = c.BindJSON(&authAndPathIn)
|
||||
err := new(sysModel.SysApiAuthority).SetAuthAndApi(authAndPathIn.AuthorityId, authAndPathIn.ApiIds)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("添加失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "添加成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
//条件搜索后端看此api
|
||||
|
||||
// @Tags SysApi
|
||||
|
||||
@@ -89,23 +89,3 @@ type GetAuthorityId struct {
|
||||
AuthorityId string `json:"authorityId"`
|
||||
}
|
||||
|
||||
// @Tags authority
|
||||
// @Summary 获取本角色所有有权限的apiId
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body api.GetAuthorityId true "获取本角色所有有权限的apiId"
|
||||
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /authority/getAuthAndApi [post]
|
||||
func GetAuthAndApi(c *gin.Context){
|
||||
var idInfo GetAuthorityId
|
||||
_ = c.BindJSON(&idInfo)
|
||||
err,apis := new(sysModel.SysApiAuthority).GetAuthAndApi(idInfo.AuthorityId)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "获取数据成功", gin.H{
|
||||
"apis": apis,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,6 @@ func RegistTable(db *gorm.DB) {
|
||||
sysModel.SysAuthority{},
|
||||
sysModel.SysMenu{},
|
||||
sysModel.SysApi{},
|
||||
sysModel.SysApiAuthority{},
|
||||
sysModel.SysBaseMenu{},
|
||||
dbModel.ExaFileUploadAndDownload{},
|
||||
sysModel.SysWorkflow{},
|
||||
|
||||
@@ -27,7 +27,7 @@ func (a *SysApi) CreateApi() (err error) {
|
||||
|
||||
func (a *SysApi) DeleteApi() (err error) {
|
||||
err = qmsql.DEFAULTDB.Delete(a).Error
|
||||
err = qmsql.DEFAULTDB.Where("api_id = ?", a.ID).Unscoped().Delete(&SysApiAuthority{}).Error
|
||||
new(CasbinModel).clearCasbin(1,a.Path)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package sysModel
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
"main/init/qmsql"
|
||||
)
|
||||
|
||||
type SysApiAuthority struct {
|
||||
gorm.Model
|
||||
AuthorityId string
|
||||
Authority SysAuthority `gorm:"ForeignKey:AuthorityId;AssociationForeignKey:AuthorityId"` //其实没有关联的必要
|
||||
ApiId uint
|
||||
Api SysApi
|
||||
}
|
||||
|
||||
//创建角色api关联关系
|
||||
func (a *SysApiAuthority) SetAuthAndApi(authId string, apisid []uint) (err error) {
|
||||
for _, v := range apisid {
|
||||
err = qmsql.DEFAULTDB.Create(&SysApiAuthority{AuthorityId: authId, ApiId: v}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取角色api关联关系
|
||||
func (a *SysApiAuthority) GetAuthAndApi(authId string) (err error,apiIds []uint) {
|
||||
var apis []SysApiAuthority
|
||||
err = qmsql.DEFAULTDB.Where("authority_id = ?", authId).Find(&apis).Error
|
||||
for _, v := range apis {
|
||||
apiIds = append(apiIds,v.ApiId)
|
||||
}
|
||||
return nil,apiIds
|
||||
}
|
||||
@@ -11,12 +11,10 @@ func InitApiRouter(Router *gin.Engine)(R gin.IRoutes) {
|
||||
{
|
||||
ApiRouter.POST("createApi", api.CreateApi) //创建Api
|
||||
ApiRouter.POST("deleteApi", api.DeleteApi) //删除Api
|
||||
ApiRouter.POST("setAuthAndApi",api.SetAuthAndApi) // 设置api和角色关系
|
||||
ApiRouter.POST("getApiList",api.GetApiList) //获取Api列表
|
||||
ApiRouter.POST("getApiById",api.GetApiById) //获取单条Api消息
|
||||
ApiRouter.POST("updataApi",api.UpdataApi) //更新api
|
||||
ApiRouter.POST("getAllApis",api.GetAllApis) // 获取所有api
|
||||
ApiRouter.POST("getAuthAndApi",api.GetAuthAndApi) // 获取api和auth关系
|
||||
}
|
||||
return ApiRouter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user