接入搜索功能
This commit is contained in:
+38
-6
@@ -522,7 +522,7 @@ func (that *MakeCode) Edit(table string, req *http.Request) Map {
|
||||
return data
|
||||
}
|
||||
|
||||
func (that *MakeCode) Search(table string, req *http.Request) (string, Map) {
|
||||
func (that *MakeCode) Search(table string, req *http.Request, db *db.HoTimeDB) (string, Map, Map) {
|
||||
reStr := ""
|
||||
for _, v := range that.TableColumns[table] {
|
||||
//不可使用,未在前端展示,但在内存中保持有
|
||||
@@ -530,13 +530,13 @@ func (that *MakeCode) Search(table string, req *http.Request) (string, Map) {
|
||||
continue
|
||||
}
|
||||
if v.Get("list") == nil || v.GetBool("list") {
|
||||
reStr += v.GetString("name") + ","
|
||||
reStr += table + "." + v.GetString("name") + ","
|
||||
}
|
||||
}
|
||||
if len(reStr) != 0 {
|
||||
reStr = reStr[:len(reStr)-1]
|
||||
}
|
||||
|
||||
leftJoin := Map{}
|
||||
data := Map{}
|
||||
keyword := Map{}
|
||||
daterange := Map{}
|
||||
@@ -555,14 +555,46 @@ func (that *MakeCode) Search(table string, req *http.Request) (string, Map) {
|
||||
columns := that.TableConfig.GetMap(table).GetSlice("columns")
|
||||
if searchItem.GetString("type") == "search" {
|
||||
for columnKey, _ := range columns {
|
||||
if columns.GetMap(columnKey)["list"] == false {
|
||||
continue
|
||||
}
|
||||
if searchItemName == "keyword" &&
|
||||
columns.GetMap(columnKey).GetString("type") == "text" {
|
||||
keyword[columns.GetMap(columnKey).GetString("name")+"[~]"] = reqValue
|
||||
keyword[table+"."+columns.GetMap(columnKey).GetString("name")+"[~]"] = reqValue
|
||||
|
||||
}
|
||||
if searchItemName == "keyword" &&
|
||||
columns.GetMap(columnKey).GetString("name") == "id" {
|
||||
keyword[table+"."+columns.GetMap(columnKey).GetString("name")] = reqValue
|
||||
|
||||
}
|
||||
|
||||
if searchItemName == "keyword" &&
|
||||
columns.GetMap(columnKey).GetString("link") != "" &&
|
||||
columns.GetMap(columnKey).GetString("name") != "parent_id" {
|
||||
for columnChildKey, _ := range columns {
|
||||
if columns.GetMap(columnChildKey).GetString("link") != "" &&
|
||||
columns.GetMap(columnChildKey).GetString("name") != "parent_id" {
|
||||
childs := db.Select(columns.GetMap(columnChildKey).GetString("link"), "id", Map{columns.GetMap(columnChildKey).GetString("value") + "[~]": reqValue})
|
||||
childIds := Slice{}
|
||||
for _, v := range childs {
|
||||
childIds = append(childIds, v.GetString("id"))
|
||||
}
|
||||
if len(childIds) != 0 {
|
||||
keyword[columns.GetMap(columnChildKey).GetString("link")+".id"] = childIds
|
||||
leftJoin["[>]"+columns.GetMap(columnChildKey).GetString("link")] =
|
||||
columns.GetMap(columnChildKey).GetString("name") + "=" +
|
||||
columns.GetMap(columnChildKey).GetString("link") + ".id"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
//日期类型
|
||||
if searchItemName == "daterange" && columns.GetMap(columnKey).GetString("type") == "time" {
|
||||
fmt.Println(req.Form["daterange"])
|
||||
daterange[columns.GetMap(columnKey).GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
daterange[table+"."+columns.GetMap(columnKey).GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -611,5 +643,5 @@ func (that *MakeCode) Search(table string, req *http.Request) (string, Map) {
|
||||
}
|
||||
}
|
||||
|
||||
return reStr, where
|
||||
return reStr, leftJoin, where
|
||||
}
|
||||
|
||||
+5
-4
@@ -85,10 +85,10 @@ var {{table}}Ctr = Ctr{
|
||||
"search": func(that *Context) {
|
||||
|
||||
|
||||
columnStr, where := that.MakeCode.Search(that.RouterString[1], that.Req)
|
||||
columnStr,leftJoin,where := that.MakeCode.Search(that.RouterString[1], that.Req,that.Db)
|
||||
page:=ObjToInt(that.Req.FormValue("page"))
|
||||
pageSize:=ObjToInt(that.Req.FormValue("pageSize"))
|
||||
|
||||
|
||||
if page<1{
|
||||
page=1
|
||||
}
|
||||
@@ -96,9 +96,10 @@ var {{table}}Ctr = Ctr{
|
||||
if pageSize<=0{
|
||||
pageSize=20
|
||||
}
|
||||
count:=that.Db.Count(that.RouterString[1], where)
|
||||
|
||||
count:=that.Db.Count(that.RouterString[1],leftJoin,where)
|
||||
reData := that.Db.Page(page, pageSize).
|
||||
PageSelect(that.RouterString[1], columnStr, where)
|
||||
PageSelect(that.RouterString[1],leftJoin,columnStr, where)
|
||||
|
||||
|
||||
for _, v := range reData {
|
||||
|
||||
Reference in New Issue
Block a user