1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-22 03:32:47 +08:00
koogua f318fccada !9 修正插入数据不一致以及后台菜单参数类型报错
* 1.修正插入的管理帐号数据
* 纠正迁移文件和时间代码中字段不一致
* 更新版本号
* 完善后台今日统计,增加权限白名单,增加后台首页菜单,调整后台登录页样式
* Merge branch 'koogua/I1XFCF' of https://gitee.com/koogua/course-tencen…
* 前台学习资料部分完成
* !2 后台运营统计合并
* 后台学习资料部分完成
* Merge branch 'master' into develop
* Merge branch 'master' of https://github.com/xiaochong0302/course-tencent-cloud
* 1.增加changelog.md
* 1.简化部分路由地址
* Merge pull request #2 from xiaochong0302/dependabot/composer/symfony/h…
* Bump symfony/http-foundation from 4.3.4 to 5.1.6
2020-10-26 20:09:31 +08:00

127 lines
3.6 KiB
PHP

<?php
namespace App\Http\Admin\Services;
use App\Services\Auth\Admin as AdminAuth;
use Phalcon\Mvc\User\Component;
class AuthMenu extends Component
{
protected $authInfo;
protected $authNodes = [];
protected $ownedRoutes = [];
protected $owned1stLevelIds = [];
protected $owned2ndLevelIds = [];
protected $owned3rdLevelIds = [];
public function __construct()
{
$this->authInfo = $this->getAuthInfo();
$this->authNodes = $this->getAuthNodes();
$this->setOwnedLevelIds();
}
public function getTopMenus()
{
$menus = [];
foreach ($this->authNodes as $node) {
if (($this->authInfo['root'] == 1) || in_array($node['id'], $this->owned1stLevelIds)) {
$menus[] = [
'id' => $node['id'],
'title' => $node['title'],
];
}
}
return $menus;
}
public function getLeftMenus()
{
$menus = [];
foreach ($this->authNodes as $key => $level) {
foreach ($level['children'] as $key2 => $level2) {
foreach ($level2['children'] as $key3 => $level3) {
$allowed = ($this->authInfo['root'] == 1) || in_array($level3['id'], $this->owned3rdLevelIds);
$params = $level3['params'] ?? [];
if ($level3['type'] == 'menu' && $allowed) {
$menus[$key]['id'] = $level['id'];
$menus[$key]['title'] = $level['title'];
$menus[$key]['children'][$key2]['id'] = $level2['id'];
$menus[$key]['children'][$key2]['title'] = $level2['title'];
$menus[$key]['children'][$key2]['children'][$key3] = [
'id' => $level3['id'],
'title' => $level3['title'],
'url' => $this->url->get(['for' => $level3['route']], $params),
];
}
}
}
}
return $menus;
}
protected function setOwnedLevelIds()
{
$routeIdMapping = $this->getRouteIdMapping();
if (!$routeIdMapping) return;
$owned1stLevelIds = [];
$owned2ndLevelIds = [];
$owned3rdLevelIds = [];
foreach ($routeIdMapping as $key => $value) {
$ids = explode('-', $value);
if (is_array($this->authInfo['routes']) && in_array($key, $this->authInfo['routes'])) {
$owned1stLevelIds[] = $ids[0];
$owned2ndLevelIds[] = $ids[0] . '-' . $ids[1];
$owned3rdLevelIds[] = $value;
}
}
$this->owned1stLevelIds = array_unique($owned1stLevelIds);
$this->owned2ndLevelIds = array_unique($owned2ndLevelIds);
$this->owned3rdLevelIds = array_unique($owned3rdLevelIds);
}
protected function getRouteIdMapping()
{
$mapping = [];
foreach ($this->authNodes as $level) {
foreach ($level['children'] as $level2) {
foreach ($level2['children'] as $level3) {
if ($level3['type'] == 'menu') {
$mapping[$level3['route']] = $level3['id'];
}
}
}
}
return $mapping;
}
protected function getAuthNodes()
{
$authNode = new AuthNode();
return $authNode->getNodes();
}
protected function getAuthInfo()
{
/**
* @var AdminAuth $auth
*/
$auth = $this->getDI()->get('auth');
return $auth->getAuthInfo();
}
}