@@ -169,10 +169,37 @@ const useRouteStore = defineStore(
169
169
return returnRoutes
170
170
} )
171
171
172
+ // TODO 将设置 meta.sidebar 的属性转换成 meta.menu ,过渡处理,未来将被弃用
173
+ let isUsedDeprecatedAttribute = false
174
+ function converDeprecatedAttribute < T extends Route . recordMainRaw [ ] > ( routes : T ) : T {
175
+ routes . forEach ( ( route ) => {
176
+ route . children = converDeprecatedAttributeRecursive ( route . children )
177
+ } )
178
+ if ( isUsedDeprecatedAttribute ) {
179
+ console . warn ( '[Fantastic-admin] 路由配置中的 "sidebar" 属性即将被弃用, 请尽快替换为 "menu" 属性' )
180
+ }
181
+ return routes
182
+ }
183
+ function converDeprecatedAttributeRecursive ( routes : RouteRecordRaw [ ] ) {
184
+ if ( routes ) {
185
+ routes . forEach ( ( route ) => {
186
+ if ( typeof route . meta ?. sidebar === 'boolean' ) {
187
+ isUsedDeprecatedAttribute = true
188
+ route . meta . menu = route . meta . sidebar
189
+ delete route . meta . sidebar
190
+ }
191
+ if ( route . children ) {
192
+ converDeprecatedAttributeRecursive ( route . children )
193
+ }
194
+ } )
195
+ }
196
+ return routes
197
+ }
198
+
172
199
// 根据权限动态生成路由(前端生成)
173
200
async function generateRoutesAtFront ( asyncRoutes : Route . recordMainRaw [ ] ) {
174
201
// 设置 routes 数据
175
- routesRaw . value = cloneDeep ( asyncRoutes ) as any
202
+ routesRaw . value = converDeprecatedAttribute ( cloneDeep ( asyncRoutes ) as any )
176
203
if ( settingsStore . settings . app . enablePermission ) {
177
204
await userStore . getPermissions ( )
178
205
}
@@ -203,7 +230,7 @@ const useRouteStore = defineStore(
203
230
async function generateRoutesAtBack ( ) {
204
231
await apiApp . routeList ( ) . then ( async ( res ) => {
205
232
// 设置 routes 数据
206
- routesRaw . value = formatBackRoutes ( res . data ) as any
233
+ routesRaw . value = converDeprecatedAttribute ( formatBackRoutes ( res . data ) as any )
207
234
if ( settingsStore . settings . app . enablePermission ) {
208
235
await userStore . getPermissions ( )
209
236
}
0 commit comments