Menu.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php namespace Manage\Api;
  2. use Dever;
  3. use Manage\Lib\Auth;
  4. class Menu extends Auth
  5. {
  6. private $list = 'list,table,card';
  7. public function info()
  8. {
  9. $top = Dever::db('menu')->select(array('parent_key' => '/'));
  10. $result = $menu = array();
  11. foreach ($top as $v) {
  12. $menu = $this->getMenu($v);
  13. }
  14. $result[] = $menu;
  15. $result[] = array
  16. (
  17. 'path' => '/:pathMatch(.*)*',
  18. 'component' => '@/views/403',
  19. 'name' => 'NotFound',
  20. 'meta' => array
  21. (
  22. 'hidden' => true,
  23. )
  24. );
  25. return array('list' => $result);
  26. }
  27. private function getMenu($v)
  28. {
  29. $info = array
  30. (
  31. 'path' => $v['key'],
  32. 'name' => ucfirst($v['key']),
  33. 'meta' => array
  34. (
  35. 'title' => $v['name'],
  36. 'icon' => $v['icon'],
  37. //'noClosable' => true,
  38. //'breadcrumbHidden' => true,
  39. 'dynamicNewTab' => true,
  40. )
  41. );
  42. if ($v['show'] == 2) {
  43. $info['meta']['hidden'] = true;
  44. }
  45. if (isset($v['active']) && $v['active']) {
  46. $info['meta']['activeMenu'] = $v['active'];
  47. }
  48. if ($v['parent_key'] == '/') {
  49. $info['path'] = '/';
  50. $info['component'] = 'Layout';
  51. }
  52. $child = Dever::db('menu')->select(array('parent_key' => $v['key']))->fetchAll();
  53. if ($child) {
  54. foreach ($child as $v1) {
  55. $info['children'][] = $this->getMenu($v1);
  56. if (isset($v1['link']) && strstr($this->list, $v1['link'])) {
  57. $v1['active'] = '/' . $v1['key'];
  58. $v1['name'] .= '更新';
  59. $v1['link'] = 'update';
  60. $v1['key'] .= '/update';
  61. $v1['show'] = 2;
  62. $info['children'][] = $this->getMenu($v1);
  63. }
  64. }
  65. } elseif ($v['link']) {
  66. $info['component'] = '@/views/page/' . $v['link'];
  67. }
  68. return $info;
  69. }
  70. }