Menu.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php namespace Manage\Api;
  2. use Dever;
  3. use Manage\Lib\Auth;
  4. class Menu extends Auth
  5. {
  6. public function info()
  7. {
  8. # 如果后续增加Root,就要这里置为false
  9. $this->top = true;
  10. $top = Dever::db('menu')->select(array('parent_id' => '0', 'system_id' => $this->user['select']['system_id']));
  11. $result = $menu = array();
  12. $result[] = array
  13. (
  14. 'path' => '/',
  15. 'name' => 'Root',
  16. 'component' => 'Layout',
  17. 'meta' => array
  18. (
  19. 'title' => '首页',
  20. 'icon' => 'home-2-line',
  21. 'breadcrumbHidden' => true,
  22. ),
  23. 'children' => array
  24. (
  25. array
  26. (
  27. 'path' => 'index',
  28. 'name' => 'Index',
  29. 'component' => '@/dever/index/index',
  30. 'meta' => array
  31. (
  32. 'title' => '控制台',
  33. 'icon' => 'home-2-line',
  34. 'noClosable' => true,
  35. )
  36. ),
  37. )
  38. );
  39. foreach ($top as $v) {
  40. $v = $this->getMenu($v);
  41. if ($v) {
  42. $result[] = $v;
  43. }
  44. }
  45. return array('list' => $result);
  46. }
  47. private function getMenu($v, $parent = '')
  48. {
  49. $info = array
  50. (
  51. 'path' => $parent ? '/' . $parent . '/' . $v['key'] : $v['key'],
  52. 'name' => $parent ? $parent . '_' . $v['key'] : $v['key'],
  53. 'meta' => array
  54. (
  55. 'title' => $v['name'],
  56. 'icon' => $v['icon'],
  57. //'noClosable' => true,
  58. 'breadcrumbHidden' => false,
  59. 'dynamicNewTab' => true,
  60. )
  61. );
  62. if ($v['show'] > 1) {
  63. $info['meta']['hidden'] = true;
  64. }
  65. if (isset($v['active']) && $v['active']) {
  66. $info['meta']['activeMenu'] = $v['active'];
  67. }
  68. if ($v['parent_id'] <= 0) {
  69. if ($this->top) {
  70. $info['path'] = '/' . $v['key'];
  71. } else {
  72. $this->top = true;
  73. $info['path'] = '/';
  74. }
  75. $info['component'] = 'Layout';
  76. }
  77. $where = array('parent_id' => $v['id'], 'system_id' => $this->user['select']['system_id']);
  78. $child = Dever::db('menu')->select($where);
  79. if ($child) {
  80. foreach ($child as $v1) {
  81. if (($v1['level'] == 3 || $v1['show'] != 1) && $this->checkMenu($v1['id'])) {
  82. continue;
  83. }
  84. $children = $this->getMenu($v1, $v['key']);
  85. if ($children) {
  86. $info['children'][] = $children;
  87. }
  88. }
  89. if (empty($info['children'])) {
  90. return array();
  91. }
  92. } elseif ($v['path']) {
  93. $info['component'] = '@/dever/page/' . $v['path'];
  94. }
  95. if (!$child) {
  96. if (($v['level'] == 3 || $v['show'] != 1) && $this->checkMenu($v['id'])) {
  97. return false;
  98. }
  99. }
  100. return $info;
  101. }
  102. }