diff --git a/widgets/component/action.go b/widgets/component/action.go index d109cda9..e0a73dfa 100644 --- a/widgets/component/action.go +++ b/widgets/component/action.go @@ -23,7 +23,8 @@ func (actions Actions) Hash() Actions { h := md4.New() for i := range actions { 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 { data, _ := jsoniter.Marshal(v) key = fmt.Sprintf("%s%s%s", key, k, data) diff --git a/widgets/component/types.go b/widgets/component/types.go index f0ed0c57..64007af3 100644 --- a/widgets/component/types.go +++ b/widgets/component/types.go @@ -30,15 +30,15 @@ type ActionsExport struct { // ActionDSL the component action DSL type ActionDSL struct { - Title string `json:"title,omitempty"` - Width int `json:"width,omitempty"` - Icon string `json:"icon,omitempty"` - Style string `json:"style,omitempty"` - ID string `json:"id,omitempty"` - Xpath string `json:"xpath,omitempty"` - Props PropsDSL `json:"props,omitempty"` - Confirm *ConfirmActionDSL `json:"confirm,omitempty"` - Action map[string]ParamsDSL `json:"action,omitempty"` + Title string `json:"title,omitempty"` + Width int `json:"width,omitempty"` + Icon string `json:"icon,omitempty"` + Style string `json:"style,omitempty"` + ID string `json:"id,omitempty"` + Xpath string `json:"xpath,omitempty"` + Props PropsDSL `json:"props,omitempty"` + Confirm *ConfirmActionDSL `json:"confirm,omitempty"` + Action []ParamsDSL `json:"action,omitempty"` } // ConfirmActionDSL action.confirm diff --git a/widgets/environment/environment_test.go b/widgets/environment/environment_test.go index 089d277c..977af03c 100644 --- a/widgets/environment/environment_test.go +++ b/widgets/environment/environment_test.go @@ -30,7 +30,7 @@ func TestReadFile(t *testing.T) { assert.Equal(t, "::PET ADMIN", res.Get("name")) 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, "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, "icon-trash", res["layout.table.operation.actions[5].icon"]) } diff --git a/widgets/form/form.go b/widgets/form/form.go index 75b3f794..012d9803 100644 --- a/widgets/form/form.go +++ b/widgets/form/form.go @@ -280,14 +280,12 @@ func (dsl *DSL) Actions() []component.ActionsExport { // layout.operation.actions if dsl.Layout != nil && - dsl.Layout.Operation != nil && - dsl.Layout.Operation.Actions != nil && - len(dsl.Layout.Operation.Actions) > 0 { - + dsl.Layout.Actions != nil && + len(dsl.Layout.Actions) > 0 { res = append(res, component.ActionsExport{ Type: "operation", Xpath: "layout.operation.actions", - Actions: dsl.Layout.Operation.Actions.Hash(), + Actions: dsl.Layout.Actions.Hash(), }) } return res diff --git a/widgets/form/layout.go b/widgets/form/layout.go index d38bc84b..a152dca9 100644 --- a/widgets/form/layout.go +++ b/widgets/form/layout.go @@ -15,22 +15,23 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, formID string, fields *FieldsDS layout.Primary = m.PrimaryKey } - if layout.Operation == nil { - layout.Operation = &OperationLayoutDSL{ - Preset: map[string]map[string]interface{}{"save": {}, "back": {}}, - Actions: []component.ActionDSL{ - { - Title: "::Delete", - Icon: "icon-trash-2", - Style: "danger", - Action: map[string]component.ParamsDSL{ - "Form.delete": {"model": formID}, - }, - Confirm: &component.ConfirmActionDSL{ - Title: "::Confirm", - Desc: "::Please confirm, the data cannot be recovered", + if layout.Actions == nil { + layout.Actions = []component.ActionDSL{ + { + Title: "::Delete", + Icon: "icon-trash-2", + Style: "danger", + Action: []component.ParamsDSL{ + { + "name": "Delete", + "type": "Form.delete", + "payload": map[string]interface{}{"model": formID}, }, }, + 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 } - if layout.Operation == nil && form.Layout.Operation != nil { - layout.Operation = &OperationLayoutDSL{ - Actions: []component.ActionDSL{}, - 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.Actions == nil || len(layout.Actions) == 0) && + form.Layout.Actions != nil { + layout.Actions = form.Layout.Actions } 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 } - if layout.Operation == nil { - layout.Operation = &OperationLayoutDSL{ - Preset: map[string]map[string]interface{}{"save": {}, "back": {}}, - Actions: []component.ActionDSL{ - { - Title: "::Delete", - Icon: "icon-trash-2", - Style: "danger", - Action: map[string]component.ParamsDSL{ - "Form.delete": {"model": formID}, - }, - Confirm: &component.ConfirmActionDSL{ - Title: "::Confirm", - Desc: "::Please confirm, the data cannot be recovered", + if layout.Actions == nil { + layout.Actions = []component.ActionDSL{ + { + Title: "::Delete", + Icon: "icon-trash-2", + Style: "danger", + Action: []component.ParamsDSL{ + { + "name": "Delete", + "type": "Form.delete", + "payload": map[string]interface{}{"model": formID}, }, }, + Confirm: &component.ConfirmActionDSL{ + Title: "::Confirm", + Desc: "::Please confirm, the data cannot be recovered", + }, }, } } diff --git a/widgets/form/types.go b/widgets/form/types.go index 7079fead..e5574ca2 100644 --- a/widgets/form/types.go +++ b/widgets/form/types.go @@ -56,16 +56,10 @@ type BindActionDSL struct { // LayoutDSL the form layout DSL type LayoutDSL struct { - Primary string `json:"primary,omitempty"` - Operation *OperationLayoutDSL `json:"operation,omitempty"` - Form *ViewLayoutDSL `json:"form,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"` + Primary string `json:"primary,omitempty"` + Actions component.Actions `json:"actions,omitempty"` + Form *ViewLayoutDSL `json:"form,omitempty"` + Config map[string]interface{} `json:"config,omitempty"` } // FieldsDSL the form fields DSL diff --git a/widgets/table/layout.go b/widgets/table/layout.go index 52fc09cb..1bdc6438 100644 --- a/widgets/table/layout.go +++ b/widgets/table/layout.go @@ -31,8 +31,12 @@ func (layout *LayoutDSL) BindModel(m *gou.Model, fields *FieldsDSL, option map[s Title: "::Create", Icon: "icon-plus", Width: 3, - Action: map[string]component.ParamsDSL{ - "Common.historyPush": {"pathname": fmt.Sprintf("/x/Form/%s/0/edit", formName)}, + Action: []component.ParamsDSL{ + { + "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{ Title: "::View", Icon: "icon-eye", - Action: map[string]component.ParamsDSL{ - "Common.openModal": { - "Form": map[string]interface{}{"type": "view", "model": formName}, + Action: []component.ParamsDSL{ + { + "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{ Title: "::Edit", Icon: "icon-edit-2", - Action: map[string]component.ParamsDSL{ - "Common.openModal": { - "Form": map[string]interface{}{"type": "edit", "model": formName}, + Action: []component.ParamsDSL{ + { + "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", Icon: "icon-trash-2", Style: "danger", - Action: map[string]component.ParamsDSL{ - "Table.delete": {"model": formName}, + Action: []component.ParamsDSL{ + { + "name": "Delete", + "type": "Table.delete", + "payload": map[string]interface{}{"model": formName}, + }, }, Confirm: &component.ConfirmActionDSL{ Title: "::Confirm",