From 027535cd68743cd8ad803a3b6dcd4148a2ef4d13 Mon Sep 17 00:00:00 2001 From: JaguarJack <82664165@qq.com> Date: Thu, 25 Apr 2024 20:34:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=BF=AE=E6=94=B9=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E7=94=9F=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/Repository/Options/Components.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/modules/Common/Repository/Options/Components.php b/modules/Common/Repository/Options/Components.php index dd83f6e..1fdc91e 100644 --- a/modules/Common/Repository/Options/Components.php +++ b/modules/Common/Repository/Options/Components.php @@ -2,7 +2,6 @@ namespace Modules\Common\Repository\Options; -use Catch\CatchAdmin; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; @@ -14,26 +13,38 @@ class Components implements OptionInterface protected array $components = [ [ 'label' => 'layout', - 'value' => '/admin/layout/index.vue' - ] + 'value' => '/layout/index.vue', + ], ]; public function get(): array { try { + $viewRootPath = config('catch.views_path'); + if ($module = request()->get('module')) { - $components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*' . DIRECTORY_SEPARATOR . '*.vue'); + if (!File::exists($viewRootPath . $module . DIRECTORY_SEPARATOR)) { + return []; + } + + $components = File::allFiles($viewRootPath . $module . DIRECTORY_SEPARATOR); foreach ($components as $component) { - $_component = Str::of($component) - ->replace(CatchAdmin::moduleRootPath(), '') + // 过滤非 vue 文件 + if ($component->getExtension() !== 'vue') { + continue; + } + + $_component = Str::of($component->getPathname()) + ->replace($viewRootPath, '') ->explode(DIRECTORY_SEPARATOR); - $_component->shift(2); + + $_component->shift(1); $this->components[] = [ 'label' => Str::of($_component->implode('/'))->replace('.vue', ''), - 'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/') + 'value' => Str::of($component)->replace($viewRootPath, '')->prepend('/'), ]; } }