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

88 lines
1.9 KiB
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/component/admin/action"
"github.com/quarkcms/quark-go/pkg/component/admin/form"
)
type EditDrawer struct {
actions.Drawer
}
// 初始化
func (p *EditDrawer) Init(name string) *EditDrawer {
// 初始化父结构
p.ParentInit()
// 类型
p.Type = "link"
// 设置按钮大小,large | middle | small | default
p.Size = "small"
// 文字
p.Name = name
// 关闭时销毁 Drawer 里的子元素
p.DestroyOnClose = true
// 执行成功后刷新的组件
p.Reload = "table"
// 设置展示位置
p.SetOnlyOnIndexTableRow(true)
return p
}
// 内容
func (p *EditDrawer) GetBody(request *builder.Request, resourceInstance interface{}) interface{} {
api := resourceInstance.(interface {
UpdateApi(*builder.Request, interface{}) string
}).UpdateApi(request, resourceInstance)
initApi := resourceInstance.(interface {
EditValueApi(*builder.Request) string
}).EditValueApi(request)
fields := resourceInstance.(interface {
UpdateFieldsWithinComponents(*builder.Request, interface{}) interface{}
}).UpdateFieldsWithinComponents(request, resourceInstance)
return (&form.Component{}).
Init().
SetKey("editDrawerForm", false).
SetApi(api).
SetInitApi(initApi).
SetBody(fields).
SetLabelCol(map[string]interface{}{
"span": 6,
}).
SetWrapperCol(map[string]interface{}{
"span": 18,
})
}
// 弹窗行为
func (p *EditDrawer) GetActions(request *builder.Request, resourceInstance interface{}) []interface{} {
return []interface{}{
(&action.Component{}).
Init().
SetLabel("取消").
SetActionType("cancel"),
(&action.Component{}).
Init().
SetLabel("提交").
SetWithLoading(true).
SetReload("table").
SetActionType("submit").
SetType("primary", false).
SetSubmitForm("editDrawerForm"),
}
}