增加条件搜索示例 前端文件参考src\view\superAdmin\api\api.vue 后台文件参考 model\dnModel\api.go
This commit is contained in:
@@ -79,6 +79,8 @@ func SetAuthAndApi(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
//条件搜索后端看此api
|
||||
|
||||
// @Tags Api
|
||||
// @Summary 分页获取API列表
|
||||
// @Security ApiKeyAuth
|
||||
@@ -88,17 +90,22 @@ func SetAuthAndApi(c *gin.Context) {
|
||||
// @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)
|
||||
// 此结构体仅本方法使用
|
||||
type searchParams struct {
|
||||
dbModel.Api
|
||||
modelInterface.PageInfo
|
||||
}
|
||||
var sp searchParams
|
||||
_ = c.ShouldBindJSON(&sp)
|
||||
err, list, total := sp.Api.GetInfoList(sp.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,
|
||||
"page": sp.PageInfo.Page,
|
||||
"pageSize": sp.PageInfo.PageSize,
|
||||
})
|
||||
|
||||
}
|
||||
|
@@ -55,7 +55,7 @@ func (a *Api) GetInfoList(info modelInterface.PageInfo) (err error, list interfa
|
||||
return
|
||||
} else {
|
||||
var apiList []Api
|
||||
err = db.Order("group", true).Find(&apiList).Error
|
||||
err = db.Order("group", true).Where("path LIKE ?", "%"+a.Path+"%").Find(&apiList).Error
|
||||
return err, apiList, total
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user