提交 e60487bb 编写于 作者: Mr.奇淼('s avatar Mr.奇淼(

增加条件搜索示例 前端文件参考src\view\superAdmin\api\api.vue 后台文件参考 model\dnModel\api.go

上级 58cf2717
......@@ -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
}
}
......@@ -5,6 +5,7 @@ export default {
total: 10,
pageSize: 10,
tableData: [],
searchInfo: {}
}
},
methods: {
......@@ -17,7 +18,7 @@ export default {
this.getTableData()
},
async getTableData(page = this.page, pageSize = this.pageSize) {
const table = await this.listApi({ page, pageSize })
const table = await this.listApi({ page, pageSize, ...this.searchInfo })
this.tableData = table.data[this.listKey]
this.total = table.data.total
this.page = table.data.page
......
......@@ -3,6 +3,17 @@
<div class="button-box clearflex">
<el-button @click="openDialog('addApi')" type="primary">新增api</el-button>
</div>
<div class="search-term">
<el-form :inline="true" :model="searchInfo" class="demo-form-inline">
<el-form-item label="路径">
<el-input v-model="searchInfo.path" placeholder="路径"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit">查询</el-button>
</el-form-item>
</el-form>
</div>
<el-table :data="tableData" border stripe>
<el-table-column label="id" min-width="60" prop="ID"></el-table-column>
<el-table-column label="api路径" min-width="150" prop="path"></el-table-column>
......@@ -48,7 +59,7 @@
<script>
// 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成
// 获取列表内容封装在mixins内部 getTableData方法 初始化已封装完成 条件搜索时候 请把条件安好后台定制的结构体字段 放到 this.searchInfo 中即可实现条件搜索
import {
getApiById,
......@@ -76,6 +87,12 @@ export default {
}
},
methods: {
//条件搜索前端看此方法
onSubmit(){
this.page = 1
this.pageSize = 10
this.getTableData()
},
// 自动设置api分组
autoGroup() {
this.form.group = this.form.path.split('/')[1]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册