Merge pull request #282 from trheyi/main

[change] action structure
This commit is contained in:
Max 2022-12-08 04:36:51 +08:00 committed by GitHub
commit 041253aeed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 84 additions and 79 deletions

View file

@ -23,7 +23,8 @@ func (actions Actions) Hash() Actions {
h := md4.New() h := md4.New()
for i := range actions { for i := range actions {
keys := []string{} keys := []string{}
for key, value := range actions[i].Action { for i, value := range actions[i].Action {
key := fmt.Sprintf("%d", i)
for k, v := range value { for k, v := range value {
data, _ := jsoniter.Marshal(v) data, _ := jsoniter.Marshal(v)
key = fmt.Sprintf("%s%s%s", key, k, data) key = fmt.Sprintf("%s%s%s", key, k, data)

View file

@ -30,15 +30,15 @@ type ActionsExport struct {
// ActionDSL the component action DSL // ActionDSL the component action DSL
type ActionDSL struct { type ActionDSL struct {
Title string `json:"title,omitempty"` Title string `json:"title,omitempty"`
Width int `json:"width,omitempty"` Width int `json:"width,omitempty"`
Icon string `json:"icon,omitempty"` Icon string `json:"icon,omitempty"`
Style string `json:"style,omitempty"` Style string `json:"style,omitempty"`
ID string `json:"id,omitempty"` ID string `json:"id,omitempty"`
Xpath string `json:"xpath,omitempty"` Xpath string `json:"xpath,omitempty"`
Props PropsDSL `json:"props,omitempty"` Props PropsDSL `json:"props,omitempty"`
Confirm *ConfirmActionDSL `json:"confirm,omitempty"` Confirm *ConfirmActionDSL `json:"confirm,omitempty"`
Action map[string]ParamsDSL `json:"action,omitempty"` Action []ParamsDSL `json:"action,omitempty"`
} }
// ConfirmActionDSL action.confirm // ConfirmActionDSL action.confirm

View file

@ -30,7 +30,7 @@ func TestReadFile(t *testing.T) {
assert.Equal(t, "::PET ADMIN", res.Get("name")) assert.Equal(t, "::PET ADMIN", res.Get("name"))
assert.Equal(t, "20", res.Get("action.search.default.2")) assert.Equal(t, "20", res.Get("action.search.default.2"))
assert.Equal(t, "https://yaoapps.com", res.Get("layout.header.preset.import.operation.0.link")) assert.Equal(t, "https://yaoapps.com", res.Get("layout.header.preset.import.operation.0.link"))
assert.Equal(t, "cured", res.Get("layout.table.operation.actions[2].action.Table.save.status")) assert.Equal(t, "cured", res.Get("layout.table.operation.actions[2].action[0].payload.status"))
assert.Equal(t, "提示", res["layout.table.operation.actions[5].confirm.title"]) assert.Equal(t, "提示", res["layout.table.operation.actions[5].confirm.title"])
assert.Equal(t, "icon-trash", res["layout.table.operation.actions[5].icon"]) assert.Equal(t, "icon-trash", res["layout.table.operation.actions[5].icon"])
} }

View file

@ -280,14 +280,12 @@ func (dsl *DSL) Actions() []component.ActionsExport {
// layout.operation.actions // layout.operation.actions
if dsl.Layout != nil && if dsl.Layout != nil &&
dsl.Layout.Operation != nil && dsl.Layout.Actions != nil &&
dsl.Layout.Operation.Actions != nil && len(dsl.Layout.Actions) > 0 {
len(dsl.Layout.Operation.Actions) > 0 {
res = append(res, component.ActionsExport{ res = append(res, component.ActionsExport{
Type: "operation", Type: "operation",
Xpath: "layout.operation.actions", Xpath: "layout.operation.actions",
Actions: dsl.Layout.Operation.Actions.Hash(), Actions: dsl.Layout.Actions.Hash(),
}) })
} }
return res return res

View file

@ -15,22 +15,23 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, formID string, fields *FieldsDS
layout.Primary = m.PrimaryKey layout.Primary = m.PrimaryKey
} }
if layout.Operation == nil { if layout.Actions == nil {
layout.Operation = &OperationLayoutDSL{ layout.Actions = []component.ActionDSL{
Preset: map[string]map[string]interface{}{"save": {}, "back": {}}, {
Actions: []component.ActionDSL{ Title: "::Delete",
{ Icon: "icon-trash-2",
Title: "::Delete", Style: "danger",
Icon: "icon-trash-2", Action: []component.ParamsDSL{
Style: "danger", {
Action: map[string]component.ParamsDSL{ "name": "Delete",
"Form.delete": {"model": formID}, "type": "Form.delete",
}, "payload": map[string]interface{}{"model": formID},
Confirm: &component.ConfirmActionDSL{
Title: "::Confirm",
Desc: "::Please confirm, the data cannot be recovered",
}, },
}, },
Confirm: &component.ConfirmActionDSL{
Title: "::Confirm",
Desc: "::Please confirm, the data cannot be recovered",
},
}, },
} }
} }
@ -71,21 +72,9 @@ func (layout *LayoutDSL) BindForm(form *DSL, fields *FieldsDSL) error {
layout.Primary = form.Layout.Primary layout.Primary = form.Layout.Primary
} }
if layout.Operation == nil && form.Layout.Operation != nil { if (layout.Actions == nil || len(layout.Actions) == 0) &&
layout.Operation = &OperationLayoutDSL{ form.Layout.Actions != nil {
Actions: []component.ActionDSL{}, layout.Actions = form.Layout.Actions
Preset: map[string]map[string]interface{}{},
}
}
if (layout.Operation.Actions == nil || len(layout.Operation.Actions) == 0) &&
form.Layout.Operation.Actions != nil {
layout.Operation.Actions = form.Layout.Operation.Actions
}
if layout.Operation.Preset == nil || len(layout.Operation.Preset) == 0 &&
form.Layout.Operation.Preset != nil {
layout.Operation.Preset = form.Layout.Operation.Preset
} }
if layout.Form == nil && form.Layout.Form != nil { if layout.Form == nil && form.Layout.Form != nil {
@ -102,22 +91,23 @@ func (layout *LayoutDSL) BindTable(tab *table.DSL, formID string, fields *Fields
layout.Primary = tab.Layout.Primary layout.Primary = tab.Layout.Primary
} }
if layout.Operation == nil { if layout.Actions == nil {
layout.Operation = &OperationLayoutDSL{ layout.Actions = []component.ActionDSL{
Preset: map[string]map[string]interface{}{"save": {}, "back": {}}, {
Actions: []component.ActionDSL{ Title: "::Delete",
{ Icon: "icon-trash-2",
Title: "::Delete", Style: "danger",
Icon: "icon-trash-2", Action: []component.ParamsDSL{
Style: "danger", {
Action: map[string]component.ParamsDSL{ "name": "Delete",
"Form.delete": {"model": formID}, "type": "Form.delete",
}, "payload": map[string]interface{}{"model": formID},
Confirm: &component.ConfirmActionDSL{
Title: "::Confirm",
Desc: "::Please confirm, the data cannot be recovered",
}, },
}, },
Confirm: &component.ConfirmActionDSL{
Title: "::Confirm",
Desc: "::Please confirm, the data cannot be recovered",
},
}, },
} }
} }

View file

@ -56,16 +56,10 @@ type BindActionDSL struct {
// LayoutDSL the form layout DSL // LayoutDSL the form layout DSL
type LayoutDSL struct { type LayoutDSL struct {
Primary string `json:"primary,omitempty"` Primary string `json:"primary,omitempty"`
Operation *OperationLayoutDSL `json:"operation,omitempty"` Actions component.Actions `json:"actions,omitempty"`
Form *ViewLayoutDSL `json:"form,omitempty"` Form *ViewLayoutDSL `json:"form,omitempty"`
Config map[string]interface{} `json:"config,omitempty"` Config map[string]interface{} `json:"config,omitempty"`
}
// OperationLayoutDSL layout.operation
type OperationLayoutDSL struct {
Preset map[string]map[string]interface{} `json:"preset,omitempty"`
Actions component.Actions `json:"actions,omitempty"`
} }
// FieldsDSL the form fields DSL // FieldsDSL the form fields DSL

View file

@ -31,8 +31,12 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
Title: "::Create", Title: "::Create",
Icon: "icon-plus", Icon: "icon-plus",
Width: 3, Width: 3,
Action: map[string]component.ParamsDSL{ Action: []component.ParamsDSL{
"Common.historyPush": {"pathname": fmt.Sprintf("/x/Form/%s/0/edit", formName)}, {
"name": "HistoryPush",
"type": "Common.historyPush",
"payload": map[string]interface{}{"pathname": fmt.Sprintf("/x/Form/%s/0/edit", formName)},
},
}, },
}, },
} }
@ -78,9 +82,16 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
component.ActionDSL{ component.ActionDSL{
Title: "::View", Title: "::View",
Icon: "icon-eye", Icon: "icon-eye",
Action: map[string]component.ParamsDSL{ Action: []component.ParamsDSL{
"Common.openModal": { {
"Form": map[string]interface{}{"type": "view", "model": formName}, "name": "OpenModal",
"type": "Common.openModal",
"payload": map[string]interface{}{
"Form": map[string]interface{}{
"type": "view",
"model": formName,
},
},
}, },
}, },
}, },
@ -88,9 +99,16 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
component.ActionDSL{ component.ActionDSL{
Title: "::Edit", Title: "::Edit",
Icon: "icon-edit-2", Icon: "icon-edit-2",
Action: map[string]component.ParamsDSL{ Action: []component.ParamsDSL{
"Common.openModal": { {
"Form": map[string]interface{}{"type": "edit", "model": formName}, "name": "OpenModal",
"type": "Common.openModal",
"payload": map[string]interface{}{
"Form": map[string]interface{}{
"type": "edit",
"model": formName,
},
},
}, },
}, },
}, },
@ -99,8 +117,12 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s
Title: "::Delete", Title: "::Delete",
Icon: "icon-trash-2", Icon: "icon-trash-2",
Style: "danger", Style: "danger",
Action: map[string]component.ParamsDSL{ Action: []component.ParamsDSL{
"Table.delete": {"model": formName}, {
"name": "Delete",
"type": "Table.delete",
"payload": map[string]interface{}{"model": formName},
},
}, },
Confirm: &component.ConfirmActionDSL{ Confirm: &component.ConfirmActionDSL{
Title: "::Confirm", Title: "::Confirm",