增加 用户名或姓名或邮箱 搜索支持

This commit is contained in:
bjdgyc 2024-01-15 17:30:58 +08:00
parent 3408198d2d
commit da92c111e7
1 changed files with 7 additions and 3 deletions

View File

@ -22,6 +22,7 @@ import (
func UserList(w http.ResponseWriter, r *http.Request) { func UserList(w http.ResponseWriter, r *http.Request) {
_ = r.ParseForm() _ = r.ParseForm()
prefix := r.FormValue("prefix") prefix := r.FormValue("prefix")
prefix = strings.TrimSpace(prefix)
pageS := r.FormValue("page") pageS := r.FormValue("page")
page, _ := strconv.Atoi(pageS) page, _ := strconv.Atoi(pageS)
if page < 1 { if page < 1 {
@ -37,8 +38,11 @@ func UserList(w http.ResponseWriter, r *http.Request) {
// 查询前缀匹配 // 查询前缀匹配
if len(prefix) > 0 { if len(prefix) > 0 {
count = dbdata.CountPrefix("username", prefix, &dbdata.User{}) prefixFuzzy := "%" + prefix + "%"
err = dbdata.Prefix("username", prefix, &datas, pageSize, 1) where := "username LIKE ? OR nickname LIKE ? OR email LIKE ?"
count = dbdata.FindWhereCount(&dbdata.User{}, where, prefixFuzzy, prefixFuzzy, prefixFuzzy)
err = dbdata.FindWhere(&datas, pageSize, page, where, prefixFuzzy, prefixFuzzy, prefixFuzzy)
} else { } else {
count = dbdata.CountAll(&dbdata.User{}) count = dbdata.CountAll(&dbdata.User{})
err = dbdata.Find(&datas, pageSize, page) err = dbdata.Find(&datas, pageSize, page)