Merge pull request #976 from trheyi/main

Refactor menu processing logic to improve error handling and streamli…
This commit is contained in:
Max 2025-05-27 12:40:40 +08:00 committed by GitHub
commit 72dca49e54
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -159,12 +159,11 @@ func exportAPI() error {
process = "yao.app.Menu" process = "yao.app.Menu"
args := []interface{}{} args := []interface{}{}
if Setting.Menu.Process != "" { if Setting.Menu.Args != nil {
if Setting.Menu.Args != nil { args = Setting.Menu.Args
args = Setting.Menu.Args
}
} }
args = append(args, "$query.locale")
path = api.Path{ path = api.Path{
Label: "App Menu", Label: "App Menu",
Description: "App Menu", Description: "App Menu",
@ -386,36 +385,21 @@ func processIcons(process *process.Process) interface{} {
func processMenu(p *process.Process) interface{} { func processMenu(p *process.Process) interface{} {
if Setting.Menu.Process != "" { if Setting.Menu.Process == "" {
exception.New("menu.process is required", 400).Throw()
return process.
New(Setting.Menu.Process, p.Args...).
WithGlobal(p.Global).
WithSID(p.Sid).
Run()
} }
args := map[string]interface{}{ handle, err := process.Of(Setting.Menu.Process, p.Args...)
"select": []string{"id", "name", "icon", "parent", "path", "blocks", "visible_menu"}, if err != nil {
"withs": map[string]interface{}{ exception.New(err.Error(), 400).Throw()
"children": map[string]interface{}{
"query": map[string]interface{}{
"select": []string{"id", "name", "icon", "parent", "path", "blocks", "visible_menu"},
},
},
},
"wheres": []map[string]interface{}{
{"column": "status", "value": "enabled"},
{"column": "parent", "op": "null"},
},
"limit": 200,
"orders": []map[string]interface{}{{"column": "rank", "option": "asc"}},
} }
return process.
New("models.xiang.menu.get", args). err = handle.WithGlobal(p.Global).WithSID(p.Sid).Execute()
WithGlobal(p.Global). if err != nil {
WithSID(p.Sid). exception.New(err.Error(), 500).Throw()
Run() }
defer handle.Dispose()
return handle.Value()
} }
func processSetting(process *process.Process) interface{} { func processSetting(process *process.Process) interface{} {