mirror of
https://github.com/quarkcloudio/quark-go.git
synced 2025-09-26 20:11:11 +08:00
89 lines
1.9 KiB
Go
89 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 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"),
|
||
}
|
||
}
|