lizhen_gitee 7 mesi fa
parent
commit
4065191a3e

+ 1 - 1
application/admin/library/Auth.php

@@ -476,7 +476,7 @@ class Auth extends \fast\Auth
                 unset($ruleList[$k]);
                 continue;
             }
-            $indexRuleName = $v['name'] . '/index';
+            $indexRuleName = $v['name'] . '/index'; // user/user 找到他的下级查看 user/user/index 如果有这个查看菜单,但是又没权限,那代表只是勾了一个空壳,所以unset
             if (isset($indexRuleList[$indexRuleName]) && !in_array($indexRuleName, $userRule)) {
                 unset($ruleList[$k]);
                 continue;

+ 28 - 7
application/common/library/Authcompany.php

@@ -536,35 +536,56 @@ class Authcompany extends \fast\Authpc
     }
 
     /**
-     * 获取左侧和顶部菜单栏
+     * 获取左侧菜单栏
      *
      * @param array  $params    URL对应的badge数据
      * @param string $fixedPage 默认页
      * @return array
      */
-    public function getmenu(){
+    public function get_menus(){
         // 读取管理员当前拥有的权限节点
         $userRule = $this->getRuleList();
 
         // 必须将结果集转换为数组
         $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
+            ->field('id,pid as parentId,name as namerule,title as name,path,component,component_name,icon')
             ->where('type', 'NEQ',3)
             ->order('weigh', 'desc')
             ->select())->toArray();
 
         foreach ($ruleList as $k => &$v) {
-            if (!in_array($v['name'], $userRule)) {
+            if (!in_array($v['namerule'], $userRule)) {
                 unset($ruleList[$k]);
                 continue;
             }
         }
-dump($ruleList);
-        Tree::instance()->init($ruleList);
-        $menu = Tree::instance()->getTreeMenu(Tree::instance()->getTreeArray(0), 'name');
-
+//        dump($ruleList);
+        Tree::instance()->init($ruleList,'parentId');
+        $menu = Tree::instance()->getTreeArray(0);
+//        dump($menu);
         return $menu;
 
     }
+    public function get_permissions(){
+        // 读取管理员当前拥有的权限节点
+        $userRule = $this->getRuleList();
+
+        // 必须将结果集转换为数组
+        $ruleList = collection(\app\admin\model\PcAuthRule::where('status', 'normal')
+            ->where('type', 3)
+            ->order('weigh', 'desc')
+            ->select())->toArray();
+
+        foreach ($ruleList as $k => &$v) {
+            if (!in_array($v['name'], $userRule)) {
+                unset($ruleList[$k]);
+                continue;
+            }
+        }
+//        dump($ruleList);
+
+        return array_column($ruleList,'permission');
+    }
     public function getSidebar($params = [], $fixedPage = 'dashboard')
     {
         // 边栏开始

+ 11 - 10
application/company/controller/Index.php

@@ -29,16 +29,17 @@ class Index extends Apic
      */
     public function index()
     {
-        $menu = $this->auth->getmenu();
-        dump($menu);
-        //左侧菜单
-       /* list($menulist, $navlist, $fixedmenu, $referermenu) = $this->auth->getSidebar([
-
-        ], 'dashboard');
-        dump($menulist);
-        dump($navlist);
-        dump($fixedmenu);
-        dump($referermenu);*/
+        $menus = $this->auth->get_menus();
+        $permissions = $this->auth->get_permissions();
+
+
+        $rs = [
+            'user' => $this->auth->getUserInfo(),
+            'permissions' => $permissions,
+            'menus' => $menus,
+        ];
+//        dump($rs);exit;
+        $this->success(1,$rs);
     }
 
     //员工账号+密码登录