File tree Expand file tree Collapse file tree 2 files changed +33
-17
lines changed Expand file tree Collapse file tree 2 files changed +33
-17
lines changed Original file line number Diff line number Diff line change 1313use app \model \AdminUser ;
1414use app \model \AdminUserData ;
1515use app \util \ReturnCode ;
16+ use app \util \RouterTool ;
1617use app \util \Tools ;
1718
1819class Login extends Base {
@@ -114,7 +115,7 @@ public function getAccessMenu() {
114115 array_push ($ access , "" );
115116 $ menus = (new AdminMenu ())->whereIn ('url ' , $ access )->where ('show ' , 1 )->select ();
116117 $ menus = Tools::listToTree (Tools::buildArrFromObj ($ menus ));
117- $ menus = $ this -> rebuildMenu ($ menus );
118+ RouterTool:: buildVueRouter ($ menus );
118119
119120 return $ this ->buildSuccess ($ menus );
120121 } else {
@@ -123,22 +124,6 @@ public function getAccessMenu() {
123124 }
124125 }
125126
126- private function rebuildMenu ($ menus ) {
127- foreach ($ menus as $ key => $ menu ) {
128- if (isset ($ menu ['children ' ])) {
129- foreach ($ menu ['children ' ] as $ cKey => $ child ) {
130- if (!isset ($ child ['children ' ])) {
131-
132- }
133- }
134- } else {
135- unset($ menus [$ key ]);
136- }
137- }
138-
139- return $ menus ;
140- }
141-
142127 /**
143128 * 获取用户权限数据
144129 * @param $uid
Original file line number Diff line number Diff line change @@ -47,6 +47,37 @@ public static function buildAdminRouter() {
4747 file_put_contents ($ routePath , $ context );
4848 }
4949
50+ /**
51+ * 构建前端路由
52+ * TODO::待算法优化
53+ * @param $menus
54+ * @return mixed
55+ * @author zhaoxiang <[email protected] > 56+ */
57+ public static function buildVueRouter (&$ menus ) {
58+ foreach ($ menus as $ key => $ menu ) {
59+ if (isset ($ menu ['children ' ])) {
60+ foreach ($ menu ['children ' ] as $ cKey => $ child ) {
61+ if (!isset ($ child ['children ' ])) {
62+ unset($ menus [$ key ]['children ' ][$ cKey ]);
63+ } else {
64+ $ menus [$ key ]['children ' ][$ cKey ]['children ' ] = [];
65+ }
66+ }
67+ } else {
68+ unset($ menus [$ key ]);
69+ }
70+ }
71+
72+ foreach ($ menus as $ k => $ m ) {
73+ if (isset ($ m ['children ' ]) && !empty ($ m ['children ' ])) {
74+ $ menus [$ k ]['children ' ] = array_values ($ m ['children ' ]);
75+ } else {
76+ unset($ menus [$ k ]);
77+ }
78+ }
79+ }
80+
5081 /**
5182 * 构建菜单权限细节
5283 * @param $menu
You can’t perform that action at this time.
0 commit comments