diff --git a/app/common/logic/PermLogic.php b/app/common/logic/PermLogic.php index af9f848..24f8e65 100644 --- a/app/common/logic/PermLogic.php +++ b/app/common/logic/PermLogic.php @@ -52,7 +52,6 @@ class PermLogic return $all->unique('id')->values()->sortBy('sort'); } - /** * 构建目录/菜单树 * @@ -66,13 +65,13 @@ class PermLogic $tree = []; foreach ($resources as $node) { - if ($node->parent_id !== $parentId) { + // 只处理目录和菜单,不把 permission 当作菜单节点 + if ($node->parent_id !== $parentId || $node->type === 'permission') { continue; } // —— 拼接当前节点的完整路径 —— $currentPath = rtrim($parentPath, '/'); - if (!empty($node->url)) { $urlSegment = ltrim($node->url, '/'); $currentPath = $currentPath === '' @@ -81,10 +80,8 @@ class PermLogic } // —— 递归构建子节点 —— - $children = []; - if (in_array($node->type, ['directory', 'menu'])) { - $children = $this->buildTree($resources, $node->id, $currentPath); - } + // 这里只会继续收目录和菜单,permission 永远不会进入此方法 + $children = $this->buildTree($resources, $node->id, $currentPath); // —— 本级权限列表 —— $authList = $resources @@ -98,10 +95,7 @@ class PermLogic ->all(); // —— 判断是否有子目录或子菜单 —— - $hasChildrenMenu = $resources - ->where('parent_id', $node->id) - ->whereIn('type', ['directory', 'menu']) - ->isNotEmpty(); + $hasChildrenMenu = ! empty($children); // —— 计算 component 字段 —— if ($hasChildrenMenu) { @@ -130,8 +124,10 @@ class PermLogic 'keepAlive' => true, 'authList' => $authList, 'openType' => $node->open_type, + 'isHide' => $node->is_hide == 0 ? false : true, + 'isHideTab' => $node->is_hide_tab == 0 ? false : true ], - 'children' => $children, + 'children' => $children ]; } diff --git a/app/common/utils/scaffold/Generate.php b/app/common/utils/scaffold/Generate.php index 7cf52ac..6735997 100644 --- a/app/common/utils/scaffold/Generate.php +++ b/app/common/utils/scaffold/Generate.php @@ -26,11 +26,11 @@ class Generate // 模板路径 $templateDir = __DIR__ . '/templates/'; - $controllerPath = __DIR__ . "/../../../{$this->options['controller']['module']}/controller/".ucfirst($this->options['controller']['name'])."Controller.php"; - $servicePath = __DIR__ . "/../../../{$this->options['service']['module']}/service/".ucfirst($this->options['service']['name'])."Service.php"; - $logicPath = __DIR__ . "/../../../{$this->options['logic']['module']}/logic/".ucfirst($this->options['logic']['name'])."Logic.php"; - $modelPath = __DIR__ . "/../../../{$this->options['model']['module']}/model/".ucfirst($this->options['model']['name']).".php"; - $validatePath = __DIR__ . "/../../../{$this->options['validate']['module']}/validate/".ucfirst($this->options['validate']['name'])."Validate.php"; + $controllerPath = __DIR__ . "/../../../{$this->options['controller']['module']}/controller/".$this->rName($this->options['controller']['name'])."Controller.php"; + $servicePath = __DIR__ . "/../../../{$this->options['service']['module']}/service/".$this->rName($this->options['service']['name'])."Service.php"; + $logicPath = __DIR__ . "/../../../{$this->options['logic']['module']}/logic/".$this->rName($this->options['logic']['name'])."Logic.php"; + $modelPath = __DIR__ . "/../../../{$this->options['model']['module']}/model/".$this->rName($this->options['model']['name']).".php"; + $validatePath = __DIR__ . "/../../../{$this->options['validate']['module']}/validate/".$this->rName($this->options['validate']['name'])."Validate.php"; // 创建目录(如果不存在) $fs->mkdir(__DIR__ . "/../../../{$this->options['controller']['module']}/controller"); @@ -86,32 +86,32 @@ class Generate case 'controller': $content = str_replace('{{controllerModule}}', $this->options['controller']['module'], $content); $content = str_replace('{{serviceModule}}', $this->options['service']['module'], $content); - $content = str_replace('{{serviceName}}', ucfirst($this->options['service']['name']), $content); - $content = str_replace('{{controllerName}}', ucfirst($this->options['controller']['name']), $content); + $content = str_replace('{{serviceName}}', $this->rName($this->options['service']['name']), $content); + $content = str_replace('{{controllerName}}', $this->rName($this->options['controller']['name']), $content); break; case 'service': $content = str_replace('{{serviceModule}}', $this->options['service']['module'], $content); $content = str_replace('{{validateModule}}', $this->options['validate']['module'], $content); - $content = str_replace('{{validateName}}', ucfirst($this->options['validate']['name']), $content); + $content = str_replace('{{validateName}}', $this->rName($this->options['validate']['name']), $content); $content = str_replace('{{modelModule}}', $this->options['model']['module'], $content); - $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content); - $content = str_replace('{{serviceName}}', ucfirst($this->options['service']['name']), $content); + $content = str_replace('{{modelName}}', $this->rName($this->options['model']['name']), $content); + $content = str_replace('{{serviceName}}', $this->rName($this->options['service']['name']), $content); break; case 'logic': $content = str_replace('{{logicModule}}', $this->options['logic']['module'], $content); $content = str_replace('{{modelModule}}', $this->options['model']['module'], $content); - $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content); - $content = str_replace('{{logicName}}', ucfirst($this->options['logic']['name']), $content); + $content = str_replace('{{modelName}}', $this->rName($this->options['model']['name']), $content); + $content = str_replace('{{logicName}}', $this->rName($this->options['logic']['name']), $content); break; case 'model': $content = str_replace('{{modelModule}}', $this->options['model']['module'], $content); - $content = str_replace('{{modelName}}', ucfirst($this->options['model']['name']), $content); + $content = str_replace('{{modelName}}', $this->rName($this->options['model']['name']), $content); $content = str_replace('{{table}}', $this->options['table'], $content); $content = str_replace('{{fillable}}', $this->fillableFields(), $content); break; case 'validate': $content = str_replace('{{validateModule}}', $this->options['validate']['module'], $content); - $content = str_replace('{{validateName}}', ucfirst($this->options['validate']['name']), $content); + $content = str_replace('{{validateName}}', $this->rName($this->options['validate']['name']), $content); break; } @@ -153,6 +153,14 @@ class Generate echo "删除已存在文件: {$path} \n"; } } + + /** + * 设置名称 + */ + public function rName($name = '') + { + return ucfirst(camelize($name)); + } } /** diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index 125ff1f..6ca6eae 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -71,26 +71,26 @@ class IndexController { $options = [ 'controller' => [ - 'module' => 'admin', - 'name' => 'systems' + 'module' => 'inquiry', + 'name' => 'inquiry_log' ], 'model' => [ - 'module' => 'common', - 'name' => 'systems' + 'module' => 'inquiry', + 'name' => 'inquiry_log' ], 'service' => [ - 'module' => 'admin', - 'name' => 'systems' + 'module' => 'inquiry', + 'name' => 'inquiry_log' ], 'logic' => [ - 'module' => 'common', - 'name' => 'systems' + 'module' => 'inquiry', + 'name' => 'inquiry_log' ], 'validate' => [ - 'module' => 'common', - 'name' => 'systems' + 'module' => 'inquiry', + 'name' => 'inquiry_log' ], - 'table' => 'systems' + 'table' => 'inquiry_log' ]; $result = (new Generate($options))->doGenerate();