Menu.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. $this->top = false;
  9. $top = Dever::db('menu')->select(array('parent_id' => '0', 'system_id' => $this->user['select']['system_id']));
  10. $result = $menu = array();
  11. foreach ($top as $v) {
  12. $menu = $this->getMenu($v);
  13. }
  14. if ($menu) {
  15. $result[] = $menu;
  16. }
  17. $result[] = array
  18. (
  19. 'path' => '/:pathMatch(.*)*',
  20. 'component' => '@/views/403',
  21. 'name' => 'NotFound',
  22. 'meta' => array
  23. (
  24. 'hidden' => true,
  25. )
  26. );
  27. return array('list' => $result);
  28. }
  29. private function getMenu($v, $parent = '')
  30. {
  31. $info = array
  32. (
  33. 'path' => $parent ? '/' . $parent . '/' . $v['key'] : $v['key'],
  34. 'name' => $v['key'],
  35. 'meta' => array
  36. (
  37. 'title' => $v['name'],
  38. 'icon' => $v['icon'],
  39. //'noClosable' => true,
  40. 'breadcrumbHidden' => true,
  41. 'dynamicNewTab' => true,
  42. )
  43. );
  44. if ($v['show'] == 2) {
  45. $info['meta']['hidden'] = true;
  46. }
  47. if (isset($v['active']) && $v['active']) {
  48. $info['meta']['activeMenu'] = $v['active'];
  49. }
  50. if ($v['parent_id'] <= 0) {
  51. if ($this->top) {
  52. $info['path'] = '/' . $v['key'];
  53. } else {
  54. $this->top = true;
  55. $info['path'] = '/';
  56. }
  57. $info['component'] = 'Layout';
  58. }
  59. $where = array('parent_id' => $v['id'], 'system_id' => $this->user['select']['system_id']);
  60. $child = Dever::db('menu')->select($where)->fetchAll();
  61. if ($child) {
  62. foreach ($child as $v1) {
  63. if ($v1['func'] == 1 && $this->checkMenu($v1['id'])) {
  64. continue;
  65. }
  66. $info['children'][] = $this->getMenu($v1, $v['key']);
  67. }
  68. } elseif ($v['path']) {
  69. $info['component'] = '@/views/page/' . $v['path'];
  70. }
  71. return $info;
  72. }
  73. }