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

89 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 CreateDrawer struct {
actions.Drawer
}
// 初始化
func (p *CreateDrawer) Init(name string) *CreateDrawer {
// 初始化父结构
p.ParentInit()
// 类型
p.Type = "primary"
// 图标
p.Icon = "plus-circle"
// 文字
p.Name = "创建" + name
// 执行成功后刷新的组件
p.Reload = "table"
// 关闭时销毁 Drawer 里的子元素
p.DestroyOnClose = true
// 设置展示位置
p.SetOnlyOnIndex(true)
return p
}
// 内容
func (p *CreateDrawer) GetBody(request *builder.Request, resourceInstance interface{}) interface{} {
api := resourceInstance.(interface {
CreationApi(*builder.Request, interface{}) string
}).CreationApi(request, resourceInstance)
fields := resourceInstance.(interface {
CreationFieldsWithinComponents(*builder.Request, interface{}) interface{}
}).CreationFieldsWithinComponents(request, resourceInstance)
// 断言BeforeCreating方法获取初始数据
data := resourceInstance.(interface {
BeforeCreating(*builder.Request) map[string]interface{}
}).BeforeCreating(request)
return (&form.Component{}).
Init().
SetKey("createDrawerForm", false).
SetApi(api).
SetBody(fields).
SetInitialValues(data).
SetLabelCol(map[string]interface{}{
"span": 6,
}).
SetWrapperCol(map[string]interface{}{
"span": 18,
})
}
// 弹窗行为
func (p *CreateDrawer) 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("createDrawerForm"),
}
}