提供了前端分页mixin解决方案
This commit is contained in:
@@ -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,
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user