diff --git a/QMPlusServer/controller/api/api.go b/QMPlusServer/controller/api/api.go index ea034ebcbd9534a792aec934f79a28622ef5685c..b1902e5f86b23efdce1cbf681e0c9594673b7bd4 100644 --- a/QMPlusServer/controller/api/api.go +++ b/QMPlusServer/controller/api/api.go @@ -5,6 +5,7 @@ import ( "github.com/gin-gonic/gin" "main/controller/servers" "main/model/dbModel" + "main/model/modelInterface" ) type CreateApiParams struct { @@ -54,3 +55,51 @@ func DeleteApi(c *gin.Context) { servers.ReportFormat(c, true, "删除成功", gin.H{}) } } + +type AuthAndPathIn struct { + AuthorityId string `json:"authorityId"` + Apis []dbModel.Api `json:"apis"` +} +// @Tags Api +// @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/setAuthAndPath [post] +func SetAuthAndPath(c *gin.Context){ + var authAndPathIn AuthAndPathIn + _ = c.BindJSON(&authAndPathIn) + err:=new(dbModel.ApiAuthority).SetAuthAndPath(authAndPathIn.AuthorityId,authAndPathIn.Apis) + if err != nil { + servers.ReportFormat(c, false, fmt.Sprintf("添加失败:%v", err), gin.H{}) + } else { + servers.ReportFormat(c, true, "添加成功", gin.H{}) + } +} + +// @Tags api +// @Summary 分页获取角色列表 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body modelInterface.PageInfo true "分页获取用户列表" +// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /api/getApiList [post] +func GetApiList(c *gin.Context) { + var pageInfo modelInterface.PageInfo + _ = c.BindJSON(&pageInfo) + err, list, total := new(dbModel.Api).GetInfoList(pageInfo) + if err != nil { + servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{}) + } else { + servers.ReportFormat(c, true, "获取数据成功", gin.H{ + "list": list, + "total": total, + "page": pageInfo.Page, + "pageSize": pageInfo.PageSize, + }) + + } +} \ No newline at end of file diff --git a/QMPlusServer/controller/api/authority.go b/QMPlusServer/controller/api/authority.go index 1554bdf6754648577511cb779c665c268d967330..c0f9b00d1491092798ff471ad62711d50ec595e8 100644 --- a/QMPlusServer/controller/api/authority.go +++ b/QMPlusServer/controller/api/authority.go @@ -76,7 +76,7 @@ func GetAuthorityList(c *gin.Context){ servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{}) } else { servers.ReportFormat(c, true, "获取数据成功", gin.H{ - "authList": list, + "list": list, "total": total, "page": pageInfo.Page, "pageSize": pageInfo.PageSize, diff --git a/QMPlusServer/controller/api/menu.go b/QMPlusServer/controller/api/menu.go index 44a91c5cf9cca4f73f5413baa1b4155b9f2261aa..b935a3b2ad77bc4c87c2fcef97f6eaeb2dee6f04 100644 --- a/QMPlusServer/controller/api/menu.go +++ b/QMPlusServer/controller/api/menu.go @@ -43,7 +43,7 @@ func GetMenuList(c *gin.Context) { servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{}) } else { servers.ReportFormat(c, true, "获取数据成功", gin.H{ - "menuList": menuList, + "list": menuList, "total": total, "page": pageInfo.Page, "pageSize": pageInfo.PageSize, diff --git a/QMPlusServer/model/dbModel/api.go b/QMPlusServer/model/dbModel/api.go index eda7436cdd330d9a1dac3d8e9190c3290ab5cca6..3623fe64cc0ec7de290cbcd3f2aa960e63c6093a 100644 --- a/QMPlusServer/model/dbModel/api.go +++ b/QMPlusServer/model/dbModel/api.go @@ -2,13 +2,14 @@ package dbModel import ( "github.com/jinzhu/gorm" + "github.com/pkg/errors" "main/controller/servers" "main/init/qmsql" "main/model/modelInterface" ) type Api struct { - gorm.Model `json:"-"` + gorm.Model Path string `json:"path"` Description string `json:"description"` } @@ -16,7 +17,7 @@ type Api struct { func (a *Api) CreateApi() (err error) { findOne := qmsql.DEFAULTDB.Where("path = ?", a.Path).Find(&Menu{}).Error if findOne != nil { - + return errors.New("存在相同api") } else { err = qmsql.DEFAULTDB.Create(a).Error } @@ -29,7 +30,8 @@ func (a *Api) DeleteApi() (err error) { } func (a *Api) EditApi() (err error) { - err = qmsql.DEFAULTDB.Update(a).Update(&Authority{}).Error + err = qmsql.DEFAULTDB.Update(a).Error + err = qmsql.DEFAULTDB.Where("path = ?",a.Path).Update("path",a.Path).Error return err } diff --git a/QMPlusServer/model/dbModel/api_authority.go b/QMPlusServer/model/dbModel/api_authority.go index c6521e1eea19259d16ed2da0e608c8c8c689e534..59f1ebf1ac69af9db836820c3d9910e9826d11ad 100644 --- a/QMPlusServer/model/dbModel/api_authority.go +++ b/QMPlusServer/model/dbModel/api_authority.go @@ -1,6 +1,21 @@ package dbModel +import "main/init/qmsql" + type ApiAuthority struct { AuthorityId string `json:"-"` - Api + Path string `json:"_"` } + + +//创建角色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){ + return err + } + } + return nil +} \ No newline at end of file diff --git a/QMPlusServer/router/api.go b/QMPlusServer/router/api.go index 21485ba85b28fcb07e2cd99a3b96c71d0cb6c453..b5f8caa021148be541e965eadb6e97165d331c4e 100644 --- a/QMPlusServer/router/api.go +++ b/QMPlusServer/router/api.go @@ -7,9 +7,11 @@ import ( ) func InitApiRouter(Router *gin.Engine) { - UserRouter := Router.Group("api").Use(middleware.JWTAuth()) + ApiRouter := Router.Group("api").Use(middleware.JWTAuth()) { - UserRouter.POST("createApi", api.CreateApi) - UserRouter.POST("deleteApi", api.DeleteApi) + ApiRouter.POST("createApi", api.CreateApi) + ApiRouter.POST("deleteApi", api.DeleteApi) + ApiRouter.POST("setAuthAndPath",api.SetAuthAndPath) + ApiRouter.POST("getApiList",api.GetApiList) } } diff --git a/QMPlusServer/router/base.go b/QMPlusServer/router/base.go index e2c92710275bf09645e724d495546435c359c904..f0889b96e772355a5b9810cdce8a3d6d7c4bbd99 100644 --- a/QMPlusServer/router/base.go +++ b/QMPlusServer/router/base.go @@ -6,9 +6,9 @@ import ( ) func InitBaseRouter(Router *gin.Engine) { - UserRouter := Router.Group("base") + BaseRouter := Router.Group("base") { - UserRouter.POST("regist", api.Regist) - UserRouter.POST("login", api.Login) + BaseRouter.POST("regist", api.Regist) + BaseRouter.POST("login", api.Login) } } diff --git a/QMPlusVuePage/src/api/api.js b/QMPlusVuePage/src/api/api.js new file mode 100644 index 0000000000000000000000000000000000000000..2baf1cbc9853044de048c56d82f3981dbcec350a --- /dev/null +++ b/QMPlusVuePage/src/api/api.js @@ -0,0 +1,20 @@ +import service from '@/utils/request' +// @Tags api +// @Summary 分页获取角色列表 +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body modelInterface.PageInfo true "分页获取用户列表" +// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /api/getApiList [post] +// { +// page int +// pageSize int +// } +export const getApiList = (data) => { + return service({ + url: "/api/getApiList", + method: 'post', + data + }) +} \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/api/api.vue b/QMPlusVuePage/src/view/superAdmin/api/api.vue index 34eb651cc261052f7e1fa3a9501e586b8339417b..7b423ffe5ff0ca8c1d7a55130f30510a6ffce284 100644 --- a/QMPlusVuePage/src/view/superAdmin/api/api.vue +++ b/QMPlusVuePage/src/view/superAdmin/api/api.vue @@ -1,14 +1,62 @@ - \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue index c8cf200cf80ee9e494fd52c53be6e6d18070a123..37af7c619e4bcff6709054942fe42839d4d06f88 100644 --- a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue +++ b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue @@ -67,15 +67,15 @@ import { createAuthority } from '@/api/authority' import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu' +import infoList from '@/view/superAdmin/mixins/infoList' export default { name: 'Authority', + mixins:[infoList], data() { return { + listApi: getAuthorityList, + listKey:'list', activeUserId: 0, - page: 1, - total: 10, - pageSize: 10, - tableData: [], treeData: [], treeIds: [], defaultProps: { @@ -91,16 +91,6 @@ export default { } }, methods: { - // 条数 - handleSizeChange(val) { - this.pageSize = val - this.getAuthList() - }, - // 页码 - handleCurrentChange(val) { - this.page = val - this.getAuthList() - }, // 删除角色 deleteAuth(row) { this.$confirm('此操作将永久删除该角色, 是否继续?', '提示', { @@ -115,7 +105,7 @@ export default { type: 'success', message: '删除成功!' }) - this.getAuthList() + this.getTableData() } }) .catch(() => { @@ -145,7 +135,7 @@ export default { type: 'success', message: '添加成功!' }) - this.getAuthList() + this.getTableData() this.closeDialog() } this.initForm() @@ -155,11 +145,7 @@ export default { addAuthority() { this.dialogFormVisible = true }, - // 获取用户列表 - async getAuthList(page = this.page, pageSize = this.pageSize) { - const table = await getAuthorityList({ page, pageSize }) - this.tableData = table.data.authList - }, + // 关联用户列表关系 async addAuthMenu(row) { const res1 = await getMenuAuthority({ authorityId: row.authorityId }) @@ -194,11 +180,11 @@ export default { // 获取基础menu树 }, created() { - this.getAuthList() + this.getTableData() } } -