first commit

This commit is contained in:
JaguarJack
2022-12-05 23:01:12 +08:00
commit 0024080c28
322 changed files with 27698 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace Modules\Options\Http;
use Exception;
use Modules\Options\Repository\Factory;
class OptionController
{
/**
* @param $name
* @param Factory $factory
* @return array
* @throws Exception
*/
public function index($name, Factory $factory): array
{
return $factory->make($name)->get();
}
}

View File

@@ -0,0 +1,2 @@
## 介绍
这是一个公共模块,不耦合其他项目,用于给前端提供统一 select options 数据接口

View File

@@ -0,0 +1,38 @@
<?php
namespace Modules\Options\Repository;
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\Options\Repository;
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\Options\Repository;
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['name'],
'value' => $module['path']
];
});
return $modules;
}
}

View File

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

View File

@@ -0,0 +1,23 @@
<?php
namespace Modules\Options\Repository;
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()
]
];
}
}