mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 完成前端动态数据准备
This commit is contained in:
parent
1b8d2d50d9
commit
2d05d3dd95
@ -13,6 +13,7 @@ use app\model\AdminMenu;
|
||||
use app\model\AdminUser;
|
||||
use app\model\AdminUserData;
|
||||
use app\util\ReturnCode;
|
||||
use app\util\RouterTool;
|
||||
use app\util\Tools;
|
||||
|
||||
class Login extends Base {
|
||||
@ -114,7 +115,7 @@ class Login extends Base {
|
||||
array_push($access, "");
|
||||
$menus = (new AdminMenu())->whereIn('url', $access)->where('show', 1)->select();
|
||||
$menus = Tools::listToTree(Tools::buildArrFromObj($menus));
|
||||
$menus = $this->rebuildMenu($menus);
|
||||
RouterTool::buildVueRouter($menus);
|
||||
|
||||
return $this->buildSuccess($menus);
|
||||
} else {
|
||||
@ -123,22 +124,6 @@ class Login extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
private function rebuildMenu($menus) {
|
||||
foreach ($menus as $key => $menu) {
|
||||
if (isset($menu['children'])) {
|
||||
foreach ($menu['children'] as $cKey => $child) {
|
||||
if (!isset($child['children'])) {
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unset($menus[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户权限数据
|
||||
* @param $uid
|
||||
|
@ -47,6 +47,37 @@ class RouterTool {
|
||||
file_put_contents($routePath, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建前端路由
|
||||
* TODO::待算法优化
|
||||
* @param $menus
|
||||
* @return mixed
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public static function buildVueRouter(&$menus) {
|
||||
foreach ($menus as $key => $menu) {
|
||||
if (isset($menu['children'])) {
|
||||
foreach ($menu['children'] as $cKey => $child) {
|
||||
if (!isset($child['children'])) {
|
||||
unset($menus[$key]['children'][$cKey]);
|
||||
} else {
|
||||
$menus[$key]['children'][$cKey]['children'] = [];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unset($menus[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($menus as $k => $m) {
|
||||
if (isset($m['children']) && !empty($m['children'])) {
|
||||
$menus[$k]['children'] = array_values($m['children']);
|
||||
} else {
|
||||
unset($menus[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建菜单权限细节
|
||||
* @param $menu
|
||||
|
Loading…
x
Reference in New Issue
Block a user