43 lines
1.2 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
{
if ($module = request()->get('module')) {
2022-12-18 22:44:58 +08:00
$components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue');
2022-12-10 18:29:42 +08:00
foreach ($components as $component) {
2023-04-07 08:13:40 +08:00
$_component = Str::of($component)
->replace(CatchAdmin::moduleRootPath(), '')
->explode(DIRECTORY_SEPARATOR);
$_component->shift(2);
2022-12-10 18:29:42 +08:00
$this->components[] = [
2023-04-07 08:13:40 +08:00
'label' => Str::of($_component->implode('/'))->replace('.vue', ''),
2022-12-10 18:29:42 +08:00
'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
];
}
}
return $this->components;
}
}