Files
quark-go/pkg/app/handler/admin/actions/create_modal.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 CreateModal struct {
actions.Modal
}
// 初始化
func (p *CreateModal) Init(name string) *CreateModal {
// 初始化父结构
p.ParentInit()
// 类型
p.Type = "primary"
// 图标
p.Icon = "plus-circle"
// 文字
p.Name = "创建" + name
// 关闭时销毁 Modal 里的子元素
p.DestroyOnClose = true
// 执行成功后刷新的组件
p.Reload = "table"
// 设置展示位置
p.SetOnlyOnIndex(true)
return p
}
// 内容
func (p *CreateModal) 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("createModalForm", false).
SetApi(api).
SetBody(fields).
SetInitialValues(data).
SetLabelCol(map[string]interface{}{
"span": 6,
}).
SetWrapperCol(map[string]interface{}{
"span": 18,
})
}
// 弹窗行为
func (p *CreateModal) 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("createModalForm"),
}
}