Skip to content

Commit e116194

Browse files
committed
修复路由渲染超三级以上不生效
1 parent 20b8672 commit e116194

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

app/Service/Auth/LoginService.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ public function getRouters() :array
163163
$module_children[] = &$permissionList[$key];
164164
}
165165
}
166-
167166
foreach ($module_children as $key => $value) {
168167
if (!empty($value['children'])) {
169168
$routers[$value['id']] = [
@@ -179,25 +178,7 @@ public function getRouters() :array
179178
],
180179
'children' => []
181180
];
182-
foreach ($value['children'] as $k => $v) {
183-
$temp = [];
184-
if (!empty($v['children'])) {
185-
foreach ($v['children'] as $k1 => $v1) {
186-
$temp[] = [
187-
'name' => $v1['name'],
188-
'path' => $v1['url'],
189-
'hidden' => $v1['hidden'],
190-
'alwaysShow' => true,
191-
'component' => $v1['component'],
192-
'meta' => [
193-
'icon' => $v1['icon'],
194-
'title' => $v1['display_name'],
195-
],
196-
];
197-
}
198-
}
199-
$routers[$value['id']]['children'] = array_merge($routers[$value['id']]['children'], $temp);
200-
}
181+
$routers[$value['id']]['children'] = $this->dealRouteChildren($value['children']);
201182
}else {
202183
array_push($routers['default']['children'], [
203184
'name' => $value['name'],
@@ -215,6 +196,37 @@ public function getRouters() :array
215196
return array_values($routers);
216197
}
217198

199+
/**
200+
* 处理路由下顶级路由下子路由
201+
* @param array $children
202+
* @return array
203+
*/
204+
private function dealRouteChildren(array $children) : array
205+
{
206+
$temp = [];
207+
if (!empty($children)) {
208+
foreach ($children as $k => $v) {
209+
if ($v['type'] == Permission::MENU_TYPE) {
210+
$temp[] = [
211+
'name' => $v['name'],
212+
'path' => $v['url'],
213+
'hidden' => $v['hidden'],
214+
'alwaysShow' => true,
215+
'component' => $v['component'],
216+
'meta' => [
217+
'icon' => $v['icon'],
218+
'title' => $v['display_name'],
219+
],
220+
];
221+
}
222+
if (!empty($v['children'])) {
223+
$temp = array_merge($temp, $this->dealRouteChildren($v['children']));
224+
}
225+
}
226+
}
227+
return $temp;
228+
}
229+
218230
/**
219231
* 处理TOKEN数据
220232
* @param $token

0 commit comments

Comments
 (0)