From ef433ef4305061c350f27377ad4511029fdc9176 Mon Sep 17 00:00:00 2001 From: pixel <303176530@qq.com> Date: Thu, 12 Dec 2019 14:49:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AFui=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QMPlusServer/controller/api/sys_api.go | 19 ---- QMPlusServer/controller/api/sys_authority.go | 20 ---- QMPlusServer/init/registTable/regist_table.go | 1 - QMPlusServer/model/sysModel/sys_api.go | 2 +- .../model/sysModel/sys_api_authority.go | 35 ------- QMPlusServer/router/sys_api.go | 2 - QMPlusVuePage/src/view/layout/aside/index.vue | 14 ++- QMPlusVuePage/src/view/layout/index.vue | 96 ++++++++++++------- 8 files changed, 72 insertions(+), 117 deletions(-) delete mode 100644 QMPlusServer/model/sysModel/sys_api_authority.go diff --git a/QMPlusServer/controller/api/sys_api.go b/QMPlusServer/controller/api/sys_api.go index daa52936..19aae1b7 100644 --- a/QMPlusServer/controller/api/sys_api.go +++ b/QMPlusServer/controller/api/sys_api.go @@ -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 diff --git a/QMPlusServer/controller/api/sys_authority.go b/QMPlusServer/controller/api/sys_authority.go index 39015c8d..69b29235 100644 --- a/QMPlusServer/controller/api/sys_authority.go +++ b/QMPlusServer/controller/api/sys_authority.go @@ -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, - }) - } -} \ No newline at end of file diff --git a/QMPlusServer/init/registTable/regist_table.go b/QMPlusServer/init/registTable/regist_table.go index 050d3a8c..b647fccb 100644 --- a/QMPlusServer/init/registTable/regist_table.go +++ b/QMPlusServer/init/registTable/regist_table.go @@ -12,7 +12,6 @@ func RegistTable(db *gorm.DB) { sysModel.SysAuthority{}, sysModel.SysMenu{}, sysModel.SysApi{}, - sysModel.SysApiAuthority{}, sysModel.SysBaseMenu{}, dbModel.ExaFileUploadAndDownload{}, sysModel.SysWorkflow{}, diff --git a/QMPlusServer/model/sysModel/sys_api.go b/QMPlusServer/model/sysModel/sys_api.go index b1fad672..5d2d9a36 100644 --- a/QMPlusServer/model/sysModel/sys_api.go +++ b/QMPlusServer/model/sysModel/sys_api.go @@ -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 } diff --git a/QMPlusServer/model/sysModel/sys_api_authority.go b/QMPlusServer/model/sysModel/sys_api_authority.go deleted file mode 100644 index 6ccb0127..00000000 --- a/QMPlusServer/model/sysModel/sys_api_authority.go +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/QMPlusServer/router/sys_api.go b/QMPlusServer/router/sys_api.go index c713b541..a16ec4e8 100644 --- a/QMPlusServer/router/sys_api.go +++ b/QMPlusServer/router/sys_api.go @@ -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 } diff --git a/QMPlusVuePage/src/view/layout/aside/index.vue b/QMPlusVuePage/src/view/layout/aside/index.vue index c9a8e2e9..51deac22 100644 --- a/QMPlusVuePage/src/view/layout/aside/index.vue +++ b/QMPlusVuePage/src/view/layout/aside/index.vue @@ -4,20 +4,23 @@ - - + + - @@ -58,6 +61,11 @@ export default { \ No newline at end of file -- GitLab