Files
quark-go/pkg/app/handler/admin/actions/select_options.go
tangtanglove 5244508c40 first commit
2023-01-18 13:40:07 +08:00

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)
}