@@ -50,44 +50,73 @@ func (i *initMenu) InitializeData(ctx context.Context) (next context.Context, er
50
50
if ! ok {
51
51
return ctx , system .ErrMissingDBContext
52
52
}
53
- entities := []SysBaseMenu {
53
+
54
+ // 定义所有菜单
55
+ allMenus := []SysBaseMenu {
54
56
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "dashboard" , Name : "dashboard" , Component : "view/dashboard/index.vue" , Sort : 1 , Meta : Meta {Title : "仪表盘" , Icon : "odometer" }},
55
57
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "about" , Name : "about" , Component : "view/about/index.vue" , Sort : 9 , Meta : Meta {Title : "关于我们" , Icon : "info-filled" }},
56
58
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "admin" , Name : "superAdmin" , Component : "view/superAdmin/index.vue" , Sort : 3 , Meta : Meta {Title : "超级管理员" , Icon : "user" }},
57
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "authority" , Name : "authority" , Component : "view/superAdmin/authority/authority.vue" , Sort : 1 , Meta : Meta {Title : "角色管理" , Icon : "avatar" }},
58
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "menu" , Name : "menu" , Component : "view/superAdmin/menu/menu.vue" , Sort : 2 , Meta : Meta {Title : "菜单管理" , Icon : "tickets" , KeepAlive : true }},
59
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "api" , Name : "api" , Component : "view/superAdmin/api/api.vue" , Sort : 3 , Meta : Meta {Title : "api管理" , Icon : "platform" , KeepAlive : true }},
60
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "user" , Name : "user" , Component : "view/superAdmin/user/user.vue" , Sort : 4 , Meta : Meta {Title : "用户管理" , Icon : "coordinate" }},
61
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "dictionary" , Name : "dictionary" , Component : "view/superAdmin/dictionary/sysDictionary.vue" , Sort : 5 , Meta : Meta {Title : "字典管理" , Icon : "notebook" }},
62
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "operation" , Name : "operation" , Component : "view/superAdmin/operation/sysOperationRecord.vue" , Sort : 6 , Meta : Meta {Title : "操作历史" , Icon : "pie-chart" }},
63
59
{MenuLevel : 0 , Hidden : true , ParentId : 0 , Path : "person" , Name : "person" , Component : "view/person/person.vue" , Sort : 4 , Meta : Meta {Title : "个人信息" , Icon : "message" }},
64
60
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "example" , Name : "example" , Component : "view/example/index.vue" , Sort : 7 , Meta : Meta {Title : "示例文件" , Icon : "management" }},
65
- {MenuLevel : 0 , Hidden : false , ParentId : 11 , Path : "upload" , Name : "upload" , Component : "view/example/upload/upload.vue" , Sort : 5 , Meta : Meta {Title : "媒体库(上传下载)" , Icon : "upload" }},
66
- {MenuLevel : 0 , Hidden : false , ParentId : 11 , Path : "breakpoint" , Name : "breakpoint" , Component : "view/example/breakpoint/breakpoint.vue" , Sort : 6 , Meta : Meta {Title : "断点续传" , Icon : "upload-filled" }},
67
- {MenuLevel : 0 , Hidden : false , ParentId : 11 , Path : "customer" , Name : "customer" , Component : "view/example/customer/customer.vue" , Sort : 7 , Meta : Meta {Title : "客户列表(资源示例)" , Icon : "avatar" }},
68
61
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "systemTools" , Name : "systemTools" , Component : "view/systemTools/index.vue" , Sort : 5 , Meta : Meta {Title : "系统工具" , Icon : "tools" }},
69
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "autoCode" , Name : "autoCode" , Component : "view/systemTools/autoCode/index.vue" , Sort : 1 , Meta : Meta {Title : "代码生成器" , Icon : "cpu" , KeepAlive : true }},
70
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "formCreate" , Name : "formCreate" , Component : "view/systemTools/formCreate/index.vue" , Sort : 3 , Meta : Meta {Title : "表单生成器" , Icon : "magic-stick" , KeepAlive : true }},
71
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "system" , Name : "system" , Component : "view/systemTools/system/system.vue" , Sort : 4 , Meta : Meta {Title : "系统配置" , Icon : "operation" }},
72
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "autoCodeAdmin" , Name : "autoCodeAdmin" , Component : "view/systemTools/autoCodeAdmin/index.vue" , Sort : 2 , Meta : Meta {Title : "自动化代码管理" , Icon : "magic-stick" }},
73
- {MenuLevel : 0 , Hidden : true , ParentId : 15 , Path : "autoCodeEdit/:id" , Name : "autoCodeEdit" , Component : "view/systemTools/autoCode/index.vue" , Sort : 0 , Meta : Meta {Title : "自动化代码-${id}" , Icon : "magic-stick" }},
74
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "autoPkg" , Name : "autoPkg" , Component : "view/systemTools/autoPkg/autoPkg.vue" , Sort : 0 , Meta : Meta {Title : "模板配置" , Icon : "folder" }},
75
62
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "https://www.gin-vue-admin.com" , Name : "https://www.gin-vue-admin.com" , Component : "/" , Sort : 0 , Meta : Meta {Title : "官方网站" , Icon : "customer-gva" }},
76
63
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "state" , Name : "state" , Component : "view/system/state.vue" , Sort : 8 , Meta : Meta {Title : "服务器状态" , Icon : "cloudy" }},
77
64
{MenuLevel : 0 , Hidden : false , ParentId : 0 , Path : "plugin" , Name : "plugin" , Component : "view/routerHolder.vue" , Sort : 6 , Meta : Meta {Title : "插件系统" , Icon : "cherry" }},
78
- {MenuLevel : 0 , Hidden : false , ParentId : 24 , Path : "https://plugin.gin-vue-admin.com/" , Name : "https://plugin.gin-vue-admin.com/" , Component : "https://plugin.gin-vue-admin.com/" , Sort : 0 , Meta : Meta {Title : "插件市场" , Icon : "shop" }},
79
- {MenuLevel : 0 , Hidden : false , ParentId : 24 , Path : "installPlugin" , Name : "installPlugin" , Component : "view/systemTools/installPlugin/index.vue" , Sort : 1 , Meta : Meta {Title : "插件安装" , Icon : "box" }},
80
- {MenuLevel : 0 , Hidden : false , ParentId : 24 , Path : "pubPlug" , Name : "pubPlug" , Component : "view/systemTools/pubPlug/pubPlug.vue" , Sort : 3 , Meta : Meta {Title : "打包插件" , Icon : "files" }},
81
- {MenuLevel : 0 , Hidden : false , ParentId : 24 , Path : "plugin-email" , Name : "plugin-email" , Component : "plugin/email/view/index.vue" , Sort : 4 , Meta : Meta {Title : "邮件插件" , Icon : "message" }},
82
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "exportTemplate" , Name : "exportTemplate" , Component : "view/systemTools/exportTemplate/exportTemplate.vue" , Sort : 5 , Meta : Meta {Title : "导出模板" , Icon : "reading" }},
83
- {MenuLevel : 0 , Hidden : false , ParentId : 24 , Path : "anInfo" , Name : "anInfo" , Component : "plugin/announcement/view/info.vue" , Sort : 5 , Meta : Meta {Title : "公告管理[示例]" , Icon : "scaleToOriginal" }},
84
- {MenuLevel : 0 , Hidden : false , ParentId : 3 , Path : "sysParams" , Name : "sysParams" , Component : "view/superAdmin/params/sysParams.vue" , Sort : 7 , Meta : Meta {Title : "参数管理" , Icon : "compass" }},
85
- {MenuLevel : 0 , Hidden : false , ParentId : 15 , Path : "picture" , Name : "picture" , Component : "view/systemTools/autoCode/picture.vue" , Sort : 6 , Meta : Meta {Title : "AI页面绘制" , Icon : "picture-filled" }},
86
65
}
87
- if err = db .Create (& entities ).Error ; err != nil {
88
- return ctx , errors .Wrap (err , SysBaseMenu {}.TableName ()+ "表数据初始化失败!" )
66
+
67
+ // 先创建父级菜单(ParentId = 0 的菜单)
68
+ if err = db .Create (& allMenus ).Error ; err != nil {
69
+ return ctx , errors .Wrap (err , SysBaseMenu {}.TableName ()+ "父级菜单初始化失败!" )
70
+ }
71
+
72
+ // 建立菜单映射 - 通过Name查找已创建的菜单及其ID
73
+ menuNameMap := make (map [string ]uint )
74
+ for _ , menu := range allMenus {
75
+ menuNameMap [menu .Name ] = menu .ID
76
+ }
77
+
78
+ // 定义子菜单,并设置正确的ParentId
79
+ childMenus := []SysBaseMenu {
80
+ // superAdmin子菜单
81
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "authority" , Name : "authority" , Component : "view/superAdmin/authority/authority.vue" , Sort : 1 , Meta : Meta {Title : "角色管理" , Icon : "avatar" }},
82
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "menu" , Name : "menu" , Component : "view/superAdmin/menu/menu.vue" , Sort : 2 , Meta : Meta {Title : "菜单管理" , Icon : "tickets" , KeepAlive : true }},
83
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "api" , Name : "api" , Component : "view/superAdmin/api/api.vue" , Sort : 3 , Meta : Meta {Title : "api管理" , Icon : "platform" , KeepAlive : true }},
84
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "user" , Name : "user" , Component : "view/superAdmin/user/user.vue" , Sort : 4 , Meta : Meta {Title : "用户管理" , Icon : "coordinate" }},
85
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "dictionary" , Name : "dictionary" , Component : "view/superAdmin/dictionary/sysDictionary.vue" , Sort : 5 , Meta : Meta {Title : "字典管理" , Icon : "notebook" }},
86
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "operation" , Name : "operation" , Component : "view/superAdmin/operation/sysOperationRecord.vue" , Sort : 6 , Meta : Meta {Title : "操作历史" , Icon : "pie-chart" }},
87
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["superAdmin" ], Path : "sysParams" , Name : "sysParams" , Component : "view/superAdmin/params/sysParams.vue" , Sort : 7 , Meta : Meta {Title : "参数管理" , Icon : "compass" }},
88
+
89
+ // example子菜单
90
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["example" ], Path : "upload" , Name : "upload" , Component : "view/example/upload/upload.vue" , Sort : 5 , Meta : Meta {Title : "媒体库(上传下载)" , Icon : "upload" }},
91
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["example" ], Path : "breakpoint" , Name : "breakpoint" , Component : "view/example/breakpoint/breakpoint.vue" , Sort : 6 , Meta : Meta {Title : "断点续传" , Icon : "upload-filled" }},
92
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["example" ], Path : "customer" , Name : "customer" , Component : "view/example/customer/customer.vue" , Sort : 7 , Meta : Meta {Title : "客户列表(资源示例)" , Icon : "avatar" }},
93
+
94
+ // systemTools子菜单
95
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "autoCode" , Name : "autoCode" , Component : "view/systemTools/autoCode/index.vue" , Sort : 1 , Meta : Meta {Title : "代码生成器" , Icon : "cpu" , KeepAlive : true }},
96
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "formCreate" , Name : "formCreate" , Component : "view/systemTools/formCreate/index.vue" , Sort : 3 , Meta : Meta {Title : "表单生成器" , Icon : "magic-stick" , KeepAlive : true }},
97
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "system" , Name : "system" , Component : "view/systemTools/system/system.vue" , Sort : 4 , Meta : Meta {Title : "系统配置" , Icon : "operation" }},
98
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "autoCodeAdmin" , Name : "autoCodeAdmin" , Component : "view/systemTools/autoCodeAdmin/index.vue" , Sort : 2 , Meta : Meta {Title : "自动化代码管理" , Icon : "magic-stick" }},
99
+ {MenuLevel : 1 , Hidden : true , ParentId : menuNameMap ["systemTools" ], Path : "autoCodeEdit/:id" , Name : "autoCodeEdit" , Component : "view/systemTools/autoCode/index.vue" , Sort : 0 , Meta : Meta {Title : "自动化代码-${id}" , Icon : "magic-stick" }},
100
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "autoPkg" , Name : "autoPkg" , Component : "view/systemTools/autoPkg/autoPkg.vue" , Sort : 0 , Meta : Meta {Title : "模板配置" , Icon : "folder" }},
101
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "exportTemplate" , Name : "exportTemplate" , Component : "view/systemTools/exportTemplate/exportTemplate.vue" , Sort : 5 , Meta : Meta {Title : "导出模板" , Icon : "reading" }},
102
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["systemTools" ], Path : "picture" , Name : "picture" , Component : "view/systemTools/autoCode/picture.vue" , Sort : 6 , Meta : Meta {Title : "AI页面绘制" , Icon : "picture-filled" }},
103
+
104
+ // plugin子菜单
105
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["plugin" ], Path : "https://plugin.gin-vue-admin.com/" , Name : "https://plugin.gin-vue-admin.com/" , Component : "https://plugin.gin-vue-admin.com/" , Sort : 0 , Meta : Meta {Title : "插件市场" , Icon : "shop" }},
106
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["plugin" ], Path : "installPlugin" , Name : "installPlugin" , Component : "view/systemTools/installPlugin/index.vue" , Sort : 1 , Meta : Meta {Title : "插件安装" , Icon : "box" }},
107
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["plugin" ], Path : "pubPlug" , Name : "pubPlug" , Component : "view/systemTools/pubPlug/pubPlug.vue" , Sort : 3 , Meta : Meta {Title : "打包插件" , Icon : "files" }},
108
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["plugin" ], Path : "plugin-email" , Name : "plugin-email" , Component : "plugin/email/view/index.vue" , Sort : 4 , Meta : Meta {Title : "邮件插件" , Icon : "message" }},
109
+ {MenuLevel : 1 , Hidden : false , ParentId : menuNameMap ["plugin" ], Path : "anInfo" , Name : "anInfo" , Component : "plugin/announcement/view/info.vue" , Sort : 5 , Meta : Meta {Title : "公告管理[示例]" , Icon : "scaleToOriginal" }},
110
+ }
111
+
112
+ // 创建子菜单
113
+ if err = db .Create (& childMenus ).Error ; err != nil {
114
+ return ctx , errors .Wrap (err , SysBaseMenu {}.TableName ()+ "子菜单初始化失败!" )
89
115
}
90
- next = context .WithValue (ctx , i .InitializerName (), entities )
116
+
117
+ // 组合所有菜单作为返回结果
118
+ allEntities := append (allMenus , childMenus ... )
119
+ next = context .WithValue (ctx , i .InitializerName (), allEntities )
91
120
return next , nil
92
121
}
93
122
0 commit comments