mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-09-26 20:11:11 +08:00
36 lines
789 B
Go
36 lines
789 B
Go
package actions
|
|
|
|
import (
|
|
"github.com/quarkcms/quark-go/pkg/builder"
|
|
"github.com/quarkcms/quark-go/pkg/builder/actions"
|
|
"github.com/quarkcms/quark-go/pkg/msg"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type SelectOptions struct {
|
|
actions.Action
|
|
}
|
|
|
|
// 执行行为句柄
|
|
func (p *SelectOptions) Handle(request *builder.Request, model *gorm.DB) interface{} {
|
|
resource := request.Param("resource")
|
|
search := request.Query("search")
|
|
lists := []map[string]interface{}{}
|
|
results := []map[string]interface{}{}
|
|
|
|
switch resource {
|
|
case "Some Field":
|
|
model.Where("Some Field = ?", search).Find(&lists)
|
|
for _, v := range lists {
|
|
item := map[string]interface{}{
|
|
"label": v["name"],
|
|
"value": v["id"],
|
|
}
|
|
|
|
results = append(results, item)
|
|
}
|
|
}
|
|
|
|
return msg.Success("操作成功", "", results)
|
|
}
|