fix: hide menu and sorting (#9141)

This commit is contained in:
2025-06-17 16:14:28 +08:00 committed by GitHub
parent 0df8a33b9e
commit 2c290dbbf7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 121 additions and 8 deletions

View file

@ -29,7 +29,7 @@ func LoadMenus() string {
{ID: "71", Disabled: false, Title: "menu.files", IsShow: true, Label: "File", Path: "/hosts/files"},
{ID: "72", Disabled: false, Title: "menu.monitor", IsShow: true, Label: "Monitorx", Path: "/hosts/monitor/monitor"},
{ID: "74", Disabled: false, Title: "menu.firewall", IsShow: true, Label: "FirewallPort", Path: "/hosts/firewall/port"},
{ID: "75", Disabled: false, Title: "menu.supervisor", IsShow: true, Label: "Process", Path: "/hosts/process/process"},
{ID: "75", Disabled: false, Title: "menu.processManage", IsShow: true, Label: "Process", Path: "/hosts/process/process"},
{ID: "76", Disabled: false, Title: "menu.ssh", IsShow: true, Label: "SSH", Path: "/hosts/ssh/ssh"},
}},
{ID: "8", Disabled: false, Title: "menu.terminal", IsShow: true, Label: "Terminal-Menu", Path: "/hosts/terminal"},
@ -40,6 +40,7 @@ func LoadMenus() string {
{ID: "118", Disabled: false, Title: "xpack.app.app", IsShow: true, Label: "XApp", Path: "/xpack/app"},
{ID: "112", Disabled: false, Title: "xpack.waf.name", IsShow: true, Label: "Dashboard", Path: "/xpack/waf/dashboard"},
{ID: "111", Disabled: false, Title: "xpack.node.nodeManagement", IsShow: true, Label: "Node", Path: "/xpack/node"},
{ID: "119", Disabled: false, Title: "xpack.upage", IsShow: true, Label: "Upage", Path: "/xpack/upage"},
{ID: "113", Disabled: false, Title: "xpack.monitor.name", IsShow: true, Label: "MonitorDashboard", Path: "/xpack/monitor/dashboard"},
{ID: "114", Disabled: false, Title: "xpack.tamper.tamper", IsShow: true, Label: "Tamper", Path: "/xpack/tamper"},
{ID: "115", Disabled: false, Title: "xpack.exchange.exchange", IsShow: true, Label: "FileExange", Path: "/xpack/exchange/file"},

View file

@ -17,6 +17,7 @@ func Init() {
migrations.InitGoogle,
migrations.AddTaskDB,
migrations.AddXpackHideMenu,
migrations.UpdateXpackHideMenu,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)

View file

@ -312,7 +312,119 @@ var AddXpackHideMenu = &gormigrate.Migration{
}
}
if !exists {
menus[i].Children = append(menus[i].Children, newItem)
menus[i].Children = append([]dto.ShowMenu{newItem}, menus[i].Children...)
}
break
}
}
updatedJSON, err := json.Marshal(menus)
if err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}
var UpdateXpackHideMenu = &gormigrate.Migration{
ID: "20250617-update-xpack-hide-menu",
Migrate: func(tx *gorm.DB) error {
var menuJSON string
if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Pluck("value", &menuJSON).Error; err != nil {
return err
}
var menus []dto.ShowMenu
if err := json.Unmarshal([]byte(menuJSON), &menus); err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
newItem := dto.ShowMenu{
ID: "119",
Disabled: false,
Title: "xpack.upage",
IsShow: true,
Label: "Upage",
Path: "/xpack/upage",
}
for i, menu := range menus {
if menu.ID == "11" {
exists := false
for _, child := range menu.Children {
if child.ID == newItem.ID {
exists = true
break
}
}
if exists {
break
}
insertIndex := -1
for j, child := range menu.Children {
if child.ID == "111" {
insertIndex = j
break
}
}
if insertIndex != -1 {
children := menu.Children
menus[i].Children = append(children[:insertIndex+1], append([]dto.ShowMenu{newItem}, children[insertIndex+1:]...)...)
} else {
menus[i].Children = append([]dto.ShowMenu{newItem}, menus[i].Children...)
}
break
}
}
for i, menu := range menus {
if menu.ID == "11" {
existsIndex := -1
for j, child := range menu.Children {
if child.ID == "118" {
existsIndex = j
break
}
}
if existsIndex == 0 {
break
}
var item118 dto.ShowMenu
if existsIndex != -1 {
item118 = menu.Children[existsIndex]
menus[i].Children = append(menu.Children[:existsIndex], menu.Children[existsIndex+1:]...)
} else {
item118 = dto.ShowMenu{
ID: "118",
Disabled: false,
Title: "xpack.app.app",
IsShow: true,
Label: "XApp",
Path: "/xpack/app",
}
}
menus[i].Children = append([]dto.ShowMenu{item118}, menus[i].Children...)
break
}
}
for i, menu := range menus {
if menu.ID == "7" {
for j, child := range menu.Children {
if child.ID == "75" {
if child.Title != "menu.processManage" {
menus[i].Children[j].Title = "menu.processManage"
}
break
}
}
break
}

View file

@ -18,7 +18,11 @@
<span>{{ $t(subItem.meta?.title as string, 2) }}</span>
</template>
</el-menu-item>
<el-menu-item :index="''" v-else-if="subItem.path === '/xpack/upage'" @click="goUpage">
<template #title>
<span style="margin-left: 10px">{{ $t('xpack.upage') }}</span>
</template>
</el-menu-item>
<el-menu-item v-else :index="subItem.path">
<el-icon v-if="subItem.meta?.icon">
<SvgIcon :iconName="(subItem.meta?.icon as string)" />
@ -28,11 +32,6 @@
<span v-else style="margin-left: 10px">{{ $t(subItem.meta?.title as string, 2) }}</span>
</template>
</el-menu-item>
<el-menu-item :index="''" v-if="subItem.path === '/xpack/node'" @click="goUpage">
<template #title>
<span style="margin-left: 10px">{{ $t('xpack.upage') }}</span>
</template>
</el-menu-item>
</template>
</template>