feat: add uploader

This commit is contained in:
JaguarJack
2023-01-11 17:17:36 +08:00
parent 68d378b4ef
commit d823f74015
15 changed files with 457 additions and 9 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace Modules\Common\Repository\Options;
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')) {
$components = File::glob(CatchAdmin::getModuleViewsPath($module).'*'.DIRECTORY_SEPARATOR.'*.vue');
foreach ($components as $component) {
$this->components[] = [
'label' => Str::of($component)->explode(DIRECTORY_SEPARATOR)->pop(2)->pop(),
'value' => Str::of($component)->replace(CatchAdmin::moduleRootPath(), '')->prepend('/')
];
}
}
return $this->components;
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace Modules\Common\Repository\Options;
use Catch\CatchAdmin;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class Controllers implements OptionInterface
{
public function get(): array
{
$controllers = [];
if ($module = request()->get('module')) {
$controllerFiles = File::glob(CatchAdmin::getModuleControllerPath($module).'*.php');
foreach ($controllerFiles as $controllerFile) {
$controllers[] = [
'label' => Str::of(File::name($controllerFile))->lcfirst()->remove('Controller'),
'value' => Str::of(File::name($controllerFile))->lcfirst()->remove('Controller'),
];
}
}
return $controllers;
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Modules\Common\Repository\Options;
use Modules\Permissions\Enums\DataRange as DataRangeEnum;
class DataRange implements OptionInterface
{
public function get(): array
{
return [
[
'label' => DataRangeEnum::All_Data->name(),
'value' => DataRangeEnum::All_Data->value()
],
[
'label' => DataRangeEnum::Personal_Choose->name(),
'value' => DataRangeEnum::Personal_Choose->value()
],
[
'label' => DataRangeEnum::Personal_Data->name(),
'value' => DataRangeEnum::Personal_Data->value()
],
[
'label' => DataRangeEnum::Department_Data->name(),
'value' => DataRangeEnum::Department_Data->value()
],
[
'label' => DataRangeEnum::Department_DOWN_Data->name(),
'value' => DataRangeEnum::Department_DOWN_Data->value()
]
];
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Modules\Common\Repository\Options;
use Exception;
use Illuminate\Support\Str;
class Factory
{
/**
* make
* @param string $optionName
* @return OptionInterface
* @throws Exception
*/
public function make(string $optionName): OptionInterface
{
$className = __NAMESPACE__.'\\'.Str::of($optionName)->ucfirst()->toString();
$class = new $className();
if (! $class instanceof OptionInterface) {
throw new Exception('option must be implement [OptionInterface]');
}
return $class;
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Modules\Common\Repository\Options;
use Catch\Support\Module\ModuleRepository;
class Modules implements OptionInterface
{
public function get(): array
{
$modules = [];
app(ModuleRepository::class)->all([])
->each(function ($module) use (&$modules) {
$modules[] = [
'label' => $module['title'],
'value' => $module['name']
];
});
return $modules;
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace Modules\Common\Repository\Options;
interface OptionInterface
{
/**
* @return array{label: string, value: string|number }
*/
public function get(): array;
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Modules\Common\Repository\Options;
use Catch\Enums\Status as StatusEnum;
class Status implements OptionInterface
{
public function get(): array
{
return [
[
'label' => StatusEnum::Enable->name(),
'value' => StatusEnum::Enable->value()
],
[
'label' => StatusEnum::Disable->name(),
'value' => StatusEnum::Disable->value()
]
];
}
}