Menu.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. $menu = $this->getMenu($v);
  41. }
  42. if ($menu) {
  43. $result[] = $menu;
  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' => $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'] == 2) {
  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)->fetchAll();
  79. if ($child) {
  80. foreach ($child as $v1) {
  81. if ($v1['func'] == 1 && $this->checkMenu($v1['id'])) {
  82. continue;
  83. }
  84. $info['children'][] = $this->getMenu($v1, $v['key']);
  85. }
  86. } elseif ($v['path']) {
  87. $info['component'] = '@/dever/page/' . $v['path'];
  88. }
  89. return $info;
  90. }
  91. }