diff --git a/app/rts.go b/app/rts.go index 5dafa6b..8c9c84f 100644 --- a/app/rts.go +++ b/app/rts.go @@ -146,7 +146,26 @@ func DeleteUser(w *ResponseWriter, r *Request) { // ListUser 用户列表 func ListUser(w *ResponseWriter, r *Request) { - + search := func(db *gorm.DB) *gorm.DB { + return db. + Model(&User{}). + Scopes(Search(r, "name", "name LIKE ?")). + Scopes(Paginate(r)) + } + var userList []User + var total int64 + var err error + if err = DB.Scopes(search).Count(&total).Error; err == nil { + err = DB.Scopes(search).Find(&userList).Error + } + if err != nil { + w.Fail(http.StatusInternalServerError, 1, err.Error()) + } else { + w.Ok(map[string]any{ + "list": userList, + "total": total, + }) + } } // Login 用户登录