47 lines
1.3 KiB
PHP
Raw Normal View History

2022-12-10 18:29:42 +08:00
<?php
2022-12-14 19:25:52 +08:00
2023-01-11 17:17:36 +08:00
namespace Modules\Common\Repository\Options;
2022-12-10 18:29:42 +08:00
use Catch\CatchAdmin;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class Components implements OptionInterface
{
/**
* @var array|string[]
*/
protected array $components = [
[
'label' => 'layout',
'value' => '/admin/layout/index.vue'
]
];
public function get(): array
{
2024-03-07 11:28:09 +08:00
try {
if ($module = request()->get('module')) {
$components = File::glob(CatchAdmin::getModuleViewsPath($module) . '*' . DIRECTORY_SEPARATOR . '*.vue');
foreach ($components as $component) {
$_component = Str::of($component)
->replace(CatchAdmin::moduleRootPath(), '')
->explode(DIRECTORY_SEPARATOR);
$_component->shift(2);
$this->components[] = [
'label' => Str::of($_component->implode('/'))->replace('.vue', ''),
'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
];
}
2022-12-10 18:29:42 +08:00
}
2024-03-07 11:28:09 +08:00
return $this->components;
} catch (\Throwable $exception) {
return [];
}
2022-12-10 18:29:42 +08:00
}
}