Browse Source

PC端权限菜单

lizhen_gitee 7 months ago
parent
commit
9065d5165b
2 changed files with 29 additions and 1 deletions
  1. 1 1
      application/common/library/Authcompany.php
  2. 28 0
      extend/fast/Tree.php

+ 1 - 1
application/common/library/Authcompany.php

@@ -564,7 +564,7 @@ class Authcompany extends \fast\Authpc
         }
 //        dump($ruleList);
         Tree::instance()->init($ruleList,'parentId');
-        $menu = Tree::instance()->getTreeArray(0);
+        $menu = Tree::instance()->getTreeArray_2(0);
 //        dump($menu);
         return $menu;
 

+ 28 - 0
extend/fast/Tree.php

@@ -411,6 +411,34 @@ class Tree
         }
         return $data;
     }
+    //专门给pc端menu用的,childlist改成children
+    public function getTreeArray_2($myid, $itemprefix = '')
+    {
+        $childs = $this->getChild($myid);
+        $n = 0;
+        $data = [];
+        $number = 1;
+        if ($childs) {
+            $total = count($childs);
+            foreach ($childs as $id => $value) {
+                $j = $k = '';
+                if ($number == $total) {
+                    $j .= $this->icon[2];
+                    $k = $itemprefix ? $this->nbsp : '';
+                } else {
+                    $j .= $this->icon[1];
+                    $k = $itemprefix ? $this->icon[0] : '';
+                }
+                $spacer = $itemprefix ? $itemprefix . $j : '';
+                $value['spacer'] = $spacer;
+                $data[$n] = $value;
+                $data[$n]['children'] = $this->getTreeArray_2($id, $itemprefix . $k . $this->nbsp);
+                $n++;
+                $number++;
+            }
+        }
+        return $data;
+    }
 
     /**
      * 将getTreeArray的结果返回为二维数组